Skip to content

Commit 2c79577

Browse files
committed
Initial Python 3 release for Kodi 19
1 parent 8470afe commit 2c79577

File tree

4 files changed

+40
-36
lines changed

4 files changed

+40
-36
lines changed

addon.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="script.module.zap2epg" name="zap2epg" version="1.3.0" provider-name="edit4ever">
2+
<addon id="script.module.zap2epg" name="zap2epg" version="2.0.0" provider-name="edit4ever">
33
<requires>
4-
<import addon="xbmc.python" version="2.7.13"/>
4+
<import addon="xbmc.python" version="3.0.0"/>
55
<import addon="script.module.dateutil" version="2.4.2"/>
66
<import addon="script.module.xbmcswift2" version="2.4.0"/>
77
<import addon="script.module.requests" version="2.9.1" />
@@ -29,6 +29,7 @@ Setup:
2929
<email></email>
3030
<source></source>
3131
<news>
32+
v2.0.0 - Python 3 update
3233
v1.3.0 - fix server issues for lineups (2019-04-12)
3334
v1.2.0 - add option to refresh download cache days (2019-03-04)
3435
v1.1.0 - added ability to refresh TBA episodes (2018-11-20)

changelog.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
v2.0.0 (2020-10-27)
2+
- Python3 update
3+
14
v1.3.0 (2019-04-12)
25
- fix server issues for lineups
3-
6+
47
v1.2.0 (2019-03-04)
58
- add option to refresh download cache days
69

default.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
import subprocess
1818
from subprocess import Popen
1919
from xbmcswift2 import Plugin
20-
import StringIO
20+
import io
2121
import os
2222
import re
2323
import sys
2424
import logging
2525
import zap2epg
26-
import urllib2
26+
import urllib.request, urllib.error, urllib.parse
2727
import json
2828
from collections import OrderedDict
2929
import time
@@ -97,7 +97,7 @@ def create_cList():
9797
channels = response.json()
9898
with open(tvhList,"w") as f:
9999
json.dump(channels,f)
100-
except urllib2.HTTPError as e:
100+
except urllib.error.HTTPError as e:
101101
logging.exception('Exception: tvhClist - %s', e.strerror)
102102
pass
103103
with open(tvhList) as tvhData:
@@ -108,7 +108,7 @@ def create_cList():
108108
tvhClist.append(ch['number'])
109109
lineupcode = xbmcaddon.Addon().getSetting('lineupcode')
110110
url = 'http://tvlistings.zap2it.com/api/grid?lineupId=&timespan=3&headendId=' + lineupcode + '&country=' + country + '&device=' + device + '&postalCode=' + zipcode + '&time=' + str(gridtime) + '&pref=-&userId=-'
111-
content = urllib2.urlopen(url).read()
111+
content = urllib.request.urlopen(url).read()
112112
contentDict = json.loads(content)
113113
stationDict = {}
114114
if 'channels' in contentDict:
@@ -121,7 +121,7 @@ def create_cList():
121121
stationDict[skey]['include'] = 'True'
122122
else:
123123
stationDict[skey]['include'] = 'False'
124-
stationDictSort = OrderedDict(sorted(stationDict.iteritems(), key=lambda i: (float(i[1]['num']))))
124+
stationDictSort = OrderedDict(sorted(iter(stationDict.items()), key=lambda i: (float(i[1]['num']))))
125125
with open(Clist,"w") as f:
126126
json.dump(stationDictSort,f)
127127

@@ -139,7 +139,7 @@ def channels():
139139
create_cList()
140140
with open(Clist) as data:
141141
stationDict = json.load(data)
142-
stationDict = OrderedDict(sorted(stationDict.iteritems(), key=lambda i: (float(i[1]['num']))))
142+
stationDict = OrderedDict(sorted(iter(stationDict.items()), key=lambda i: (float(i[1]['num']))))
143143
stationCode = []
144144
stationListName = []
145145
stationListNum = []
@@ -150,7 +150,7 @@ def channels():
150150
stationListNum.append(stationDict[station]['num'])
151151
stationListInclude.append(stationDict[station]['include'])
152152
stationPre = [i for i, x in enumerate(stationListInclude) if x == 'True']
153-
stationListFull = zip(stationListNum, stationListName)
153+
stationListFull = list(zip(stationListNum, stationListName))
154154
stationList = ["%s %s" % x for x in stationListFull]
155155
selCh = dialog.multiselect('Click to Select Channels to Include', stationList, preselect=stationPre)
156156
for station in stationDict:
@@ -191,7 +191,7 @@ def location():
191191
lineupsN = ['AVAILABLE LINEUPS', 'TIMEZONE - Eastern', 'TIMEZONE - Central', 'TIMEZONE - Mountain', 'TIMEZONE - Pacific']
192192
lineupsC = ['NONE', 'DFLTEC', 'DFLTCC', 'DFLTMC', 'DFLTPC']
193193
deviceX = ['-', '-', '-', '-', '-']
194-
content = urllib2.urlopen(url).read()
194+
content = urllib.request.urlopen(url).read()
195195
lineupDict = json.loads(content)
196196
if 'Providers' in lineupDict:
197197
for provider in lineupDict['Providers']:
@@ -253,25 +253,25 @@ def index():
253253
items.append(
254254
{
255255
'label': 'Run zap2epg and Update Guide Data',
256-
'path': plugin.url_for(u'run'),
256+
'path': plugin.url_for('run'),
257257
'thumbnail':get_icon_path('run'),
258258
})
259259
items.append(
260260
{
261261
'label': 'Change Current Location | Zipcode: ' + zipcode + ' & Lineup: ' + lineup,
262-
'path': plugin.url_for(u'location'),
262+
'path': plugin.url_for('location'),
263263
'thumbnail':get_icon_path('antenna'),
264264
})
265265
items.append(
266266
{
267267
'label': 'Configure Channel List',
268-
'path': plugin.url_for(u'channels'),
268+
'path': plugin.url_for('channels'),
269269
'thumbnail':get_icon_path('channel'),
270270
})
271271
items.append(
272272
{
273273
'label': 'Configure Settings and Options',
274-
'path': plugin.url_for(u'open_settings'),
274+
'path': plugin.url_for('open_settings'),
275275
'thumbnail':get_icon_path('settings'),
276276
})
277277
return items

zap2epg.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
################################################################################
1616

17-
import urllib2
17+
import urllib.request, urllib.error, urllib.parse
1818
import base64
1919
import codecs
2020
import time
@@ -110,11 +110,11 @@ def tvhMatchGet():
110110
channels_url = tvhUrlBase + '/api/channel/grid?all=1&limit=999999999&sort=name&filter=[{"type":"boolean","value":true,"field":"enabled"}]'
111111
if usern is not None and passw is not None:
112112
logging.info('Adding Tvheadend username and password to request url...')
113-
request = urllib2.Request(channels_url)
113+
request = urllib.request.Request(channels_url)
114114
request.add_header('Authorization', b'Basic ' + base64.b64encode(usern + b':' + passw))
115-
response = urllib2.urlopen(request)
115+
response = urllib.request.urlopen(request)
116116
else:
117-
response = urllib2.urlopen(channels_url)
117+
response = urllib.request.urlopen(channels_url)
118118
try:
119119
logging.info('Accessing Tvheadend channel list from: %s', tvhUrlBase)
120120
channels = json.load(response)
@@ -123,7 +123,7 @@ def tvhMatchGet():
123123
channelNum = ch['number']
124124
tvhMatchDict[channelNum] = channelName
125125
logging.info('%s Tvheadend channels found...', str(len(tvhMatchDict)))
126-
except urllib2.HTTPError as e:
126+
except urllib.error.HTTPError as e:
127127
logging.exception('Exception: tvhMatch - %s', e.strerror)
128128
pass
129129

@@ -140,7 +140,7 @@ def deleteOldCache(gridtimeStart):
140140
try:
141141
os.remove(fn)
142142
logging.info('Deleting old cache: %s', entry)
143-
except OSError, e:
143+
except OSError as e:
144144
logging.warn('Error Deleting: %s - %s.' % (e.filename, e.strerror))
145145
except Exception as e:
146146
logging.exception('Exception: deleteOldCache - %s', e.strerror)
@@ -158,7 +158,7 @@ def deleteOldShowCache(showList):
158158
try:
159159
os.remove(fn)
160160
logging.info('Deleting old show cache: %s', entry)
161-
except OSError, e:
161+
except OSError as e:
162162
logging.warn('Error Deleting: %s - %s.' % (e.filename, e.strerror))
163163
except Exception as e:
164164
logging.exception('Exception: deleteOldshowCache - %s', e.strerror)
@@ -267,9 +267,9 @@ def printStations(fh):
267267
try:
268268
logging.info('Writing Stations to xmltv.xml file...')
269269
try:
270-
scheduleSort = OrderedDict(sorted(schedule.iteritems(), key=lambda x: int(x[1]['chnum'])))
270+
scheduleSort = OrderedDict(sorted(iter(schedule.items()), key=lambda x: int(x[1]['chnum'])))
271271
except:
272-
scheduleSort = OrderedDict(sorted(schedule.iteritems(), key=lambda x: x[1]['chfcc']))
272+
scheduleSort = OrderedDict(sorted(iter(schedule.items()), key=lambda x: x[1]['chfcc']))
273273
for station in scheduleSort:
274274
fh.write('\t<channel id=\"' + station + '.zap2epg\">\n')
275275
if 'chtvh' in scheduleSort[station] and scheduleSort[station]['chtvh'] is not None:
@@ -533,8 +533,8 @@ def parseXdetails():
533533
url = 'https://tvlistings.zap2it.com/api/program/overviewDetails'
534534
data = 'programSeriesID=' + EPseries
535535
try:
536-
URLcontent = urllib2.Request(url, data=data)
537-
JSONcontent = urllib2.urlopen(URLcontent).read()
536+
URLcontent = urllib.request.Request(url, data=data)
537+
JSONcontent = urllib.request.urlopen(URLcontent).read()
538538
if JSONcontent:
539539
with open(fileDir,"wb+") as f:
540540
f.write(JSONcontent)
@@ -544,7 +544,7 @@ def parseXdetails():
544544
time.sleep(1)
545545
retry -= 1
546546
logging.warn('Retry downloading missing details data for: %s', EPseries)
547-
except urllib2.URLError, e:
547+
except urllib.error.URLError as e:
548548
time.sleep(1)
549549
retry -= 1
550550
logging.warn('Retry downloading details data for: %s - %s', EPseries, e)
@@ -583,7 +583,7 @@ def parseXdetails():
583583
os.remove(fileDir)
584584
logging.info('Deleting %s due to TBA listings', filename)
585585
showList.remove(edict['epseries'])
586-
except OSError, e:
586+
except OSError as e:
587587
logging.warn('Error Deleting: %s - %s.' % (e.filename, e.strerror))
588588
except Exception as e:
589589
logging.exception('Could not parse TBAcheck for: %s - %s', episode, e)
@@ -616,14 +616,14 @@ def addXDetails(edict):
616616
prog = ""
617617
plot= ""
618618
descsort = ""
619-
bullet = u"\u2022 "
620-
hyphen = u"\u2013 "
619+
bullet = "\u2022 "
620+
hyphen = "\u2013 "
621621
newLine = "\n"
622622
space = " "
623-
colon = u"\u003A "
624-
vbar = u"\u007C "
625-
slash = u"\u2215 "
626-
comma = u"\u002C "
623+
colon = "\u003A "
624+
vbar = "\u007C "
625+
slash = "\u2215 "
626+
comma = "\u002C "
627627

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

0 commit comments

Comments
 (0)