Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zap2it #4608

Closed
wants to merge 18 commits into from
Closed

zap2it #4608

Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cross/zap2it/Makefile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions cross/zap2it/PLIST
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin:bin/zap2it-GuideScrape.py
rsc:etc/zap2itconfig.ini
3 changes: 3 additions & 0 deletions cross/zap2it/digests
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zap2it-20210519.tar.gz SHA1 4ccdac6d462ad4f9f94ae70e2a3caba9f4dd23e2
zap2it-20210519.tar.gz SHA256 545156f31e7cdcc7d332c5e98dbcf854b2fd37269dcdd4afa5401dfa181332f0
zap2it-20210519.tar.gz MD5 0973df894f626964149a2e33d7667e0d
32 changes: 32 additions & 0 deletions spk/zap2it/Makefile
Original file line number Diff line number Diff line change
@@ -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
Empty file added spk/zap2it/PLIST
Empty file.
96 changes: 96 additions & 0 deletions spk/zap2it/src/service-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# 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)
th0ma7 marked this conversation as resolved.
Show resolved Hide resolved
# 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})"
mkdir -p --mode=0755 ${ZAP2IT_CACHE}
th0ma7 marked this conversation as resolved.
Show resolved Hide resolved
# 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}
}
63 changes: 63 additions & 0 deletions spk/zap2it/src/wizard/install_uifile
Original file line number Diff line number Diff line change
@@ -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 <a target=\"_blank\" href=\"https://tvlistings.zap2it.com\">tvlistings.zap2it.com</a>",
"subitems": [{
"key": "zap2it_user",
"desc": "Username",
"emptyText": "abc@xyz.com",
"validator": {
"vtype": "email"
}
}]
},{
"type": "password",
"desc": " ",
"subitems": [{
"key": "zap2it_password",
"desc": "Password"
}]
}]
}]
80 changes: 80 additions & 0 deletions spk/zap2it/src/wizard/upgrade_uifile.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF > $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 <a target=\"_blank\" href=\"https://tvlistings.zap2it.com\">tvlistings.zap2it.com</a>",
"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
Binary file added spk/zap2it/src/zap2it.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions spk/zap2it/src/zap2it.synocron
Original file line number Diff line number Diff line change
@@ -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"
}
]