Skip to content

Commit

Permalink
Initial Python 3 release for Kodi 19
Browse files Browse the repository at this point in the history
  • Loading branch information
edit4ever committed Nov 17, 2020
1 parent 8470afe commit 2c79577
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
5 changes: 3 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.zap2epg" name="zap2epg" version="1.3.0" provider-name="edit4ever">
<addon id="script.module.zap2epg" name="zap2epg" version="2.0.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" />
Expand Down Expand Up @@ -29,6 +29,7 @@ Setup:
<email></email>
<source></source>
<news>
v2.0.0 - Python 3 update
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
5 changes: 4 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
v2.0.0 (2020-10-27)
- Python3 update

v1.3.0 (2019-04-12)
- fix server issues for lineups

v1.2.0 (2019-03-04)
- add option to refresh download cache days

Expand Down
24 changes: 12 additions & 12 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
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
Expand Down Expand Up @@ -97,7 +97,7 @@ def create_cList():
channels = response.json()
with open(tvhList,"w") as f:
json.dump(channels,f)
except urllib2.HTTPError as e:
except urllib.error.HTTPError as e:
logging.exception('Exception: tvhClist - %s', e.strerror)
pass
with open(tvhList) as tvhData:
Expand All @@ -108,7 +108,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,7 +121,7 @@ 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)

Expand All @@ -139,7 +139,7 @@ def channels():
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,7 +150,7 @@ 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:
Expand Down Expand Up @@ -191,7 +191,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 @@ -253,25 +253,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 Down
42 changes: 21 additions & 21 deletions zap2epg.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
################################################################################

import urllib2
import urllib.request, urllib.error, urllib.parse
import base64
import codecs
import time
Expand Down Expand Up @@ -110,11 +110,11 @@ def tvhMatchGet():
channels_url = tvhUrlBase + '/api/channel/grid?all=1&limit=999999999&sort=name&filter=[{"type":"boolean","value":true,"field":"enabled"}]'
if usern is not None and passw is not None:
logging.info('Adding Tvheadend username and password to request url...')
request = urllib2.Request(channels_url)
request = urllib.request.Request(channels_url)
request.add_header('Authorization', b'Basic ' + base64.b64encode(usern + b':' + passw))
response = urllib2.urlopen(request)
response = urllib.request.urlopen(request)
else:
response = urllib2.urlopen(channels_url)
response = urllib.request.urlopen(channels_url)
try:
logging.info('Accessing Tvheadend channel list from: %s', tvhUrlBase)
channels = json.load(response)
Expand All @@ -123,7 +123,7 @@ def tvhMatchGet():
channelNum = ch['number']
tvhMatchDict[channelNum] = channelName
logging.info('%s Tvheadend channels found...', str(len(tvhMatchDict)))
except urllib2.HTTPError as e:
except urllib.error.HTTPError as e:
logging.exception('Exception: tvhMatch - %s', e.strerror)
pass

Expand All @@ -140,7 +140,7 @@ def deleteOldCache(gridtimeStart):
try:
os.remove(fn)
logging.info('Deleting old cache: %s', entry)
except OSError, e:
except OSError as e:
logging.warn('Error Deleting: %s - %s.' % (e.filename, e.strerror))
except Exception as e:
logging.exception('Exception: deleteOldCache - %s', e.strerror)
Expand All @@ -158,7 +158,7 @@ def deleteOldShowCache(showList):
try:
os.remove(fn)
logging.info('Deleting old show cache: %s', entry)
except OSError, e:
except OSError as e:
logging.warn('Error Deleting: %s - %s.' % (e.filename, e.strerror))
except Exception as e:
logging.exception('Exception: deleteOldshowCache - %s', e.strerror)
Expand Down Expand Up @@ -267,9 +267,9 @@ def printStations(fh):
try:
logging.info('Writing Stations to xmltv.xml file...')
try:
scheduleSort = OrderedDict(sorted(schedule.iteritems(), key=lambda x: int(x[1]['chnum'])))
scheduleSort = OrderedDict(sorted(iter(schedule.items()), key=lambda x: int(x[1]['chnum'])))
except:
scheduleSort = OrderedDict(sorted(schedule.iteritems(), key=lambda x: x[1]['chfcc']))
scheduleSort = OrderedDict(sorted(iter(schedule.items()), key=lambda x: x[1]['chfcc']))
for station in scheduleSort:
fh.write('\t<channel id=\"' + station + '.zap2epg\">\n')
if 'chtvh' in scheduleSort[station] and scheduleSort[station]['chtvh'] is not None:
Expand Down Expand Up @@ -533,8 +533,8 @@ def parseXdetails():
url = 'https://tvlistings.zap2it.com/api/program/overviewDetails'
data = 'programSeriesID=' + EPseries
try:
URLcontent = urllib2.Request(url, data=data)
JSONcontent = urllib2.urlopen(URLcontent).read()
URLcontent = urllib.request.Request(url, data=data)
JSONcontent = urllib.request.urlopen(URLcontent).read()
if JSONcontent:
with open(fileDir,"wb+") as f:
f.write(JSONcontent)
Expand All @@ -544,7 +544,7 @@ def parseXdetails():
time.sleep(1)
retry -= 1
logging.warn('Retry downloading missing details data for: %s', EPseries)
except urllib2.URLError, e:
except urllib.error.URLError as e:
time.sleep(1)
retry -= 1
logging.warn('Retry downloading details data for: %s - %s', EPseries, e)
Expand Down Expand Up @@ -583,7 +583,7 @@ def parseXdetails():
os.remove(fileDir)
logging.info('Deleting %s due to TBA listings', filename)
showList.remove(edict['epseries'])
except OSError, e:
except OSError as e:
logging.warn('Error Deleting: %s - %s.' % (e.filename, e.strerror))
except Exception as e:
logging.exception('Could not parse TBAcheck for: %s - %s', episode, e)
Expand Down Expand Up @@ -616,14 +616,14 @@ def addXDetails(edict):
prog = ""
plot= ""
descsort = ""
bullet = u"\u2022 "
hyphen = u"\u2013 "
bullet = "\u2022 "
hyphen = "\u2013 "
newLine = "\n"
space = " "
colon = u"\u003A "
vbar = u"\u007C "
slash = u"\u2215 "
comma = u"\u002C "
colon = "\u003A "
vbar = "\u007C "
slash = "\u2215 "
comma = "\u002C "

def getSortName(opt):
return {
Expand Down Expand Up @@ -759,7 +759,7 @@ def makeDescsortList(optList):
try:
logging.info('Downloading guide data for: %s', str(gridtime))
url = 'http://tvlistings.zap2it.com/api/grid?lineupId=&timespan=3&headendId=' + lineupcode + '&country=' + country + '&device=' + device + '&postalCode=' + zipcode + '&time=' + str(gridtime) + '&pref=-&userId=-'
saveContent = urllib2.urlopen(url).read()
saveContent = urllib.request.urlopen(url).read()
savepage(fileDir, saveContent)
except:
logging.warn('Could not download guide data for: %s', str(gridtime))
Expand All @@ -777,7 +777,7 @@ def makeDescsortList(optList):
try:
os.remove(fileDir)
logging.info('Deleting %s due to TBA listings', filename)
except OSError, e:
except OSError as e:
logging.warn('Error Deleting: %s - %s.' % (e.filename, e.strerror))
except:
logging.warn('JSON file error for: %s - deleting file', filename)
Expand Down

0 comments on commit 2c79577

Please sign in to comment.