Skip to content

Commit

Permalink
Updated genre algorithm and added language detection
Browse files Browse the repository at this point in the history
Update for Kodi 20 program.  Also update genre matching algorithm and added language detection capability to help TVH and Kodi display the correct characters.
  • Loading branch information
wbeard52 committed Aug 3, 2024
1 parent a3f6387 commit f5c6cab
Show file tree
Hide file tree
Showing 7 changed files with 658 additions and 270 deletions.
11 changes: 8 additions & 3 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.zap2epg" name="zap2epg" version="1.3.1" provider-name="edit4ever">
<addon id="script.module.zap2epg" name="zap2epg" version="2.1.0" provider-name="edit4ever">
<requires>
<import addon="xbmc.python" version="2.7.13"/>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.dateutil" version="2.4.2"/>
<import addon="script.module.xbmcswift2" version="2.4.0"/>
<import addon="script.module.requests" version="2.9.1" />
<!--import addon="script.module.web-pdb"/-->
</requires>
<extension point="xbmc.python.pluginsource" library="default.py">
<provides>executable</provides>
Expand All @@ -29,7 +30,11 @@ Setup:
<email></email>
<source></source>
<news>
v1.3.1 - remove doctype error for TVH on OSMC
v2.0.4 - Update for Kodi 20+. Updated EPG Genre linking and language detection.
v2.0.3 - fix channel configuration error (2021-05-23)
v2.0.2 - fix Tvheadend username and password option (2021-03-29)
v2.0.1 - Kodi 19 dialog fix (2021-02-25)
v2.0.0 - Python 3 update (2020-10-27)
v1.3.0 - fix server issues for lineups (2019-04-12)
v1.2.0 - add option to refresh download cache days (2019-03-04)
v1.1.0 - added ability to refresh TBA episodes (2018-11-20)
Expand Down
2 changes: 1 addition & 1 deletion bin/tv_grab_zap2epg
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ do case "$1" in
;;

-v | --version )
printf "1.3.x\n"
printf "2.0.x\n"
;;

-c | --capabilities )
Expand Down
64 changes: 33 additions & 31 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@
import subprocess
from subprocess import Popen
from xbmcswift2 import Plugin
import StringIO
import io
import os
import re
import sys
import logging
import zap2epg
import urllib2
import urllib.request, urllib.error, urllib.parse
import json
from collections import OrderedDict
import time
import datetime
import _strptime
import requests
#import web_pdb; web_pdb.set_trace()

userdata = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile'))
userdata = xbmcvfs.translatePath(xbmcaddon.Addon().getAddonInfo('profile'))
tvhoff = xbmcaddon.Addon().getSetting('tvhoff')
if not os.path.exists(userdata):
os.mkdir(userdata)
os.mkdir(userdata)
log = os.path.join(userdata, 'zap2epg.log')
Clist = os.path.join(userdata, 'channels.json')
tvhList = os.path.join(userdata, 'TVHchannels.json')
Expand Down Expand Up @@ -78,9 +79,9 @@
check_load = requests.get(check_url)
check_status = check_load.raise_for_status()
except requests.exceptions.HTTPError as err:
dialog.ok("Tvheadend Access Error!", str(err), "", "Please check your username/password in settings.")
dialog.ok("Tvheadend Access Error!",f"{err}\n\nPlease check your username/password in settings.")
except requests.exceptions.RequestException as e:
dialog.ok("Tvheadend Access Error!", "Could not connect to Tvheadend server.", "Please check your Tvheadend server is running or check the IP and port configuration in the settings.")
dialog.ok("Tvheadend Access Error!", "Could not connect to Tvheadend server.\nPlease check your Tvheadend server is running or check the IP and port configuration in the settings.")

def get_icon_path(icon_name):
addon_path = xbmcaddon.Addon().getAddonInfo("path")
Expand All @@ -90,16 +91,16 @@ def create_cList():
tvhClist = []
if tvhoff == 'true':
if not os.path.isfile(tvhList):
channels_url = 'http://' + tvh_url + ':' + tvh_port + '/api/channel/grid?all=1&limit=999999999&sort=name'
response = requests.get(channels_url)
try:
logging.info('Accessing Tvheadend channel list from: %s', channels_url)
channels = response.json()
with open(tvhList,"w") as f:
json.dump(channels,f)
except urllib2.HTTPError as e:
logging.exception('Exception: tvhClist - %s', e.strerror)
pass
channels_url = 'http://' + tvh_url + ':' + tvh_port + '/api/channel/grid?all=1&limit=999999999&sort=name'
response = requests.get(channels_url)
try:
logging.info('Accessing Tvheadend channel list from: %s', channels_url)
channels = response.json()
with open(tvhList,"w") as f:
json.dump(channels,f)
except urllib.error.HTTPError as e:
logging.exception('Exception: tvhClist - %s', e.strerror)
pass
with open(tvhList) as tvhData:
tvhDict = json.load(tvhData)
for ch in tvhDict['entries']:
Expand All @@ -108,7 +109,7 @@ def create_cList():
tvhClist.append(ch['number'])
lineupcode = xbmcaddon.Addon().getSetting('lineupcode')
url = 'http://tvlistings.zap2it.com/api/grid?lineupId=&timespan=3&headendId=' + lineupcode + '&country=' + country + '&device=' + device + '&postalCode=' + zipcode + '&time=' + str(gridtime) + '&pref=-&userId=-'
content = urllib2.urlopen(url).read()
content = urllib.request.urlopen(url).read()
contentDict = json.loads(content)
stationDict = {}
if 'channels' in contentDict:
Expand All @@ -121,25 +122,25 @@ def create_cList():
stationDict[skey]['include'] = 'True'
else:
stationDict[skey]['include'] = 'False'
stationDictSort = OrderedDict(sorted(stationDict.iteritems(), key=lambda i: (float(i[1]['num']))))
stationDictSort = OrderedDict(sorted(iter(stationDict.items()), key=lambda i: (float(i[1]['num']))))
with open(Clist,"w") as f:
json.dump(stationDictSort,f)

@plugin.route('/channels')
def channels():
lineupcode = xbmcaddon.Addon().getSetting('lineupcode')
if lineup is None or zipcode is None:
dialog.ok('Location not configured!', '', 'Please setup your location before configuring channels.')
dialog.ok('Location not configured!', 'Please setup your location before configuring channels.')
if not os.path.isfile(Clist):
create_cList()
else:
newList = dialog.yesno('Existing Channel List Found', 'Would you like to download a new channel list or review your current list?', '', 'Select Yes to download new list.')
newList = dialog.yesno('Existing Channel List Found', 'Would you like to download a new channel list or review your current list?', 'Review', 'Download')
if newList:
os.remove(Clist)
create_cList()
with open(Clist) as data:
stationDict = json.load(data)
stationDict = OrderedDict(sorted(stationDict.iteritems(), key=lambda i: (float(i[1]['num']))))
stationDict = OrderedDict(sorted(iter(stationDict.items()), key=lambda i: (float(i[1]['num']))))
stationCode = []
stationListName = []
stationListNum = []
Expand All @@ -150,13 +151,13 @@ def channels():
stationListNum.append(stationDict[station]['num'])
stationListInclude.append(stationDict[station]['include'])
stationPre = [i for i, x in enumerate(stationListInclude) if x == 'True']
stationListFull = zip(stationListNum, stationListName)
stationListFull = list(zip(stationListNum, stationListName))
stationList = ["%s %s" % x for x in stationListFull]
selCh = dialog.multiselect('Click to Select Channels to Include', stationList, preselect=stationPre)
for station in stationDict:
stationDict[station]['include'] = 'False'
stationListCodes = []
if selCh >= 0:
if selCh:
for channel in selCh:
skey = stationCode[channel]
stationDict[skey]['include'] = 'True'
Expand All @@ -174,7 +175,8 @@ def location():
zipcodeNew = dialog.input('Enter your zipcode', defaultt=zipcode, type=xbmcgui.INPUT_NUMERIC)
if countryNew == 1:
zipcodeNew = dialog.input('Enter your zipcode', defaultt=zipcode, type=xbmcgui.INPUT_ALPHANUM)
if not zipcodeNew:
#import web_pdb; web_pdb.set_trace()
if not 'zipcodeNew' in vars() or 'zipcodeNew' in globals():
return
zipcodeNew = re.sub(' ', '', zipcodeNew)
zipcodeNew = zipcodeNew.upper()
Expand All @@ -191,7 +193,7 @@ def location():
lineupsN = ['AVAILABLE LINEUPS', 'TIMEZONE - Eastern', 'TIMEZONE - Central', 'TIMEZONE - Mountain', 'TIMEZONE - Pacific']
lineupsC = ['NONE', 'DFLTEC', 'DFLTCC', 'DFLTMC', 'DFLTPC']
deviceX = ['-', '-', '-', '-', '-']
content = urllib2.urlopen(url).read()
content = urllib.request.urlopen(url).read()
lineupDict = json.loads(content)
if 'Providers' in lineupDict:
for provider in lineupDict['Providers']:
Expand Down Expand Up @@ -238,7 +240,7 @@ def location():
def run():
logging.basicConfig(filename=log, filemode='w', format='%(asctime)s %(message)s', datefmt='%Y/%m/%d %H:%M:%S', level=logging.DEBUG)
status = zap2epg.mainRun(userdata)
dialog.ok('zap2epg Finished!', 'zap2epg completed in ' + str(status[0]) + ' seconds.', '', str(status[1]) + ' Stations and ' + str(status[2]) + ' Episodes written to xmltv.xml file.')
dialog.ok('zap2epg Finished!', 'zap2epg completed in ' + str(status[0]) + ' seconds.\n' + str(status[1]) + ' Stations and ' + str(status[2]) + ' Episodes written to xmltv.xml file.')



Expand All @@ -253,25 +255,25 @@ def index():
items.append(
{
'label': 'Run zap2epg and Update Guide Data',
'path': plugin.url_for(u'run'),
'path': plugin.url_for('run'),
'thumbnail':get_icon_path('run'),
})
items.append(
{
'label': 'Change Current Location | Zipcode: ' + zipcode + ' & Lineup: ' + lineup,
'path': plugin.url_for(u'location'),
'path': plugin.url_for('location'),
'thumbnail':get_icon_path('antenna'),
})
items.append(
{
'label': 'Configure Channel List',
'path': plugin.url_for(u'channels'),
'path': plugin.url_for('channels'),
'thumbnail':get_icon_path('channel'),
})
items.append(
{
'label': 'Configure Settings and Options',
'path': plugin.url_for(u'open_settings'),
'path': plugin.url_for('open_settings'),
'thumbnail':get_icon_path('settings'),
})
return items
Expand All @@ -287,7 +289,7 @@ def index():
lineup = xbmcaddon.Addon().getSetting('lineup')
device = xbmcaddon.Addon().getSetting('device')
if zipcode == '' or lineup == '':
zipConfig = dialog.yesno('No Lineup Configured!', 'You need to configure your lineup location before running zap2epg.', '', 'Would you like to setup your lineup?')
zipConfig = dialog.yesno('No Lineup Configured!', 'You need to configure your lineup location before running zap2epg.\n\nWould you like to setup your lineup?')
if zipConfig:
location()
xbmc.executebuiltin('Container.Refresh')
Expand Down
62 changes: 58 additions & 4 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ msgctxt "#32006"
msgid "Device"
msgstr ""

# 32007-32010 blank
# 32007-32009 blank

msgctxt "#32010"
msgid "Data Handling"
msgstr ""

msgctxt "#32011"
msgid "Options"
Expand All @@ -52,7 +56,20 @@ msgctxt "#32015"
msgid "Number of Days to Delete Cache (re-download)"
msgstr ""

# 32016-32019 blank
msgctxt "#32016"
msgid "Remove unsafe Windows® characters from Show Titles"
msgstr ""

msgctxt "#32017"
msgid "Remove unsafe Windows® characters from Episode Titles"
msgstr ""

msgctxt "#32018"
msgid "Replace unsafe characters with: "
msgstr ""

msgctxt "#32019"
msgid "Default language:"

msgctxt "#32020"
msgid "Include Episode Thumbnail"
Expand All @@ -70,7 +87,28 @@ msgctxt "#32023"
msgid "Episode Image"
msgstr ""

# 32024-32029 blank
msgctxt "#32024"
msgid "Use Language Identification (requires langid module)"
msgstr ""

msgctxt "#32025"
msgid "English"
msgstr ""

msgctxt "#32026"
msgid "Spanish"
msgstr ""

msgctxt "#32027"
msgid "French"
msgstr ""


# 32028 blank

msgctxt "#32029"
msgid "Use hex values for genre type instead of textual name"
msgstr ""

msgctxt "#32030"
msgid "Include Episode Genres (colored EPG grid)"
Expand Down Expand Up @@ -222,7 +260,15 @@ msgctxt "#32229"
msgid "20"
msgstr ""

# 32230-32299 blank
msgctxt "#32230"
msgid "21"
msgstr ""

msgctxt "#32231"
msgid "22"
msgstr ""

# 32232-32299 blank

msgctxt "#32300"
msgid "None"
Expand Down Expand Up @@ -284,6 +330,14 @@ msgctxt "#32314"
msgid "Movie Release Year"
msgstr ""

msgctxt "#32315"
msgid "Genres"
msgstr ""

msgctxt "#32316"
msgid "Determined Language"
msgstr ""

msgctxt "#32320"
msgid "LINE BREAK"
msgstr ""
Expand Down
Loading

0 comments on commit f5c6cab

Please sign in to comment.