Hi guys - I need some help with a Kodi addon (UKTVNOW) - I'd like to modify the addon so that it no longer prompts everytime I select a channel to watch, asking me to choose either HTTP or RTMP for the stream. Essentially I just want to disable the dialogue box altogether and force HTTP everytime.
Here's the default.py in the addon directory (I believe this is the file to edit)
Any help appreciated
Here's the default.py in the addon directory (I believe this is the file to edit)
Code:
import urllib,urllib2,sys,re,xbmcplugin,xbmcgui,xbmcaddon,xbmc,os,json,random,string,base64,hashlib,pyaes
import net
AddonID ='plugin.video.uktvnow.net'
fanart = xbmc.translatePath(os.path.join('special://home/addons/' + AddonID , 'fanart.jpg'))
icon = xbmc.translatePath(os.path.join('special://home/addons/' + AddonID, 'icon.png'))
artpath = xbmc.translatePath(os.path.join('special://home/addons/' + AddonID + '/resources/art/'))
thumbpath = xbmc.translatePath(os.path.join('special://home/addons/' + AddonID + '/resources/thumbs/'))
dialog = xbmcgui.Dialog()
selfAddon = xbmcaddon.Addon(id=AddonID)
Username='-1'
net2 = net.Net()
class SafeString(str):
def title(self):
return self
def capitalize(self):
return self
def Main():
addDir('All Channels','0',1,artpath+'all.PNG',fanart)
addDir('Entertainment','1',1,artpath+'ent.PNG',fanart)
addDir('Movies','2',1,artpath+'mov.PNG',fanart)
addDir('Music','3',1,artpath+'mus.PNG',fanart)
addDir('News','4',1,artpath+'news.PNG',fanart)
addDir('Sports','5',1,artpath+'sport.PNG',fanart)
addDir('Documentary','6',1,artpath+'doc.PNG',fanart)
addDir('Kids','7',1,artpath+'kids.PNG',fanart)
addDir('Food','8',1,artpath+'food.PNG',fanart)
addDir('USA','10',1,artpath+'us.PNG',fanart)
addDir('Others','11',1,artpath+'others.PNG',fanart)
xbmc.executebuiltin('Container.SetViewMode(500)')
def GetContent(catid):
if catid=='0':
token=GetToken('/uktvnow8/index.php?case=get_all_channels',Username)
postdata={SafeString('username'):Username}
else:
token=GetToken('/uktvnow8/index.php?case=get_channel_by_catid',Username+catid)
postdata={SafeString('username'):Username,SafeString('cat_id'):catid}
headers={'User-Agent':'USER-AGENT-UKTVNOW-APP-V2',SafeString('app-token'):token}
if catid=='0':
channels = net2.http_POST('http://uktvnow.net/uktvnow8/index.php?case=get_all_channels',postdata, headers).content
else:
channels = net2.http_POST('http://uktvnow.net/uktvnow8/index.php?case=get_channel_by_catid',postdata, headers).content
channels = channels.replace('\/','/')
match=re.compile('"pk_id":"(.+?)","channel_name":"(.+?)","img":"(.+?)","http_stream":"(.+?)","rtmp_stream":"(.+?)","cat_id":"(.+?)"').findall(channels)
return match
def GetToken(url,username):
return '37a6259cc0c1dae299a7866489dff0bd'
def GetChannels(catid):
match = GetContent(catid)
image = urllib.URLopener()
i = 0.0
cancel = False
progress=None
for channelid,name,iconimage,stream1,stream2,cat in match:
i = i + 1.0
filename = thumbpath+iconimage.split("?")[0].split("/")[-1]
if not cancel and not os.path.isfile(filename):
if progress==None:
progress = xbmcgui.DialogProgress()
progress.create('UKTVNow.net', 'Downloading channel images')
xbmc.executebuiltin( 'Dialog.Close(busydialog)' )
if not cancel and progress!=None:
percent = int((100.0 / len(match)) * i)
progress.update( percent, "", name, "" )
if progress.iscanceled():
cancel = True
#xbmc.log(filename, xbmc.LOGNOTICE)
thumb='http://uktvnow.net/uktvnow8/'+iconimage
#xbmc.log(thumb, xbmc.LOGNOTICE)
try:
image.retrieve(thumb,filename)
except IOError, e:
xbmc.log('failed to get image: '+ SafeString(e), xbmc.LOGNOTICE)
addLink(name,'url',2,filename,fanart,channelid)
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE)
xbmc.executebuiltin('Container.SetViewMode(500)')
if progress!=None:
progress.close()
def GetStreams(name,iconimage,channelid):
token = GetToken('http://uktvnow.net/uktvnow8/index.php?case=get_valid_link_revision', Username+channelid)
postdata = {SafeString('channel_id'):channelid,'username':Username}
headers={'User-Agent':'USER-AGENT-UKTVNOW-APP-V2',SafeString('app-token'):token}
channels = net2.http_POST('http://uktvnow.net/uktvnow8/index.php?case=get_valid_link_revision',postdata, headers).content
match=re.compile('"channel_name":"(.+?)","img":".+?","http_stream":"(.+?)","http_stream2":"(.+?)","http_stream3":"(.+?)","rtmp_stream":"(.+?)","rtmp_stream2":"(.+?)","rtmp_stream3":"(.+?)"').findall(channels)
for name,stream1,stream2,stream3,stream4,stream5,stream6 in match:
streamname=[]
streamurl=[]
streamurl.append( stream1 )
streamurl.append( stream4 )
streamname.append( 'HTTP Stream' )
streamname.append( 'RTMP Stream' )
select = dialog.select(name,streamname)
if select == -1:return
else:
url=streamurl[select]
url.strip()
url=magicness(url)
#if 'http' in url: url = url+"|User-Agent=VLC/2.2.4 LibVLC/2.2.4"
#else: url = url+' timeout=10'
ok=True
liz=xbmcgui.ListItem(name, iconImage=iconimage,thumbnailImage=iconimage); liz.setInfo( type="Video", infoLabels={ "Title": name } )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
xbmc.Player().play(url, liz, False)
return ok
def magicness(url):
magic="1579547dfghuh,555eop564dfbaaec,45h4jggf5f6g,f5fg65jj46,wwe324jkl874qq99".split(',')
decryptor = pyaes.new(magic[1], pyaes.MODE_CBC, IV=magic[4])
url= decryptor.decrypt(url.decode("hex")).split('\0')[0]
return url
def addLink(name,url,mode,iconimage,fanart,channelid=''):
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&channelid="+str(channelid)+"&iconimage="+urllib.quote_plus(iconimage)
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name, 'plot': channelid } )
liz.setProperty('fanart_image', fanart)
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=False)
return ok
def addDir(name,url,mode,iconimage,fanart,channelid=''):
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&channelid="+str(channelid)+"&iconimage="+urllib.quote_plus(iconimage)
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name, 'plot': channelid } )
liz.setProperty('fanart_image', fanart)
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
return ok
def get_params():
param=[]
paramstring=sys.argv[2]
if len(paramstring)>=2:
params=sys.argv[2]
cleanedparams=params.replace('?','')
if (params[len(params)-1]=='/'):
params=params[0:len(params)-2]
pairsofparams=cleanedparams.split('&')
param={}
for i in range(len(pairsofparams)):
splitparams={}
splitparams=pairsofparams[i].split('=')
if (len(splitparams))==2:
param[splitparams[0]]=splitparams[1]
return param
def setView(content, viewType):
if content:
xbmcplugin.setContent(int(sys.argv[1]), content)
if selfAddon.getSetting('auto-view')=='true':
xbmc.executebuiltin("Container.SetViewMode(%s)" % selfAddon.getSetting(viewType) )
params=get_params()
url=None
name=None
mode=None
iconimage=None
channelid=None
try:url=urllib.unquote_plus(params["url"])
except:pass
try:name=urllib.unquote_plus(params["name"])
except:pass
try:mode=int(params["mode"])
except:pass
try:iconimage=urllib.unquote_plus(params["iconimage"])
except:pass
try:channelid=urllib.unquote_plus(params["channelid"])
except:pass
if mode==None or url==None or len(url)<1:Main()
elif mode==1:GetChannels(url)
elif mode==2:GetStreams(name,iconimage,channelid)
elif mode==3:Schedule(url)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
Any help appreciated