diff --git a/cross/zap2it/Makefile b/cross/zap2it/Makefile new file mode 100644 index 00000000000..8ab1da703b1 --- /dev/null +++ b/cross/zap2it/Makefile @@ -0,0 +1,25 @@ +PKG_NAME = zap2it +PKG_VERS = 20210519 +PKG_EXT = tar.gz +PKG_DIST_NAME = v$(PKG_VERS).$(PKG_EXT) +PKG_DIST_SITE = https://github.com/daniel-widrick/zap2it-GuideScraping/archive +PKG_DIST_FILE = $(PKG_NAME)-$(PKG_VERS).$(PKG_EXT) +PKG_DIR = $(PKG_NAME)-GuideScraping-$(PKG_VERS) + +DEPENDS = + +HOMEPAGE = https://github.com/daniel-widrick/zap2it-GuideScraping +COMMENT = Take TV listings from zap2it and convert them to xmltv for use with applications such as Jellyfin/Emby +LICENSE = MIT + +INSTALL_TARGET = zap2it_install + +include ../../mk/spksrc.install-resources.mk + +.PHONY: zap2it_install +zap2it_install: + install -m 755 -d $(STAGING_INSTALL_PREFIX)/bin + install -m 755 $(WORK_DIR)/$(PKG_DIR)/zap2it-GuideScrape.py $(STAGING_INSTALL_PREFIX)/bin + @sed -i '1 i\#!/usr/bin/env python3' $(STAGING_INSTALL_PREFIX)/bin/zap2it-GuideScrape.py + install -m 750 -d $(STAGING_INSTALL_PREFIX)/etc + install -m 640 $(WORK_DIR)/$(PKG_DIR)/zap2itconfig.ini.dist $(STAGING_INSTALL_PREFIX)/etc/zap2itconfig.ini diff --git a/cross/zap2it/PLIST b/cross/zap2it/PLIST new file mode 100644 index 00000000000..ccdf24056fe --- /dev/null +++ b/cross/zap2it/PLIST @@ -0,0 +1,2 @@ +bin:bin/zap2it-GuideScrape.py +rsc:etc/zap2itconfig.ini diff --git a/cross/zap2it/digests b/cross/zap2it/digests new file mode 100644 index 00000000000..ac76a87c75d --- /dev/null +++ b/cross/zap2it/digests @@ -0,0 +1,3 @@ +zap2it-20210519.tar.gz SHA1 4ccdac6d462ad4f9f94ae70e2a3caba9f4dd23e2 +zap2it-20210519.tar.gz SHA256 545156f31e7cdcc7d332c5e98dbcf854b2fd37269dcdd4afa5401dfa181332f0 +zap2it-20210519.tar.gz MD5 0973df894f626964149a2e33d7667e0d diff --git a/spk/zap2it/Makefile b/spk/zap2it/Makefile new file mode 100644 index 00000000000..7da4468fb0d --- /dev/null +++ b/spk/zap2it/Makefile @@ -0,0 +1,32 @@ +SPK_NAME = zap2it +SPK_VERS = 20210519 +SPK_REV = 1 +SPK_ICON = src/zap2it.png +DSM_UI_DIR = app + +DEPENDS = cross/$(SPK_NAME) +SPK_DEPENDS = "python3>=3.7.7-15" + +MAINTAINER = th0ma7 +DESCRIPTION = Takes TV listings from zap2it and convert them to XMLTV for use with applications such as Jellyfin / Emby / TVheadEnd +DESCRIPTION_FRE = Prend la programmation télé de zap2it et la convertis en XMLTV pour une utilisation avec des applications telles que Jellyfin / Emby / TVheadEnd +DISPLAY_NAME = zap2it XMLTV Scrapper +CHANGELOG = "Initial package" + +STARTABLE = no +HOMEPAGE = https://github.com/daniel-widrick/zap2it-GuideScraping +LICENSE = MIT + +WIZARDS_DIR = src/wizard/ + +# 'auto' reserved value grabs SPK_NAME +SERVICE_USER = auto +SERVICE_SETUP = src/service-setup.sh + +POST_STRIP_TARGET = zap2it_extra_install + +include ../../mk/spksrc.spk.mk + +.PHONY: zap2it_extra_install +zap2it_extra_install: + install -m 600 src/zap2it.synocron $(STAGING_DIR)/etc/zap2it.synocron diff --git a/spk/zap2it/PLIST b/spk/zap2it/PLIST new file mode 100644 index 00000000000..e69de29bb2d diff --git a/spk/zap2it/src/service-setup.sh b/spk/zap2it/src/service-setup.sh new file mode 100644 index 00000000000..7cc49184cee --- /dev/null +++ b/spk/zap2it/src/service-setup.sh @@ -0,0 +1,101 @@ +# Package specific behaviors +# Sourced script by generic installer and start-stop-status scripts + +# Group to access XMLTV files +GROUP=sc-media + +# Default configuration file +SPKETC="/var/packages/${SYNOPKG_PKGNAME}/etc" +SYNOCRON=/usr/local/etc/synocron.d/ +INSTALLER_VARIABLES="${SPKETC}/installer-variables" +# +ZAP2IT_CONF=${SYNOPKG_PKGDEST}/etc/zap2itconfig.ini +ZAP2IT_CACHE=${SYNOPKG_PKGVAR} +ZAP2IT_BACKUP=/tmp/zap2it + +write_zap2it_config() +{ + echo "Call write_zap2it_config()" + + # Set default country + [ "${zap2it_CAN}" = "true" ] && zap2it_country=CAN || zap2it_country=USA + # Remove spaces from CAD postal code + zap2it_code=$(echo ${zap2it_code} | sed 's/ //g') + + # Keep previous passwd if left blank at upgrade time + echo "Keep previous passwd if left blank at upgrade time" + if [ "${ZAP2IT_PASSWD}" -a ! "${zap2it_password}" ]; then + zap2it_password=$(echo "${ZAP2IT_PASSWD}" | openssl enc -d -aes-256-cbc -pass pass:zap2it -a) + fi + + # Set configuration according to the wizard + echo "Set configuration according to the wizard" + sed -i "/^Username: /s/ .*/ ${zap2it_user}/" ${ZAP2IT_CONF} + sed -i "/^Password: /s/ .*/ ${zap2it_password}/" ${ZAP2IT_CONF} + sed -i "/^country: /s/ .*/ ${zap2it_country}/" ${ZAP2IT_CONF} + sed -i "/^zipCode: /s/ .*/ ${zap2it_code}/" ${ZAP2IT_CONF} + sed -i "/^historicalGuideDays: /s/ .*/ ${zap2it_days}/" ${ZAP2IT_CONF} + + # Encrypt password + echo "Encrypt password" + ZAP2IT_PASSWD=$(echo -n "${zap2it_password}" | openssl enc -aes-256-cbc -pass pass:zap2it -a) + # Backup installer variables + sed -i -n -e '/^ZAP2IT_USER=/!p' -e "\$aZAP2IT_USER=\"${zap2it_user}\"" ${INSTALLER_VARIABLES} + sed -i -n -e '/^ZAP2IT_PASSWD=/!p' -e "\$aZAP2IT_PASSWD=\"${ZAP2IT_PASSWD}\"" ${INSTALLER_VARIABLES} + sed -i -n -e '/^ZAP2IT_CAN=/!p' -e "\$aZAP2IT_CAN=\"${zap2it_CAN}\"" ${INSTALLER_VARIABLES} + sed -i -n -e '/^ZAP2IT_US=/!p' -e "\$aZAP2IT_US=\"${zap2it_US}\"" ${INSTALLER_VARIABLES} + sed -i -n -e '/^ZAP2IT_CODE=/!p' -e "\$aZAP2IT_CODE=\"${zap2it_code}\"" ${INSTALLER_VARIABLES} + sed -i -n -e '/^ZAP2IT_DAYS=/!p' -e "\$aZAP2IT_DAYS=\"${zap2it_days}\"" ${INSTALLER_VARIABLES} +} + +service_postinst () +{ + # Create cache directory if it does not exist + echo "Create cache directory if it does not exist (${ZAP2IT_CACHE})" + if [ ! -d ${ZAP2IT_CACHE} ]; then + mkdir --mode=0755 ${ZAP2IT_CACHE} && echo "cache directory created" || "error creating cache directory" + else + echo "cache directory already exists" + fi + + # For backwards compatibility, set ownership of package system directories + if [ $SYNOPKG_DSM_VERSION_MAJOR == 6 ]; then + echo "Set unix permissions on configuration directory" + set_unix_permissions "${SYNOPKG_PKGDEST}" + echo "Set unix permissions on cache directory" + set_unix_permissions "${SYNOPKG_PKGVAR}" + fi + + # Adjust configuration files + write_zap2it_config + + # Install the synocron + echo "Install synocron (${SYNOCRON}/zap2it.conf)" + cp ${SYNOPKG_PKGDEST}/etc/zap2it.synocron ${SYNOCRON}/zap2it.conf + synoservice --restart synocrond +} + +service_postuninst () +{ + # Remove synocron + echo "Remove synocron" + rm -f ${SYNOCRON}/zap2it.conf + synoservice --restart synocrond +} + +service_preupgrade () +{ + # Create a backup copy + echo "Create a backup copy" + mkdir -p ${ZAP2IT_BACKUP} + rsync -ah ${SYNOPKG_PKGDEST}/var ${ZAP2IT_BACKUP} +} + +service_postupgrade () +{ + # Recover backup + echo "Recover backup" + rsync -ah --ignore-existing --remove-source-files ${ZAP2IT_BACKUP}/var/ ${SYNOPKG_PKGDEST}/var + # Remove backup directory + rm -fr ${ZAP2IT_BACKUP} +} diff --git a/spk/zap2it/src/wizard/install_uifile b/spk/zap2it/src/wizard/install_uifile new file mode 100644 index 00000000000..11868166dd1 --- /dev/null +++ b/spk/zap2it/src/wizard/install_uifile @@ -0,0 +1,63 @@ +[{ + "step_title": "Set country and region", + "items": [{ + "type": "singleselect", + "desc": "Location", + "subitems": [{ + "key": "zap2it_CAN", + "desc": "Canada", + "defaultValue": true + },{ + "key": "zap2it_US", + "desc": "United States", + "defaultValue": false + }] + },{ + "type": "textfield", + "subitems": [{ + "key": "zap2it_code", + "desc": "Postal or ZIP code", + "emptyText": "90210 or J9J1Z1", + "validator": { + "vtype": "alphanum", + "regex": { + "expr": "/^[0-9]{5}$|^[A-Z][0-9][A-Z][ ]?[0-9][A-Z][0-9]$/i" + } + } + }] + },{ + "type": "textfield", + "subitems": [{ + "key": "zap2it_days", + "desc": "TV Guide Numbers of days (max. 14)", + "defaultValue": "14", + "validator": { + "vtype": "alphanum", + "regex": { + "expr": "/^[1-9]$|^1[0-4]$/i" + } + } + }] + }] +}, { + "step_title": "Set username and password", + "items": [{ + "type": "textfield", + "desc": "User account to connect to tvlistings.zap2it.com", + "subitems": [{ + "key": "zap2it_user", + "desc": "Username", + "emptyText": "abc@xyz.com", + "validator": { + "vtype": "email" + } + }] + },{ + "type": "password", + "desc": " ", + "subitems": [{ + "key": "zap2it_password", + "desc": "Password" + }] + }] +}] diff --git a/spk/zap2it/src/wizard/upgrade_uifile.sh b/spk/zap2it/src/wizard/upgrade_uifile.sh new file mode 100644 index 00000000000..ff7cd95f8b7 --- /dev/null +++ b/spk/zap2it/src/wizard/upgrade_uifile.sh @@ -0,0 +1,80 @@ +#!/bin/sh + +SPKETC="/var/packages/${SYNOPKG_PKGNAME}/etc" +INSTALLER_VARIABLES="${SPKETC}/installer-variables" + +# Reload wizard variables stored by postinst +if [ -r "${INSTALLER_VARIABLES}" ]; then + . "${INSTALLER_VARIABLES}" +fi + +cat < $SYNOPKG_TEMP_LOGFILE +[{ + "step_title": "Set country and region", + "items": [{ + "type": "singleselect", + "desc": "Location", + "subitems": [{ + "key": "zap2it_CAN", + "desc": "Canada", + "defaultValue": "${ZAP2IT_CAN}" + },{ + "key": "zap2it_US", + "desc": "United States", + "defaultValue": "${ZAP2IT_US}" + }] + },{ + "type": "textfield", + "subitems": [{ + "key": "zap2it_code", + "desc": "Postal or ZIP code", + "emptyText": "90210 or J9J1Z1", + "defaultValue": "${ZAP2IT_CODE}", + "validator": { + "vtype": "alphanum", + "regex": { + "expr": "/^[0-9]{5}$|^[A-Z][0-9][A-Z][ ]?[0-9][A-Z][0-9]$/i" + } + } + }] + },{ + "type": "textfield", + "subitems": [{ + "key": "zap2it_days", + "desc": "TV Guide Numbers of days (max. 14)", + "defaultValue": "${ZAP2IT_DAYS}", + "validator": { + "vtype": "alphanum", + "regex": { + "expr": "/^[1-9]$|^1[0-4]$/i" + } + } + }] + }] +}, { + "step_title": "Set username and password", + "items": [{ + "type": "textfield", + "desc": "User account to connect to tvlistings.zap2it.com", + "subitems": [{ + "key": "zap2it_user", + "desc": "Username", + "emptyText": "abc@xyz.com", + "defaultValue": "${ZAP2IT_USER}", + "validator": { + "vtype": "email" + } + }] + },{ + "type": "password", + "desc": " ", + "subitems": [{ + "key": "zap2it_password", + "desc": "Password", + "emptyText": "(leave blank to keep existing password)", + "defaultValue": "" + }] + }] +}] +EOF +exit 0 diff --git a/spk/zap2it/src/zap2it.png b/spk/zap2it/src/zap2it.png new file mode 100644 index 00000000000..48218415081 Binary files /dev/null and b/spk/zap2it/src/zap2it.png differ diff --git a/spk/zap2it/src/zap2it.synocron b/spk/zap2it/src/zap2it.synocron new file mode 100644 index 00000000000..81e6482451a --- /dev/null +++ b/spk/zap2it/src/zap2it.synocron @@ -0,0 +1,10 @@ +[ + { + "cmd" : "/var/packages/zap2it/target/bin/zap2it-GuideScrape.py -i /var/packages/zap2it/target/etc/zap2itconfig.ini -o /var/packages/zap2it/target/var/xmlguide.xmltv", + "crontab" : "0 */12 * * *", + "name" : "zap2it", + "package_username" : "sc-zap2it", + "period" : "crontab", + "user" : "package" + } +]