Skip to content
Open
4 changes: 4 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Rai Play
-- desc --

Storage Server used is a fork of Common Plugin Cache, edited to make it works with Python 3
8 changes: 4 additions & 4 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.raitv"
name="Rai On Demand"
version="2.0.0"
provider-name="Nightflyer">
name="Rai Play"
version="3.0.2"
provider-name="Nightflyer, cttynul, maxbambi">
<requires>
<import addon="xbmc.python" version="2.1.0"/>
<import addon="script.common.plugin.cache" version="0.9.1"/>
<!--<import addon="script.common.plugin.cache" version="0.9.1"/>-->
</requires>
<extension point="xbmc.python.pluginsource"
library="default.py">
Expand Down
161 changes: 112 additions & 49 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@
import xbmcplugin
import xbmcaddon
import urllib
import urlparse
try:
import urllib.parse as urlparse
except ImportError:
import urlparse
try:
from urllib.parse import urlencode
except:
from urllib import urlencode
import datetime
import StorageServer
from resources.lib import StorageServer
from resources.lib.tgr import TGR
from resources.lib.search import Search
from resources.lib.raiplay import RaiPlay
from resources.lib.raiplayradio import RaiPlayRadio
from resources.lib.relinker import Relinker
import resources.lib.utils as utils
import re

# plugin constants
__plugin__ = "plugin.video.raitv"
Expand All @@ -37,13 +45,13 @@ def parameters_string_to_dict(parameters):
return paramDict

def addDirectoryItem(parameters, li):
url = sys.argv[0] + '?' + urllib.urlencode(parameters)
url = sys.argv[0] + '?' + urlencode(parameters)
return xbmcplugin.addDirectoryItem(handle=handle, url=url,
listitem=li, isFolder=True)

def addLinkItem(parameters, li, url=""):
if url == "":
url = sys.argv[0] + '?' + urllib.urlencode(parameters)
url = sys.argv[0] + '?' + urlencode(parameters)
li.setProperty('IsPlayable', 'true')
return xbmcplugin.addDirectoryItem(handle=handle, url=url,
listitem=li, isFolder=False)
Expand Down Expand Up @@ -71,10 +79,16 @@ def show_root_menu():

def show_tg_root():
search = Search()
for k, v in search.newsArchives.iteritems():
liStyle = xbmcgui.ListItem(k)
addDirectoryItem({"mode": "get_last_content_by_tag",
"tags": search.newsArchives[k]}, liStyle)
try:
for k, v in search.newsArchives.iteritems():
liStyle = xbmcgui.ListItem(k)
addDirectoryItem({"mode": "get_last_content_by_tag",
"tags": search.newsArchives[k]}, liStyle)
except:
for k, v in search.newsArchives.items():
liStyle = xbmcgui.ListItem(k)
addDirectoryItem({"mode": "get_last_content_by_tag",
"tags": search.newsArchives[k]}, liStyle)
liStyle = xbmcgui.ListItem("TGR",
thumbnailImage="http://www.tgr.rai.it/dl/tgr/mhp/immagini/splash.png")
addDirectoryItem({"mode": "tgr"}, liStyle)
Expand Down Expand Up @@ -127,7 +141,7 @@ def play(url, pathId="", srt=[]):
else:
raiplay = RaiPlay()
metadata = raiplay.getVideoMetadata(pathId)
url = metadata["contentUrl"]
url = metadata["content_url"]
srtUrl = metadata["subtitles"]

if srtUrl != "":
Expand All @@ -148,7 +162,8 @@ def play(url, pathId="", srt=[]):
xbmc.log("Media URL: " + url)

# Play the item
item=xbmcgui.ListItem(path=url + '|User-Agent=' + urllib.quote_plus(Relinker.UserAgent))
try: item=xbmcgui.ListItem(path=url + '|User-Agent=' + urllib.quote_plus(Relinker.UserAgent))
except: item=xbmcgui.ListItem(path=url + '|User-Agent=' + urllib.parse.quote_plus(Relinker.UserAgent))
if len(srt) > 0:
item.setSubtitles(srt)
xbmcplugin.setResolvedUrl(handle=handle, succeeded=True, listitem=item)
Expand Down Expand Up @@ -208,38 +223,79 @@ def show_replay_tv_epg(date, channelId):
xbmc.log("Showing EPG for " + channelId + " on " + date)
raiplay = RaiPlay()
programmes = raiplay.getProgrammes(channelId, date)

for programme in programmes:
if not programme:
continue

startTime = programme["timePublished"]
title = programme["name"]

if programme["images"]["landscape"] != "":
thumb = raiplay.getThumbnailUrl(programme["images"]["landscape"])
elif programme["isPartOf"] and programme["isPartOf"]["images"]["landscape"] != "":
thumb = raiplay.getThumbnailUrl(programme["isPartOf"]["images"]["landscape"])
else:
thumb = raiplay.noThumbUrl

if programme["hasVideo"]:
videoUrl = programme["pathID"]
else:
videoUrl = None

if videoUrl is None:
# programme is not available
liStyle = xbmcgui.ListItem(startTime + " [I]" + title + "[/I]",
thumbnailImage=thumb)
liStyle.setInfo("video", {})
addLinkItem({"mode": "nop"}, liStyle)
else:
liStyle = xbmcgui.ListItem(startTime + " " + title,
thumbnailImage=thumb)
liStyle.setInfo("video", {})
addLinkItem({"mode": "play",
"path_id": videoUrl}, liStyle)
if(programmes):
for programme in programmes:
if not programme:
continue

startTime = programme["timePublished"]
title = programme["name"]

if programme["images"]["landscape"] != "":
thumb = raiplay.getThumbnailUrl(programme["images"]["landscape"])
elif programme["isPartOf"] and programme["isPartOf"]["images"]["landscape"] != "":
thumb = raiplay.getThumbnailUrl(programme["isPartOf"]["images"]["landscape"])
else:
thumb = raiplay.noThumbUrl

if programme["hasVideo"]:
videoUrl = programme["pathID"]
else:
videoUrl = None

if videoUrl is None:
# programme is not available
liStyle = xbmcgui.ListItem(startTime + " [I]" + title + "[/I]",
thumbnailImage=thumb)
liStyle.setInfo("video", {})
addLinkItem({"mode": "nop"}, liStyle)
else:
liStyle = xbmcgui.ListItem(startTime + " " + title,
thumbnailImage=thumb)
liStyle.setInfo("video", {})
addLinkItem({"mode": "play",
"path_id": videoUrl}, liStyle)
else:
response = raiplay.getProgrammesHtml(channelId, date)
programmes = re.findall('(<li.*?</li>)', response)
for i in programmes:
icon = re.findall('''data-img=['"]([^'^"]+?)['"]''', i)
if icon:
icon = raiplay.getUrl(icon[0])
else:
icon =''

title = re.findall("<p class=\"info\">([^<]+?)</p>", i)
if title:
title = title[0]
else:
title = ''

startTime = re.findall("<p class=\"time\">([^<]+?)</p>", i)
if startTime:
title = startTime[0] + " " + title

desc = re.findall("<p class=\"descProgram\">([^<]+?)</p>", i, re.S)
if desc:
desc= desc[0]
else:
desc=""

videoUrl = re.findall('''data-href=['"]([^'^"]+?)['"]''', i)

if not videoUrl:
# programme is not available
liStyle = xbmcgui.ListItem(" [I]" + title + "[/I]", thumbnailImage = icon)
liStyle.setInfo("video", {})
addLinkItem({"mode": "nop"}, liStyle)
else:
videoUrl = videoUrl[0]
if not videoUrl.endswith('json'):
videoUrl = videoUrl + "?json"

liStyle = xbmcgui.ListItem(title, thumbnailImage = icon )
liStyle.setInfo("video", {})
addLinkItem({"mode": "play", "path_id": videoUrl}, liStyle)
xbmcplugin.endOfDirectory(handle=handle, succeeded=True)

def show_replay_radio_epg(date, channelId):
Expand Down Expand Up @@ -284,7 +340,7 @@ def show_ondemand_root():
raiplay = RaiPlay()
items = raiplay.getMainMenu()
for item in items:
if item["sub-type"] in ("RaiPlay Tipologia Page", "RaiPlay Genere Page"):
if item["sub-type"] in ("RaiPlay Tipologia Page", "RaiPlay Genere Page", "RaiPlay Tipologia Editoriale Page" ):
liStyle = xbmcgui.ListItem(item["name"])
addDirectoryItem({"mode": "ondemand", "path_id": item["PathID"], "sub_type": item["sub-type"]}, liStyle)
liStyle = xbmcgui.ListItem("Cerca")
Expand Down Expand Up @@ -368,7 +424,8 @@ def search_ondemand_programmes():
kb.setHeading("Cerca un programma")
kb.doModal()
if kb.isConfirmed():
name = kb.getText().decode('utf8')
try: name = kb.getText().decode('utf8').lower()
except: name = kb.getText().lower()
xbmc.log("Searching for programme: " + name)
raiplay = RaiPlay()
dir = raiplay.getProgrammeList(raiplay.AzTvShowPath)
Expand All @@ -382,10 +439,16 @@ def search_ondemand_programmes():

def show_news_providers():
search = Search()
for k, v in search.newsProviders.iteritems():
liStyle = xbmcgui.ListItem(k)
addDirectoryItem({"mode": "get_last_content_by_tag",
"tags": search.newsProviders[k]}, liStyle)
try:
for k, v in search.newsProviders.iteritems():
liStyle = xbmcgui.ListItem(k)
addDirectoryItem({"mode": "get_last_content_by_tag",
"tags": search.newsProviders[k]}, liStyle)
except:
for k, v in search.newsProviders.items():
liStyle = xbmcgui.ListItem(k)
addDirectoryItem({"mode": "get_last_content_by_tag",
"tags": search.newsProviders[k]}, liStyle)
xbmcplugin.addSortMethod(handle, xbmcplugin.SORT_METHOD_LABEL)
xbmcplugin.endOfDirectory(handle=handle, succeeded=True)

Expand Down Expand Up @@ -469,7 +532,7 @@ def log_country():
elif mode == "ondemand":
if subType == "":
show_ondemand_root()
elif subType in ("RaiPlay Tipologia Page", "RaiPlay Genere Page"):
elif subType in ("RaiPlay Tipologia Page", "RaiPlay Genere Page", "RaiPlay Tipologia Editoriale Page"):
show_ondemand_programmes(pathId)
elif subType == "Raiplay Tipologia Item":
show_ondemand_list(pathId)
Expand Down
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading