Witam.
Nie mogę sobie poradzić z modyfikacją poniższego kodu pluginu odtwarzacza tv online. Co z niego usunąć lub jak zmodyfikować parametry, by ominać tzw. 'premium' lub ustawiony w kodzie limit darmowego oglądania i zapobiec zakończeniu transmisji?
podaję jeszcze znaczenia ważniejszych "współczynników", które występują w kodzie:
57018 - Błąd odtwarzania!
57019 - Przekroczony limit darmowego oglądania lub zbyt duża ilość użytkowników.
57027 - Serwer zamknął połączenie z nie znanych przyczyn! Spróbuj ponownie
57028 - Odtwarzanie wstrzymane
57034 - Informacje o koncie użytkownika
57035 - Twoje konto posiada status premium
57036 - Nie posiadasz konta premium
jeżeli jeszcze są jakieś potrzebne to proszę dać znać
KOD pluginu:
# -*- coding: utf-8 -*-
import urllib, urllib2, httplib
import re, sys, os, cgi
import xbmcplugin, xbmcgui, xbmcaddon, xbmc, gui
import threading
import simplejson as json
__scriptID__ = sys.modules[ "__main__" ].__scriptID__
t = sys.modules[ "__main__" ].__language__
__addon__ = xbmcaddon.Addon(__scriptID__)
os.path.join( __addon__.getAddonInfo('path'), "resources" )
login = __addon__.getSetting('username')
password = __addon__.getSetting('userpassword')
multi = __addon__.getSetting('video_quality')
display = __addon__.getSetting('list_display')
#confluence: thumb: 500, biglist: 51, normal 50
#transparency: thumb: 53, biglist: 52, normal: 590
SKINS = {
'confluence': { 'opt1': 51, 'opt2': 50 },
'transparency': { 'opt1': 52, 'opt2': 590 }
}
class Settings:
def __init__(self):
pass
def showSettings(self):
__addon__.openSettings(sys.argv[0])
def setApiUrl(self):
return apiUrl
def setIconUrl(self):
return iconUrl
def setViewMode(self, view):
if view != 'orig':
for k,v in SKINS.items():
if k in xbmc.getSkinDir():
if view == 'general':
xbmc.executebuiltin("Container.SetViewMode(" + str(v['opt2']) + ")")
elif view == 'other':
xbmc.executebuiltin("Container.SetViewMode(" + str(v['opt1']) + ")")
class ShowList:
def __init__(self):
pass
def decode(self, string):
json_ustr = json.dumps(string, ensure_ascii=False)
return json_ustr.encode('utf-8')
def JsonToSortedTab(self, json):
strTab = []
outTab = []
for v,k in json.iteritems():
strTab.append(int(v))
strTab.append(k)
outTab.append(strTab)
strTab = []
outTab.sort(key=lambda x: x[0])
return outTab
def getJsonFromAPI(self, url):
s = Settings()
result_json = { "0": "Null" }
try:
headers = { 'User-Agent' : HOST, 'ContentType' : 'application/x-www-form-urlencoded' }
post = { 'username': login, 'userpassword': password }
data = urllib.urlencode(post)
reqUrl = urllib2.Request(url, data, headers)
raw_json = urllib2.urlopen(reqUrl)
content_json = raw_json.read()
result_json = json.loads(content_json)
except urllib2.URLError, urlerr:
msg = Messages()
result_json = { "0": "Error" }
print urlerr
msg.Error(t(57001).encode('utf-8'), t(57002).encode('utf-8'), t(57003).encode('utf-8'))
except NameError, namerr:
msg = Messages()
result_json = { "0": "Error" }
print namerr
msg.Error(t(57009).encode('utf-8'), t(57010).encode('utf-8'))
except ValueError, valerr:
msg = Messages()
result_json = { "0": "Error" }
print valerr
msg.Error(t(57001).encode('utf-8'), t(57011).encode('utf-8'), t(57012).encode('utf-8'), t(57013).encode('utf-8'))
except httplib.BadStatusLine, statuserr:
msg = Messages()
result_json = { "0": "Error" }
print statuserr
msg.Error(t(57001).encode('utf-8'), t(57002).encode('utf-8'), t(57003).encode('utf-8'))
return result_json
def loadChannels(self, url):
action = 0
parser = UrlParser()
params = parser.getParams()
mode = parser.getIntParam(params, "mode")
channelsArray = self.JsonToSortedTab(self.getJsonFromAPI(url))
if len(channelsArray) > 0:
try:
if channelsArray[0][1] == 'Null':
msg = Messages()
msg.Warning(t(57001).encode('utf-8'), t(57004).encode('utf-8'))
elif channelsArray[0][1] != 'Error' and channelsArray[0][1] != 'Null':
for i in range(len(channelsArray)):
k = channelsArray[i][1]
cid = k['cid']
name = self.decode(k['channel_name']).replace("\"", "")
title = self.decode(k['channel_title']).replace("\"", "")
desc = self.decode(k['channel_description']).replace("\"", "")
tags = self.decode(k['channel_tags']).replace("\"", "")
img = k['channel_image']
online = k['channel_online']
rank = k['rank']
bitrate = k['multibitrate']
user = self.decode(k['user_name']).replace("\"", "")
image = iconUrl + "no_video.png"
if img == '1':
image = iconUrl + cid + ".jpg"
if online == '2':
action = 1
else:
action = 0
self.addChannelToXBMC(str(mode), str(action), cid, title, image, desc, tags, user, name)
s = Settings()
s.setViewMode('other')
xbmcplugin.endOfDirectory(int(sys.argv[1]))
if mode == 1:
xbmcplugin.addSortMethod(handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_VIDEO_TITLE)
except KeyError, keyerr:
msg = Messages()
print keyerr
msg.Error(t(57001).encode('utf-8'), t(57025).encode('utf-8'))
else:
msg = Messages()
msg.Error(t(57001).encode('utf-8'), t(57004).encode('utf-8'))
def addChannelToXBMC(self, mode, action, cid, title, img, desc, tags, user, name):
status = t(57033).encode('utf-8')
label = title
if desc == None or desc == '' or desc == 'null':
desc = t(57016).encode('utf-8')
if tags == None or tags == 'null':
tags = t(57017).encode('utf-8')
if title == '':
title = name
if int(action) == 0:
if display == 'color':
status = '[COLOR red]' + t(57030).encode('utf-8') + '[/COLOR]'
elif display == 'gray':
status = t(57030).encode('utf-8')
elif int(action) == 1:
if display == 'color':
status = '[COLOR green]' + t(57029).encode('utf-8') + '[/COLOR]'
elif display == 'gray':
status = t(57029).encode('utf-8')
if display == 'color':
label = ' [B]%s[/B] %s [I]%s[/I] %s [I]%s[/I] [B]%s[/B] ' % (title, t(57031).encode('utf-8'), name, t(57032).encode('utf-8'), user, status)
elif display == 'gray':
label = ' %s %s %s %s %s %s ' % (title, t(57031).encode('utf-8'), name, t(57032).encode('utf-8'), user, status)
liz = xbmcgui.ListItem(label, iconImage = "DefaultFolder.png", thumbnailImage = img)
liz.setProperty("IsPlayable", "false")
liz.setInfo(type = "Video", infoLabels={ "Title": title,
"Plot": desc,
"Studio": "WEEB.TV",
"Tagline": tags,
"Status": status,
"Aired": user } )
u = '%s?mode=%d&action=%d&cid=%d&title=%s' % (sys.argv[0], int(mode), int(action), int(cid), urllib.quote_plus(title))
xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = liz, isFolder = False)
class UrlParser:
def __init__(self):
pass
def getParam(self, params, name):
try:
result = params[name]
result = urllib.unquote_plus(result)
return result
except:
return None
def getIntParam (self, params, name):
try:
param = self.getParam(params, name)
return int(param)
except:
return None
def getBoolParam (self, params, name):
try:
param = self.getParam(params,name)
return 'True' == param
except:
return None
def getParams(self, paramstring = sys.argv[2]):
param=[]
if len(paramstring) >= 2:
params = paramstring
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
class RTMP:
def __init__(self):
pass
def ConnectionParams(self, channel):
data = None
if login == '' and password == '':
values = { 'cid': channel, 'platform': 'XBMC' }
else:
values = { 'cid': channel, 'platform': 'XBMC', 'username': login, 'userpassword': password }
try:
parser = UrlParser()
headers = { 'User-Agent' : HOST }
data = urllib.urlencode(values)
reqUrl = urllib2.Request(playerUrl, data, headers)
response = urllib2.urlopen(reqUrl)
resLink = response.read()
params = parser.getParams(resLink)
status = parser.getParam(params, "0")
premium = parser.getIntParam(params, "5")
rtmpLink = parser.getParam(params, "10")
playPath = parser.getParam(params, "11")
ticket = parser.getParam(params, "73")
data = { 'rtmp': rtmpLink, 'ticket': ticket, 'playpath': playPath, 'premium': premium, 'status': status }
except urllib2.URLError, urlerr:
msg = Messages()
data = { 'rtmp': None, 'ticket': None, 'playpath': None, 'premium': premium, 'status': status }
print urlerr
msg.Error(t(57014).encode('utf-8'), t(57015).encode('utf-8'), t(57003).encode('utf-8'))
return data
def GetLinkParameters(self, channel, bitrate):
dataLink = {}
valTabA = self.ConnectionParams(channel)
rtmpLink = valTabA['rtmp']
ticket = valTabA['ticket']
playpath = valTabA['playpath']
premium = valTabA['premium']
status = valTabA['status']
if bitrate == '1' and multi == 'true':
playpath = playpath + 'HI'
rtmp = str(rtmpLink) + '/' + str(playpath)
rtmp += ' swfUrl=' + str(ticket)
rtmp += ' pageUrl=token'
rtmp += ' live=true'
print 'Output rtmp link: %s' % (rtmp)
return { 'rtmp': rtmp, 'premium': premium, 'status': status }
class VideoPlayer(xbmc.Player):
def __init__(self, *args, **kwargs):
self.is_active = True
print "#Starting control VideoPlayer events#"
def setPremium(self, premium):
self.premium = premium
def getPremium(self):
return self.premium
def onPlayBackPaused(self):
print "#Im paused#"
ThreadPlayerControl("Stop").start()
self.is_active = False
def onPlayBackResumed(self):
print "#Im Resumed #"
def onPlayBackStarted(self):
print "#Playback Started#"
try:
print "#Im playing :: " + self.getPlayingFile()
except:
print "#I failed get what Im playing#"
def onPlayBackEnded(self):
msg = Messages()
print "#Playback Ended#"
self.is_active = False
if self.getPremium() == 0:
msg.Warning(t(57018).encode('utf-8'), t(57019).encode('utf-8'), t(57020).encode('utf-8'))
else:
msg.Warning(t(57018).encode('utf-8'), t(57027).encode('utf-8'))
def onPlayBackStopped(self):
print "## Playback Stopped ##"
self.is_active = False
def sleep(self, s):
xbmc.sleep(s)
class InitPlayer:
def __init__(self):
pass
def getChannelInfoFromJSON(self, channel):
chan = ShowList()
dataInfo = { 'title': '', 'image': '', 'bitrate': '' }
try:
channelsArray = chan.getJsonFromAPI(apiUrl)
for v,k in channelsArray.items():
if channel == int(k['cid']):
cid = k['cid']
title = chan.decode(k['channel_title']).replace("\"", "")
bitrate = k['multibitrate']
img = k['channel_image']
image = iconUrl + "no_video.png"
if img == '1':
image = iconUrl + cid + ".jpg"
dataInfo = { 'title': title, 'image': image, 'bitrate': bitrate }
break
except TypeError, typerr:
print typerr
return dataInfo
def LoadVideoLink(self, channel):
res = True
rtmp = RTMP()
val = self.getChannelInfoFromJSON(channel)
videoLink = rtmp.GetLinkParameters(channel, val['bitrate'])
if videoLink['status'] == '1':
if videoLink['rtmp'].startswith('rtmp'):
liz = xbmcgui.ListItem(val['title'], iconImage = val['image'], thumbnailImage = val['image'])
liz.setInfo( type="Video", infoLabels={ "Title": val['title'], } )
try:
player = VideoPlayer()
player.setPremium(int(videoLink['premium']))
if videoLink['premium'] == 0:
msg = Messages()
msg.Warning(t(57034).encode('utf-8'), t(57036).encode('utf-8'), t(57037).encode('utf-8'), t(57038).encode('utf-8'))
player.play(videoLink['rtmp'], liz)
while player.is_active:
player.sleep(100)
except:
msg = Messages()
msg.Error(t(57018).encode('utf-8'), t(57021).encode('utf-8'), t(57028).encode('utf-8'))
else:
msg = Messages()
msg.Error(t(57018).encode('utf-8'), t(57022).encode('utf-8'))
elif videoLink['status'] == '-1':
msg = Messages()
msg.Warning(t(57018).encode('utf-8'), t(57043).encode('utf-8'))
elif videoLink['status'] == '-2':
msg = Messages()
msg.Warning(t(57018).encode('utf-8'), t(57044).encode('utf-8'))
elif videoLink['status'] == '-3':
msg = Messages()
msg.Warning(t(57018).encode('utf-8'), t(57045).encode('utf-8'))
elif videoLink['status'] == '-4':
msg = Messages()
msg.Warning(t(57018).encode('utf-8'), t(57046).encode('utf-8'), t(57047).encode('utf-8'))
else:
msg = Messages()
msg.Warning(t(57018).encode('utf-8'), t(57042).encode('utf-8'))
return res
class ThreadPlayerControl(threading.Thread):
def __init__(self, command):
self.command = command
threading.Thread.__init__ (self)
def run(self):
xbmc.executebuiltin('PlayerControl(' + self.command + ')')
class Messages:
def __init__(self):
pass
def Error(self, title, text1, text2 = "", text3 = ""):
err = gui.Windows()
err.Error(title, text1, text2, text3)
def Warning(self, title, text1, text2 = "", text3 = ""):
warn = gui.Windows()
warn.Warning(title, text1, text2, text3)
class Handler:
def __init__(self):
pass
def run(self, mode):
s = Settings()
parser = UrlParser()
params = parser.getParams()
url = ""
mode = parser.getIntParam(params, "mode")
cid = parser.getIntParam(params, "cid")
title = parser.getParam(params, "title")
action = parser.getIntParam(params, "action")
if mode > 0 and action == None:
if mode > 0:
showlist = ShowList()
if mode == 1:
url = apiUrl + "&option=online-alphabetical"
elif mode == 2:
url = apiUrl + "&option=online-now-viewed"
elif mode == 3:
url = apiUrl + "&option=online-most-viewed"
elif mode == 4:
url = apiUrl + "&option=offline-ranking"
elif mode == 5:
url = apiUrl + "&option=all-ranking"
showlist.loadChannels(url)
elif mode > 0 and action == 1:
s.setViewMode('other')
if cid > 0 and title != "":
run = InitPlayer()
run.LoadVideoLink(cid)
elif mode > 0 and action == 0:
s.setViewMode('other')
msg = Messages()
msg.Warning(t(57005).encode('utf-8'), t(57006).encode('utf-8'), t(57007).encode('utf-8'), t(57008).encode('utf-8'))