Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xbmcplugin
- import xbmcgui
- import sys
- import urllib, urllib2
- import time
- import re
- import random
- from htmlentitydefs import name2codepoint as n2cp
- thisPlugin = int(sys.argv[1])
- urlHost = "http://rtl-now.rtl.de"
- ajaxUrl = "/xajaxuri.php"
- # -----regexContent-------
- # [0] is url (/foo.php)
- # [1] is name (foo is bar)
- # ------------------------
- # -----regexSeries--------
- # [0] is class even or odd
- # [1] is url to videourl
- # [2] is title
- # [3] is time
- # All content is in!
- # the free-content will be filtered in code (paytype)
- n_regexContent = '<div class="m03medium".*?<div class="m03img">.*?<img.*?src="([^"]+)">.*?<div class="m03text"[^>]*?>.*?<span class="m03date">(FREE|PAY|PRE-TV).*?<h2>(.*?)</h2>(.*?)</div>.*?<div class="m03link">.*?href="([^"]+)" target="_self"([^>]?)>.*?</div>'
- regexContent = '<div class="seriennavi_free" style=""><a href="(.*?)".*?>FREE.*?</div>.*?<div style="" class="seriennavi_link">.*?">(.*?)</a>.*?</div>'
- regexSeries = '<div class="line (even|odd) "><div onclick="link\(\'(.*?)\'\); return false;".*?<a href=".*?" title=".*?">(.*?)</a>.*?class="time">.*?<div.*?</div>(.*?)</div>.*?class="minibutton">(.*?)</a></div></div>'
- n_regexMeta = '<meta property="og:description" content="([^"]+)">.*?<meta property="og:image" content="([^"]+)">'
- regexVideoData = "data:'(.*?)'"
- regexF4mVideo = "http://.*?videos/(.*?).f4m\?ts.*?"
- regexBiggerPic = "(.*?)(\d{3}x\d{3})([^\d]{1})(.*)"
- regexXML = '<filename.*?><!\[CDATA\[(.*?)\]\]></filename>'
- regexTextOnly = '<\s*\/?\s*\s*.*?>'
- regexTabVars = '<select\s*?onchange.*?xajax_show_top_and_movies.*?\'(.*?)\'.*?\'(.*?)\'.*?\'(.*?)\'.*?\'(.*?)\'.*?\'(.*?)\'.*?>(.*?)</select>'
- regexTabEntry = '<option.*?value=\'(\d)\'.*?>'
- # ------------------------
- newRegexContent = '<div class="m03medium".*?</h4>'
- newLinkRegexContent = '<a href="([^"]+?)"'
- newImgRegexContent = '<img.+?src="([^"]+?)">'
- newFreeRegexContent = 'FREE'
- newTitleRegexContent = '<h4>([^<]+?)</h4>'
- newsRegexContent = '<div id="navi_.*?</a>\s*</div>\s*</div>'
- newsLinkRegexContent = 'href="([^"]+?)"'
- newsFreeRegexContent = 'FREE'
- newsTitleRegexContent = '<a class[^<]+?>([^<]+?)</a>'
- def showGenre():
- global thisPlugin
- addDirectoryItem("Serien und Shows", {"urlC": "/sendung_a_z.php"})
- addDirectoryItem("News und Reportagen", {"urlN": "/newsuebersicht.php"})
- #addDirectoryItem("Filme (Pay only)", {"urlC": "/film_a_z.php"})
- xbmcplugin.endOfDirectory(thisPlugin)
- def showContent(urlC):
- global thisPlugin
- print "[phr] -- urlC "+urlC
- content = getUrl(urlC)
- #print "[phr] -- content "+content
- match = re.compile(newRegexContent,re.DOTALL).findall(content)
- for showcontent in match:
- matchLink = re.compile(newLinkRegexContent,re.DOTALL).findall(showcontent)
- matchImg = re.compile(newImgRegexContent,re.DOTALL).findall(showcontent)
- matchFree = re.compile(newFreeRegexContent,re.DOTALL).findall(showcontent)
- matchTitle = re.compile(newTitleRegexContent,re.DOTALL).findall(showcontent)
- link = matchLink[0]
- img = matchImg[0]
- title = matchTitle[0]
- if matchFree:
- print "FREE show: "+title+", link: "+link+", image: "+img
- addDirectoryItem(title, {"urlS": "/"+link}, img)
- else:
- print "PAY show: "+title+", link: "+link+", image: "+img
- print "[phr] --- showContent ok"
- xbmcplugin.endOfDirectory(thisPlugin)
- def showNews(urlN):
- print urlN
- global thisPlugin
- content = getUrl(urlN)
- match = re.compile(newsRegexContent,re.DOTALL).findall(content)
- for showcontent in match:
- #print showcontent
- #print "-----------"
- matchLink = re.compile(newsLinkRegexContent,re.DOTALL).findall(showcontent)
- matchFree = re.compile(newsFreeRegexContent,re.DOTALL).findall(showcontent)
- matchTitle = re.compile(newsTitleRegexContent,re.DOTALL).findall(showcontent)
- link = matchLink[0]
- title = matchTitle[0].strip()
- if matchFree:
- print "FREE show: "+title+", link: "+link+", image: "
- addDirectoryItem(title, {"urlS": "/"+link}, "")
- else:
- print "PAY show: "+title+", link: "+link+", image: "
- print "[phr] --- showContent ok"
- xbmcplugin.endOfDirectory(thisPlugin)
- def showSeries(urlS):
- global thisPlugin
- content = getUrl(urlS)
- meta = re.compile(n_regexMeta,re.DOTALL).findall(content)
- print "[phr] --- MetaData"
- print meta
- vars = re.compile(regexTabVars,re.DOTALL).search(content)
- if vars:
- tabVars = "&xajaxargs[]="+vars.group(1)+"&xajaxargs[]="+vars.group(2)+"&xajaxargs[]="+vars.group(3)+"&xajaxargs[]="+vars.group(4)+"&xajaxargs[]="+vars.group(5)+"&xajax=show_top_and_movies&xajaxr="+str(time.time()).replace('.','')
- tabentries = re.compile(regexTabEntry,re.DOTALL).findall(vars.group(6))
- content = ""
- for te in tabentries:
- ajcon = postUrl(urlHost+ajaxUrl,"xajaxargs[]="+te+tabVars);
- content += ajcon;
- #print content
- match = re.compile(regexSeries,re.DOTALL).findall(content)
- #print match
- for m in match:
- #print m
- if "kostenlos" in m[4]:
- date = remHTML(m[3])
- if date == "232.000x":
- date = ""
- else:
- date = " - " + date
- title = decode_htmlentities(m[2]) + date
- metatext = title.encode("UTF-8") + " : "+decode_htmlentities(meta[0][0])
- print "[phr] -- metatext: "+metatext
- #decode_htmlentities(title + " - " + meta[0][0])
- addPlayableItem(title, {"urlV": m[1], "vidN": m[2]},meta[0][1], metatext)
- ##print m[2]
- print "[phr] --- showSeries ok"
- xbmcplugin.endOfDirectory(thisPlugin)
- def showVideo(urlV, vidN):
- print "[phr] --- showVideo"
- global thisPlugin
- print "[phr] --- "+urlV
- content = getUrl(urlV)
- match=re.compile(regexVideoData).findall(content)
- xmlUrl = urlHost+urllib.unquote(match[0])
- print "[phr] --- "+xmlUrl
- contentB = getUrl(xmlUrl)
- print contentB
- print "[phr] ------DebugOutput showVideo--"
- matchfilename = re.compile(regexXML).findall(contentB)
- if matchfilename[0].find(".f4v.f4m?ts=") != -1:
- f4mXML = getUrl(matchfilename[0])
- #print f4mXML
- videoReged = re.compile(regexF4mVideo).findall(matchfilename[0])
- print "[phr] -- found f4m videourl: "+videoReged[0]
- videoUrl = "rtmpe://fms-fra"+str(random.randint(1, 20))+".rtl.de/rtlnow/"
- playpath = "mp4:"+videoReged[0]
- else:
- print "[phr] -- found flv videourl: "+ matchfilename[0]
- splitted = matchfilename[0].split('/')
- print splitted
- # -----
- videoUrl=splitted[0]+"//"+splitted[2]+"/"+splitted[3]+"/"
- videoUrlB=splitted[2]+"/"+splitted[3]+"/"
- addpre=""
- if splitted[5][-4:-1] == ".f4":
- addpre="mp4:"
- if splitted[5][-4:-1] == ".fl":
- splitted[5]=splitted[5][0:-4]
- playpath = addpre+splitted[4]+"/"+splitted[5]
- #print "[phr] playPath -- "+playpath
- swfUrl = "http://rtl-now.rtl.de/includes/vodplayer.swf"
- pageUrl = "http://rtl-now.rtl.de/p"
- listitem = xbmcgui.ListItem(vidN)
- fullData = videoUrl+' swfVfy=1 playpath='+playpath+' app=rtlnow/_definst_ pageUrl='+pageUrl+'/ tcUrl='+videoUrl+' swfUrl='+swfUrl
- print fullData
- print "[phr] ------------"
- listitem = xbmcgui.ListItem(path=fullData)
- return xbmcplugin.setResolvedUrl(thisPlugin, True, listitem)
- # ------ helper ------
- def returnBiggerPic(picUrl):
- #matchPic = re.compile("(.*?format/)(.*?)(/format.*?)",re.DOTALL).findall(m[0])
- #if !matchPic:
- matchPic = re.compile(regexBiggerPic,re.DOTALL).findall(picUrl)
- Res = matchPic[0][1].split("x")
- resx = int(Res[0])*3
- resy = int(Res[1])*3
- newUrl = matchPic[0][0]+str(resx)+"x"+str(resy)+matchPic[0][2]+matchPic[0][3]
- return newUrl
- def remHTML(text):
- result = re.compile(regexTextOnly,re.DOTALL).sub('',text)
- return result
- def postUrl(url, values):
- req = urllib2.Request(url)
- response = urllib2.urlopen(req, values)
- link=response.read()
- response.close()
- return link
- def getUrl(url):
- req = urllib2.Request(url)
- req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
- response = urllib2.urlopen(req)
- link=response.read()
- response.close()
- return link
- def addDirectoryItem(name, parameters={},pic=""):
- li = xbmcgui.ListItem(name,iconImage="DefaultFolder.png", thumbnailImage=pic)
- url = sys.argv[0] + '?' + urllib.urlencode(parameters)
- return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=li, isFolder=True)
- def addPlayableItem(name, parameters={}, pic="", desc=""):
- li = xbmcgui.ListItem(name,iconImage="DefaultFolder.png", thumbnailImage=pic)
- li.setInfo( type="Video", infoLabels={ "Title": name, "Plot" : desc, "PlotOutline":desc, "Label":desc } )
- li.setProperty('IsPlayable', 'true')
- url = sys.argv[0] + '?' + urllib.urlencode(parameters)
- return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=li, isFolder=False)
- def parameters_string_to_dict(parameters):
- ''' Convert parameters encoded in a URL to a dict. '''
- paramDict = {}
- if parameters:
- paramPairs = parameters[1:].split("&")
- for paramsPair in paramPairs:
- paramSplits = paramsPair.split('=')
- if (len(paramSplits)) == 2:
- paramDict[paramSplits[0]] = paramSplits[1]
- return paramDict
- def substitute_entity(match):
- ent = match.group(3)
- if match.group(1) == "#":
- if match.group(2) == '':
- return unichr(int(ent))
- elif match.group(2) == 'x':
- return unichr(int('0x'+ent, 16))
- else:
- cp = n2cp.get(ent)
- if cp:
- return unichr(cp)
- else:
- return match.group()
- def decode_htmlentities(string):
- entity_re = re.compile(r'&(#?)(x?)(\w+);')
- return entity_re.subn(substitute_entity, string)[0]
- # ----- main -----
- params = parameters_string_to_dict(sys.argv[2])
- urlContent = str(params.get("urlC", ""))
- urlNews = str(params.get("urlN", ""))
- urlSeries = str(params.get("urlS", ""))
- urlVideo = str(params.get("urlV", ""))
- vidName = str(params.get("vidN", ""))
- if not sys.argv[2]:
- # new start
- ok = showGenre()
- else:
- if urlContent:
- newUrl = urlHost + urllib.unquote(urlContent)
- print "[phr] showContent: "+newUrl
- ok = showContent(newUrl)
- if urlNews:
- newUrl = urlHost + urllib.unquote(urlNews)
- print "[phr] showNews: "+newUrl
- ok = showNews(newUrl)
- if urlSeries:
- newUrl = urlHost + urllib.unquote(urlSeries)
- print "[phr] showSeries: "+newUrl
- ok = showSeries(newUrl)
- if urlVideo:
- newUrl = urlHost + decode_htmlentities(urllib.unquote(urlVideo))
- print "[phr] showVideo: "+newUrl
- ok = showVideo(newUrl, decode_htmlentities(urllib.unquote_plus(vidName)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement