Skip to content

Commit 63e2fd9

Browse files
committed
update to Python 3
1 parent 1cc4ded commit 63e2fd9

File tree

4 files changed

+44
-40
lines changed

4 files changed

+44
-40
lines changed

addon.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
22
<addon id="script.module.tvh2kodi"
33
name="TVheadend Setup"
4-
version="2.1.1"
4+
version="3.0.0"
55
provider-name="edit4ever">
66
<requires>
7-
<import addon="xbmc.python" version="2.6.0"/>
8-
<import addon="script.module.dateutil" version="2.4.2"/>
9-
<import addon="script.module.xbmcswift2" version="2.4.0"/>
10-
<import addon="script.module.requests" version="2.9.1" />
7+
<import addon="xbmc.python" version="3.0.0" />
8+
<import addon="script.module.dateutil" version="2.8.1"/>
9+
<import addon="script.module.xbmcswift2" version="19.0.5"/>
10+
<import addon="script.module.requests" version="2.22.0" />
1111
</requires>
1212
<extension point="xbmc.python.pluginsource" library="default.py">
1313
<provides>executable</provides>
@@ -30,7 +30,8 @@
3030
<screenshot>resources/screenshot-03.jpg</screenshot>
3131
</assets>
3232
<news>
33-
2.1 - add support for mapping selected services to channels
33+
3.0 - Convert to Python 3
34+
2.1 - add support for mapping selected services to channels
3435
</news>
3536
</extension>
3637
</addon>

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v3.0 (2021-07-14)
2+
- convert to Python 3
3+
14
v2.1 (2018-01-04)
25
- add support for mapping selected services to channels
36

default.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222
import subprocess
2323
from subprocess import Popen
2424
from xbmcswift2 import Plugin
25-
import StringIO
25+
import io
2626
import os
2727
import re
2828
import requests
2929
import sys
3030
import json
31-
import urllib2
31+
import urllib.request, urllib.error, urllib.parse
3232
import time
3333
import ast
3434
import zipfile
3535
import datetime
36-
import urllib
36+
import urllib.request, urllib.parse, urllib.error
3737
import picons
3838

3939
plugin = Plugin()
@@ -228,7 +228,7 @@ def _ArchiveDirectory(parentDirectory):
228228
if os.path.islink(fullPath):
229229
zipInfo = zipfile.ZipInfo(archiveRoot)
230230
zipInfo.create_system = 3
231-
zipInfo.external_attr = 2716663808L
231+
zipInfo.external_attr = 2716663808
232232
zipOut.writestr(zipInfo, os.readlink(fullPath))
233233
else:
234234
zipOut.write(fullPath, archiveRoot, zipfile.ZIP_DEFLATED)
@@ -551,9 +551,9 @@ def muxes_load(net_uuid_sel):
551551
except:
552552
for mux_f in muxes['entries']:
553553
muxes_frequency.append(mux_f['channel_number'])
554-
muxes_full = zip(muxes_name, muxes_network,)
554+
muxes_full = list(zip(muxes_name, muxes_network,))
555555
muxes_list = ["%s %s" % x for x in muxes_full]
556-
muxes_frequency, muxes_list, muxes_uuid = zip(*sorted(zip(muxes_frequency, muxes_list, muxes_uuid)))
556+
muxes_frequency, muxes_list, muxes_uuid = list(zip(*sorted(zip(muxes_frequency, muxes_list, muxes_uuid))))
557557
create_mux = "CREATE NEW MUX"
558558
muxes_list = list(muxes_list)
559559
muxes_list.insert(0,create_mux)
@@ -1178,7 +1178,7 @@ def ch_param_edit(ch_uuid_sel, ch_info_list, ch_enabled, ch_autoname, ch_name, c
11781178
epg_list_text = [x['names'] for x in epg_grid_load['entries']]
11791179
epg_list_id = [x['id'] for x in epg_grid_load['entries']]
11801180
epg_list_uuid = [x['uuid'] for x in epg_grid_load['entries']]
1181-
epg_list_full = zip(epg_list_text, epg_list_id)
1181+
epg_list_full = list(zip(epg_list_text, epg_list_id))
11821182
epg_list_list = ["%s - %s" % x for x in epg_list_full]
11831183
sel_epg = dialog.select('Select EPG source for channel: ' + str(ch_number) + " " + str(ch_name), list=epg_list_list)
11841184
if sel_epg < 0:
@@ -1223,13 +1223,13 @@ def cron_edit(epg_intcron):
12231223
if cron_edit_sel:
12241224
cron_sel_weekday = dialog.select('Select which day(s) to run the grabber', list=cron_def_weekday_list)
12251225
if cron_sel_weekday >= 0:
1226-
cron_new_weekday = cron_def_weekday.keys()[cron_def_weekday.values().index(cron_def_weekday_list[cron_sel_weekday])]
1226+
cron_new_weekday = list(cron_def_weekday.keys())[list(cron_def_weekday.values()).index(cron_def_weekday_list[cron_sel_weekday])]
12271227
cron_sel_hour = dialog.select('Select which hour(s) to run the grabber', list=cron_def_split_hour_list)
12281228
if cron_sel_hour == 0:
12291229
cron_sel_hour_spec = dialog.select('Select which hour(s) to run the grabber', list=cron_def_hours)
12301230
cron_new_hour = cron_sel_hour_spec
12311231
if cron_sel_hour > 0:
1232-
cron_new_hour = cron_def_split_hour.keys()[cron_def_split_hour.values().index(cron_def_split_hour_list[cron_sel_hour])]
1232+
cron_new_hour = list(cron_def_split_hour.keys())[list(cron_def_split_hour.values()).index(cron_def_split_hour_list[cron_sel_hour])]
12331233
cron_new_min = dialog.input('Enter the minutes after the hour to run the grabber', defaultt='0', type=xbmcgui.INPUT_NUMERIC)
12341234
cron_update = str(cron_new_min) + ' ' + str(cron_new_hour) + ' ' + cron_new_weekday + ' * *'
12351235
return cron_update
@@ -1309,7 +1309,7 @@ def epgmod_list_load():
13091309
epg_modlist_enabled.append(str(e['status']))
13101310
epg_modlist_enabled = [w.replace('epggrabmodNone', ' ** DISABLED **') for w in epg_modlist_enabled]
13111311
epg_modlist_enabled = [w.replace('epggrabmodEnabled', ' ') for w in epg_modlist_enabled]
1312-
epg_modlist_full = zip(epg_modlist_name, epg_modlist_enabled)
1312+
epg_modlist_full = list(zip(epg_modlist_name, epg_modlist_enabled))
13131313
epg_modlist_list = ["%s %s" % x for x in epg_modlist_full]
13141314
epg_modlist_list, epg_modlist_uuid = (list(t) for t in zip(*sorted(zip(epg_modlist_list, epg_modlist_uuid))))
13151315
sel_epgmod = dialog.select('Select an EPG grabber module to configure', list=epg_modlist_list)
@@ -2644,7 +2644,7 @@ def adapters():
26442644
adapter_enabled.append(str(adapter_e['params'][0]['value']))
26452645
adapter_enabled = [w.replace('False', ' ** DISABLED **') for w in adapter_enabled]
26462646
adapter_enabled = [w.replace('True', ' ') for w in adapter_enabled]
2647-
adapters_full = zip(adapter_text, adapter_enabled)
2647+
adapters_full = list(zip(adapter_text, adapter_enabled))
26482648
adapters_list = ["%s %s" % x for x in adapters_full]
26492649
sel_adapter = dialog.select('Select which adapter you would like to configure', list=adapters_list)
26502650
if sel_adapter >= 0:
@@ -2722,7 +2722,7 @@ def channels():
27222722
channels_enabled.append(str(ch_e['enabled']))
27232723
channels_enabled = [w.replace('False', ' ** DISABLED **') for w in channels_enabled]
27242724
channels_enabled = [w.replace('True', ' ') for w in channels_enabled]
2725-
channels_full = zip(channels_name, channels_enabled)
2725+
channels_full = list(zip(channels_name, channels_enabled))
27262726
channels_list = ["%s %s" % x for x in channels_full]
27272727
sel_ch = dialog.select('Select a channel to configure', list=channels_list)
27282728
if sel_ch >= 0:
@@ -2987,73 +2987,73 @@ def index():
29872987
items.append(
29882988
{
29892989
'label': 'Adapters Configuration',
2990-
'path': plugin.url_for(u'adapters'),
2990+
'path': plugin.url_for('adapters'),
29912991
'thumbnail':get_icon_path('adapter'),
29922992
})
29932993
items.append(
29942994
{
29952995
'label': 'Networks Configuration',
2996-
'path': plugin.url_for(u'networks'),
2996+
'path': plugin.url_for('networks'),
29972997
'thumbnail':get_icon_path('antenna'),
29982998
})
29992999
items.append(
30003000
{
30013001
'label': 'Muxes Configuration',
3002-
'path': plugin.url_for(u'muxes'),
3002+
'path': plugin.url_for('muxes'),
30033003
'thumbnail':get_icon_path('signal'),
30043004
})
30053005
items.append(
30063006
{
30073007
'label': 'Channels Configuration',
3008-
'path': plugin.url_for(u'channels'),
3008+
'path': plugin.url_for('channels'),
30093009
'thumbnail':get_icon_path('numlist'),
30103010
})
30113011
items.append(
30123012
{
30133013
'label': 'Scan for New Channels',
3014-
'path': plugin.url_for(u'mux_scan'),
3014+
'path': plugin.url_for('mux_scan'),
30153015
'thumbnail':get_icon_path('frequency'),
30163016
})
30173017
items.append(
30183018
{
30193019
'label': 'Map Services to Channels',
3020-
'path': plugin.url_for(u'services'),
3020+
'path': plugin.url_for('services'),
30213021
'thumbnail':get_icon_path('folder'),
30223022
})
30233023
items.append(
30243024
{
30253025
'label': 'EPG Grabber Configuration',
3026-
'path': plugin.url_for(u'epg'),
3026+
'path': plugin.url_for('epg'),
30273027
'thumbnail':get_icon_path('list'),
30283028
})
30293029
items.append(
30303030
{
30313031
'label': 'DVR Configuration',
3032-
'path': plugin.url_for(u'dvr'),
3032+
'path': plugin.url_for('dvr'),
30333033
'thumbnail':get_icon_path('dvr'),
30343034
})
30353035
items.append(
30363036
{
30373037
'label': 'Conditional Access Clients',
3038-
'path': plugin.url_for(u'cas'),
3038+
'path': plugin.url_for('cas'),
30393039
'thumbnail':get_icon_path('cas'),
30403040
})
30413041
items.append(
30423042
{
30433043
'label': 'Tvh Base Configuration & Backup',
3044-
'path': plugin.url_for(u'tvh'),
3044+
'path': plugin.url_for('tvh'),
30453045
'thumbnail':get_icon_path('settings'),
30463046
})
30473047
items.append(
30483048
{
30493049
'label': 'Start Wizard',
3050-
'path': plugin.url_for(u'wizard'),
3050+
'path': plugin.url_for('wizard'),
30513051
'thumbnail':get_icon_path('wand'),
30523052
})
30533053
items.append(
30543054
{
30553055
'label': 'Tvheadend Backend: ' + tvh_url + ':' + tvh_port,
3056-
'path': plugin.url_for(u'tvhclient'),
3056+
'path': plugin.url_for('tvhclient'),
30573057
'thumbnail':get_icon_path('server'),
30583058
})
30593059

picons.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
################################################################################
2020

2121
import os, xbmc, xbmcaddon, xbmcgui
22-
import json, urllib, urllib2, subprocess, time, zipfile
22+
import json, urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse, subprocess, time, zipfile
2323
import shutil, datetime, sys
24-
from urlparse import urlparse
24+
from urllib.parse import urlparse
2525
from os.path import splitext
2626

2727
addon = xbmcaddon.Addon(id='script.module.tvh2kodi')
@@ -34,7 +34,7 @@
3434
picons_dest = xbmc.translatePath(xbmcaddon.Addon().getSetting('pdest'))
3535
pdest = os.path.join(picons_dest)
3636
url_latest = 'http://cvh.libreelec.tv/picons/latest2.json'
37-
latest_json = urllib.urlopen(url_latest)
37+
latest_json = urllib.request.urlopen(url_latest)
3838
log_json = os.path.join(addondata, 'data/log.json')
3939
log3rdparty = os.path.join(addondata, 'data/3rdparty.log')
4040
logfile = os.path.join(addondata, 'data')
@@ -114,16 +114,16 @@ def delete_file(path):
114114
def subprocess_cmd(command):
115115
process = subprocess.Popen(command,stdout=subprocess.PIPE, shell=True)
116116
proc_stdout = process.communicate()[0].strip()
117-
print proc_stdout
117+
print(proc_stdout)
118118

119119
def downloader(url,dest, header):
120120
dp.create(header,"Downloading","Please Wait...")
121-
urllib.urlretrieve(url,dest,lambda nb, bs, fs, url=url: _pbhook(nb,bs,fs,url,dp))
121+
urllib.request.urlretrieve(url,dest,lambda nb, bs, fs, url=url: _pbhook(nb,bs,fs,url,dp))
122122

123123
def _pbhook(numblocks, blocksize, filesize, url=None,dp=None):
124124
try:
125125
percent = min((numblocks*blocksize*100)/filesize, 100)
126-
print percent
126+
print(percent)
127127
dp.update(percent)
128128
except:
129129
percent = 100
@@ -164,8 +164,8 @@ def extract_zip(_in, _out, dp, header):
164164
update = count / nFiles * 100
165165
dp.update(int(update))
166166
zin.extract(item, _out)
167-
except Exception, e:
168-
print str(e)
167+
except Exception as e:
168+
print(str(e))
169169
return False
170170
return True
171171

@@ -175,7 +175,7 @@ def picons_get(url_base, urljson, picons_file):
175175
picons_file_ext = picons_file + ".tar.zst"
176176
packageFile = os.path.join(tempfolder, picons_file_ext)
177177
url = url_base + ".tar.zst"
178-
check_file = urllib.urlopen(url)
178+
check_file = urllib.request.urlopen(url)
179179
if check_file.getcode() == 200:
180180
downloader(url,packageFile,header)
181181
create_directories(pdest)
@@ -195,7 +195,7 @@ def picons_get(url_base, urljson, picons_file):
195195
picons_file_ext = picons_file + ".tar.xz"
196196
packageFile = os.path.join(tempfolder, picons_file_ext)
197197
url = url_base + ".tar.xz"
198-
check_file = urllib.urlopen(url)
198+
check_file = urllib.request.urlopen(url)
199199
if check_file.getcode() == 200:
200200
downloader(url,packageFile,header)
201201
create_directories(pdest)

0 commit comments

Comments
 (0)