Skip to content

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
Add support for NextPVR as a source
  • Loading branch information
emveepee committed Nov 14, 2023
1 parent 04f6bd5 commit fda8c19
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 7 deletions.
6 changes: 4 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.zap2epg" name="zap2epg" version="2.0.3" provider-name="edit4ever">
<addon id="script.module.zap2epg" name="zap2epg" version="2.1.0" provider-name="edit4ever">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.dateutil" version="2.4.2"/>
Expand All @@ -18,7 +18,7 @@ Setup:
2. Run the addon and setup your lineup
3. Configure your channel list (add channels to be downloaded)
4. You can run the program from the addon as a test (not necessary)
5. Setup the zap2epg grabber in tvheadend
5. Setup the zap2epg grabber in tvheadend or xmltv in NextPVR
6. Enjoy your new EPG!</description>
<disclaimer lang="en_gb"></disclaimer>
<language></language>
Expand All @@ -29,6 +29,8 @@ Setup:
<email></email>
<source></source>
<news>
v2.1.0 - added NextPVR option. (2022-09-xx)
- fixes for Kodi 19/20.
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)
Expand Down
83 changes: 82 additions & 1 deletion default.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,56 @@
import logging
import zap2epg
import urllib.request, urllib.error, urllib.parse
from urllib.request import urlopen,Request
import json
from collections import OrderedDict
import time
import datetime
import _strptime
import requests

def sidLogin():
global nextpvr_sid
method = 'session.initiate&ver=1.0&device=zap2epg'
ret, keys = doRequest(method)
if ret == True:
nextpvr_sid = keys['sid']
salt = keys['salt']
method = 'session.login&md5=' + hashMe(':' + hashMe(nextpvr_pin) + ':' + salt)
ret, login = doRequest(method)
if ret and login['stat'] == 'ok':
nextpvr_sid = login['sid']

def doRequest(method, isJSON = True):
retval = False
getResult = None
url = "http://" + nextpvr_url + ":" + str(nextpvr_port) + '/service?method=' + method
if not 'session.initiate' in method:
url += '&sid=' + nextpvr_sid

print(url)
try:
request = Request(url, headers={"Accept" : "application/json"})
json_file = urlopen(request, timeout=5)
getResult = json.load(json_file)
json_file.close()
print(json.dumps(getResult))
retval = True
except Exception as e:
print(str(e))

return retval, getResult

def hashMe (thedata):
import hashlib
h = hashlib.md5()
h.update(thedata.encode('utf-8'))
return h.hexdigest()


userdata = xbmcvfs.translatePath(xbmcaddon.Addon().getAddonInfo('profile'))
tvhoff = xbmcaddon.Addon().getSetting('tvhoff')
nextpvroff = xbmcaddon.Addon().getSetting('nextpvroff')
if not os.path.exists(userdata):
os.mkdir(userdata)
log = os.path.join(userdata, 'zap2epg.log')
Expand All @@ -43,6 +84,13 @@
dialog = xbmcgui.Dialog()
gridtime = (int(time.mktime(time.strptime(str(datetime.datetime.now().replace(microsecond=0,second=0,minute=0)), '%Y-%m-%d %H:%M:%S'))))

if tvhoff == 'true' and nextpvroff == 'true' :
backend = dialog.yesno('Multiple server error', 'Please choose NextPVR or TVHeadend','TVHeadend' ,'NextPVR')
if backend:
tvhoff = 'false'
else:
nextpvroff = 'false'

if tvhoff == 'true':
try:
tvh_url_get = xbmcaddon.Addon('pvr.hts').getSetting("host")
Expand Down Expand Up @@ -80,7 +128,20 @@
except requests.exceptions.HTTPError as err:
dialog.ok("Tvheadend Access Error!", str(err) +'\nPlease check your username/password in settings.')
except requests.exceptions.RequestException as e:
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.")
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.")



if nextpvroff == 'true':

nextpvr_url = xbmcaddon.Addon().getSetting('nextpvrurl')
nextpvr_port = xbmcaddon.Addon().getSetting('nextpvrport')
nextpvr_pin = xbmcaddon.Addon().getSetting('nextpvrpin')
global nextpvr_sid
nextpvr_sid = None
sidLogin()
if nextpvr_sid == None:
dialog.ok("NextPVR Access Error!", "Could not connect to NextPVR server.\nPlease check your NextPVR server settings.")

def get_icon_path(icon_name):
addon_path = xbmcaddon.Addon().getAddonInfo("path")
Expand All @@ -106,6 +167,25 @@ def create_cList():
channelEnabled = ch['enabled']
if channelEnabled == True:
tvhClist.append(ch['number'])
if nextpvroff == 'true':
if not os.path.isfile(tvhList):
if nextpvr_sid == None:
sidLogin()
ret, channels = doRequest('channel.list&extras=true')
doRequest('session.logout')
try:
logging.info('Accessing NextPVR channel list')
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['channels']:
channelEnabled = ch['channelEPG']
if channelEnabled == 'XMLTV':
tvhClist.append(ch['channelNumberFormated'])
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 = urllib.request.urlopen(url).read()
Expand Down Expand Up @@ -136,6 +216,7 @@ def channels():
newList = dialog.yesno('Existing Channel List Found', 'Would you like to download a new channel list or review your current list?.','Revew' ,'Download')
if newList:
os.remove(Clist)
os.remove(tvhList)
create_cList()
with open(Clist) as data:
stationDict = json.load(data)
Expand Down
11 changes: 10 additions & 1 deletion resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,16 @@ msgctxt "#32049"
msgid "Tvheadend Options Enabled"
msgstr ""

# 32050-32199 blank
msgctxt "#32050"
msgid "NextPVR"
msgstr ""

msgctxt "#32051"
msgid "NextPVR PIN"
msgstr ""


# 32052-32199 blank

msgctxt "#32200"
msgid "X-Details Order"
Expand Down
9 changes: 8 additions & 1 deletion resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<setting label="32229" type="enum" id="desc20" default="0" lvalues="32300|32301|32320|32302|32321|32322|32323|32324|32325|32303|32304|32305|32306|32307|32308|32309|32310|32311|32312|32313|32314"/>
</category>
<category label="32040">
<setting label="32049" type="bool" id="tvhoff" default="true"/>
<setting label="32049" type="bool" id="tvhoff" default="false"/>
<setting type="sep"/>
<setting label="32045" enable="eq(-2,true)" type="ipaddress" id="tvhurl" default="127.0.0.1"/>
<setting label="32046" enable="eq(-3,true)" type="number" id="tvhport" default="9981"/>
Expand All @@ -42,6 +42,13 @@
<setting label="32043" enable="eq(-6,true)" type="bool" id="chmatch" default="true"/>
<setting label="32044" enable="eq(-7,true)" type="bool" id="tvhmatch" default="true"/>
</category>
<category label="32050">
<setting label="32049" type="bool" id="nextpvroff" default="false"/>
<setting type="sep"/>
<setting label="32045" enable="eq(-2,true)" type="ipaddress" id="nextpvrurl" default="127.0.0.1"/>
<setting label="32046" enable="eq(-3,true)" type="number" id="nextpvrport" default="8866"/>
<setting label="32051" enable="eq(-4,true)" type="text" id="nextpvrpin" default="0000"/>
</category>
<category label="32001">
<setting label="32002" type="text" id="zipcode" default=""/>
<setting label="32003" type="text" id="lineup" default=""/>
Expand Down
6 changes: 4 additions & 2 deletions zap2epg.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def mainRun(userdata):
tvhmatch = settingsDict[setting]
if setting == 'stitle':
stitle = settingsDict[setting]
if setting == 'nextpvroff':
nextpvroff = settingsDict[setting]
if setting.startswith('desc'):
xdescOrderDict[setting] = (settingsDict[setting])
xdescOrder = [value for (key, value) in sorted(xdescOrderDict.items())]
Expand All @@ -99,7 +101,7 @@ def mainRun(userdata):
country = 'USA'
else:
country = 'CAN'
logging.info('Running zap2epg-2.0.1 for zipcode: %s and lineup: %s', zipcode, lineup)
logging.info('Running zap2epg-2.1.0 for zipcode: %s and lineup: %s', zipcode, lineup)
pythonStartTime = time.time()
cacheDir = os.path.join(userdata, 'cache')
dayHours = int(days) * 8 # set back to 8 when done testing
Expand Down Expand Up @@ -260,7 +262,7 @@ def printHeader(fh, enc):
logging.info('Creating xmltv.xml file...')
fh.write("<?xml version=\"1.0\" encoding=\""+ enc + "\"?>\n")
fh.write("<!DOCTYPE tv SYSTEM \"xmltv.dtd\">\n\n")
fh.write("<tv source-info-url=\"http://tvschedule.zap2it.com/\" source-info-name=\"zap2it.com\">\n")
fh.write("<tv source-info-url=\"http://tvschedule.zap2it.com/\" generator=\"zap2xml\" source-info-name=\"zap2it.com\">\n")

def printFooter(fh):
fh.write("</tv>\n")
Expand Down

0 comments on commit fda8c19

Please sign in to comment.