def show_ondemand_programme(url): pageId = url[-46:-5] liStyle = xbmcgui.ListItem("Più recenti") addDirectoryItem( { "mode": "get_last_content_by_tag", "tags": "PageOB:" + pageId }, liStyle) liStyle = xbmcgui.ListItem("Più visti") addDirectoryItem({ "mode": "get_most_visited", "tags": "PageOB:" + pageId }, liStyle) ondemand = OnDemand() psets = ondemand.getProgrammeSets(url) for pset in psets: liStyle = xbmcgui.ListItem(pset["name"]) addDirectoryItem( { "mode": "ondemand", "uniquename": pset["uniquename"], "mediatype": pset["mediatype"] }, liStyle) xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def play(title, url, thumbailUrl="", uniquename="", mediatype="RaiTv Media Video Item"): # Retrieve the file URL if missing if uniquename != "": ondemand = OnDemand() (url, mediatype) = ondemand.getMediaUrl(uniquename) # Handle RAI relinker if url[:53] == "http://mediapolis.rai.it/relinker/relinkerServlet.htm" or \ url[:56] == "http://mediapolisvod.rai.it/relinker/relinkerServlet.htm": relinker = Relinker() url = relinker.getURL(url) # Add the server to the URL if missing if url !="" and url.find("://") == -1: url = ondemand.baseUrl + url print "Playing URL: %s" % url # It seems that all .ram files I found are not working # because upstream file is no longer present if url[-4:].lower() == ".ram": dialog = xbmcgui.Dialog() dialog.ok("Errore", "I file RealAudio (.ram) non sono supportati.") return # Play the item item=xbmcgui.ListItem(title, thumbnailImage=thumbailUrl) if mediatype == "RaiTv Media Video Item": item.setInfo(type="Video", infoLabels={"Title": title}) elif mediatype == "RaiTv Media Audio Item": item.setInfo(type="Audio", infoLabels={"Title": title}) xbmc.Player().play(url, item)
def play(title, url, thumbailUrl="", uniquename="", mediatype="RaiTv Media Video Item"): # Retrieve the file URL if missing if uniquename != "": ondemand = OnDemand() (url, mediatype) = ondemand.getMediaUrl(uniquename) # Handle RAI relinker if url[:53] == "http://mediapolis.rai.it/relinker/relinkerServlet.htm" or \ url[:56] == "http://mediapolisvod.rai.it/relinker/relinkerServlet.htm": relinker = Relinker() url = relinker.getURL(url) # Add the server to the URL if missing if url != "" and url.find("://") == -1: url = ondemand.baseUrl + url print "Playing URL: %s" % url # It seems that all .ram files I found are not working # because upstream file is no longer present if url[-4:].lower() == ".ram": dialog = xbmcgui.Dialog() dialog.ok("Errore", "I file RealAudio (.ram) non sono supportati.") return # Play the item item = xbmcgui.ListItem(title, thumbnailImage=thumbailUrl) if mediatype == "RaiTv Media Video Item": item.setInfo(type="Video", infoLabels={"Title": title}) elif mediatype == "RaiTv Media Audio Item": item.setInfo(type="Audio", infoLabels={"Title": title}) xbmc.Player().play(url, item)
def show_ondemand_new(): ondemand = OnDemand() programmes = ondemand.searchNewProgrammes() for programme in programmes: liStyle = xbmcgui.ListItem(programme["title"]) addDirectoryItem({"mode": "ondemand", "url": programme["linkDemand"]}, liStyle) xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def search_ondemand_programmes(): kb = xbmc.Keyboard() kb.setHeading("Cerca un programma") kb.doModal() if kb.isConfirmed(): name = kb.getText().decode('utf8') ondemand = OnDemand() programmes = ondemand.searchByName(name) show_ondemand_programmes(programmes)
def show_ondemand_new(): ondemand = OnDemand() programmes = ondemand.searchNewProgrammes() for programme in programmes: liStyle = xbmcgui.ListItem(programme["title"]) addDirectoryItem({ "mode": "ondemand", "url": programme["linkDemand"] }, liStyle) xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def show_must_watch_list(): ondemand = OnDemand() programmes = ondemand.getMustWatchList() for programme in programmes: if programme["type"] != "RaiTv Media Foto Item": thumb = ondemand.fixThumbnailUrl(programme["image"]) liStyle = xbmcgui.ListItem(programme["name"], thumbnailImage=thumb) liStyle.setProperty('IsPlayable', 'true') addLinkItem({"mode": "play", "url": programme["m3u8"]}, liStyle) xbmcplugin.addSortMethod(handle, xbmcplugin.SORT_METHOD_NONE) xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def show_ondemand_programme(url): pageId = url[-46:-5] liStyle = xbmcgui.ListItem("Più recenti") addDirectoryItem({"mode": "get_last_content_by_tag", "tags": "PageOB:"+pageId}, liStyle) liStyle = xbmcgui.ListItem("Più visti") addDirectoryItem({"mode": "get_most_visited", "tags": "PageOB:"+pageId}, liStyle) ondemand = OnDemand() psets = ondemand.getProgrammeSets(url) for pset in psets: liStyle = xbmcgui.ListItem(pset["name"]) addDirectoryItem({"mode": "ondemand", "uniquename": pset["uniquename"], "mediatype": pset["mediatype"] }, liStyle) xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def show_ondemand_themes(): ondemand = OnDemand() for position, tematica in enumerate(ondemand.tematiche): liStyle = xbmcgui.ListItem(tematica) addDirectoryItem( { "mode": "ondemand_search_by_theme", "index": position }, liStyle) xbmcplugin.addSortMethod(handle, xbmcplugin.SORT_METHOD_LABEL) xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def show_ondemand_channels(): ondemand = OnDemand() for k, v in ondemand.editori.iteritems(): liStyle = xbmcgui.ListItem(k) addDirectoryItem( { "mode": "ondemand_search_by_channel", "channel_id": v }, liStyle) xbmcplugin.addSortMethod(handle, xbmcplugin.SORT_METHOD_LABEL) xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def play(url, uniquename="", pathId=""): # Retrieve the file URL if missing if uniquename != "": xbmc.log("Uniquename: " + uniquename) ondemand = OnDemand() (url, mediatype) = ondemand.getMediaUrl(uniquename) if pathId != "": xbmc.log("PathID: " + pathId) ondemand = OnDemand() url = ondemand.getVideoUrl(pathId) # Handle RAI relinker if url[:53] == "http://mediapolis.rai.it/relinker/relinkerServlet.htm" or \ url[:56] == "http://mediapolisvod.rai.it/relinker/relinkerServlet.htm" or \ url[:58] == "http://mediapolisevent.rai.it/relinker/relinkerServlet.htm": xbmc.log("Relinker URL: " + url) relinker = Relinker() url = relinker.getURL(url) # Add the server to the URL if missing if url != "" and url.find("://") == -1: url = ondemand.baseUrl + url xbmc.log("Media URL: " + url) # It seems that all .ram files I found are not working # because upstream file is no longer present if url[-4:].lower() == ".ram": dialog = xbmcgui.Dialog() dialog.ok("Errore", "I file RealAudio (.ram) non sono supportati.") return # Play the item item = xbmcgui.ListItem(path=url) xbmcplugin.setResolvedUrl(handle=handle, succeeded=True, listitem=item)
def show_search_result(items): ondemand = OnDemand() for item in items: # We don't handle photos if "type" in item and item["type"] == "Foto": continue # Get best thumbnail available if "thumb" in item and item["thumb"] != "": thumb = item["thumb"] elif "image" in item and item["image"] != "": thumb = item["image"] else: thumb = ondemand.nothumb # Add the server to the URL if missing if thumb[:7] != "http://": thumb = ondemand.baseUrl + thumb #thumb = ondemand.fixThumbnailUrl(item["image"]) item["date"] = item["date"].replace("/", ".") liStyle = xbmcgui.ListItem(item["name"], thumbnailImage=thumb) # liStyle.setInfo(type="Video", # infoLabels={"title": item["name"], # "date": item["date"], # "plot": item["desc"], # "tvshowtitle": item["from"]}) liStyle.setProperty('IsPlayable', 'true') # Check if Video URL is present if item["h264"] != "": addLinkItem({"mode": "play", "url": item["h264"]}, liStyle) elif item["itemId"] != "": addLinkItem({ "mode": "play", "uniquename": item["itemId"] }, liStyle) else: # extract uniquename from weblink uniquename = item["weblink"][item["weblink"].rfind("/") + 1:] uniquename = uniquename.replace(".html", "") addLinkItem({"mode": "play", "uniquename": uniquename}, liStyle) #xbmc.executebuiltin("Container.SetViewMode(502)") xbmcplugin.addSortMethod(handle, xbmcplugin.SORT_METHOD_NONE) xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def show_replay_epg(channelId, date): replay = Replay() programmes = replay.getProgrammes(channelId, date) for programme in programmes: if not programme: continue startTime = programme["timePublished"] title = programme["name"] if programme["images"]["landscape"] != "": thumb = programme["images"]["landscape"].replace( "[RESOLUTION]", "256x-") elif programme["isPartOf"] and programme["isPartOf"]["images"][ "landscape"] != "": thumb = programme["isPartOf"]["images"]["landscape"].replace( "[RESOLUTION]", "256x-") else: ondemand = OnDemand() thumb = ondemand.nothumb plot = programme["description"] 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(type="Video", infoLabels={"Title" : title, # "Label": title, # "Plot": plot}) liStyle.setProperty('IsPlayable', 'true') addLinkItem({"mode": "nop"}, liStyle) else: liStyle = xbmcgui.ListItem(startTime + " " + title, thumbnailImage=thumb) # liStyle.setInfo(type="Video", infoLabels={"Title" : title, # "Label": title, # "Plot": plot}) liStyle.setProperty('IsPlayable', 'true') addLinkItem({"mode": "play", "path_id": videoUrl}, liStyle) xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def show_ondemand_channel(channel): ondemand = OnDemand() programmes = ondemand.searchByChannel(channel) show_ondemand_programmes(programmes)
def show_ondemand_theme(index): ondemand = OnDemand() programmes = ondemand.searchByTheme(ondemand.tematiche[int(index)]) show_ondemand_programmes(programmes)
def show_ondemand_items(uniquename, mediatype): ondemand = OnDemand() items = ondemand.getItems(uniquename, mediatype) for item in items: # Change date format item["date"] = item["date"].replace("/",".") item["date"] = item["date"].replace("-",".") # Get best thumbnail available if "image_medium" in item and item["image_medium"] != "": thumb = item["image_medium"] elif "image" in item and item["image"] != "": thumb = item["image"] else: thumb = ondemand.nothumb # Add the server to the URL if missing if thumb[:7] != "http://": thumb = ondemand.baseUrl + thumb if mediatype == "V": # Get best video available if "h264" in item and item["h264"] != "": url = item["h264"] elif "wmv" in item and item["wmv"] != "": url = item["wmv"] else: url = item["mediaUri"] labels = {"title": item["name"], "plot": item["desc"], "date": item["date"]} # Get length, if present if item["length"] != "": labels["duration"] = int(item["length"][:2]) * 60 + int(item["length"][3:5]) liStyle = xbmcgui.ListItem(item["name"], thumbnailImage=thumb) liStyle.setInfo(type="Video", infoLabels=labels) if url != "": addLinkItem({"mode": "play", "title": item["name"].encode('utf8'), "url": url, "thumbnail": thumb}, liStyle) else: addLinkItem({"mode": "play", "title": item["name"].encode('utf8'), "uniquename": item["itemId"], "thumbnail": thumb}, liStyle) elif mediatype == "A": liStyle = xbmcgui.ListItem(item["name"], thumbnailImage=thumb) liStyle.setInfo(type="Audio", infoLabels={"title": item["name"], "date": item["date"]}) addLinkItem({"mode": "play", "title": item["name"].encode('utf8'), "uniquename": item["itemId"], "thumbnail": thumb, "mediatype": "RaiTv Media Audio Item"}, liStyle) elif mediatype == "P": (url, mediatype) = ondemand.getMediaUrl(item["itemId"]) podcast = Podcast() poditems = podcast.getItems(url) for poditem in poditems: if poditem["thumbnail"] == "": poditem["thumbnail"] = thumb labels = {"title": item["name"], "plot": item["desc"], "date": item["date"]} # Get length, if present if poditem["length"] != "": labels["duration"] = int(poditem["length"][:2]) * 60 + int(poditem["length"][3:5]) liStyle = xbmcgui.ListItem(poditem["title"], thumbnailImage=poditem["thumbnail"]) liStyle.setInfo(type="Audio", infoLabels=labels) addLinkItem({"mode": "play", "title": poditem["title"].encode('utf8'), "url": poditem["url"], "thumbnail": poditem["thumbnail"], "mediatype": "RaiTv Media Audio Item"}, liStyle) #xbmcplugin.addSortMethod(handle, xbmcplugin.SORT_METHOD_DATE) xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def log_country(): ondemand = OnDemand() country = ondemand.getCountry() xbmc.log("RAI geolocation: %s" % country)
def show_ondemand_new(): ondemand = OnDemand() programmes = ondemand.searchNewProgrammes() show_ondemand_programmes(programmes)
def show_ondemand_index(index): ondemand = OnDemand() programmes = ondemand.searchByIndex(index) show_ondemand_programmes(programmes)
def show_ondemand_items(uniquename, mediatype): ondemand = OnDemand() items = ondemand.getItems(uniquename, mediatype) for item in items: # Change date format item["date"] = item["date"].replace("/", ".") item["date"] = item["date"].replace("-", ".") # Get best thumbnail available if "image_medium" in item and item["image_medium"] != "": thumb = item["image_medium"] elif "image" in item and item["image"] != "": thumb = item["image"] else: thumb = ondemand.nothumb # Add the server to the URL if missing if thumb[:7] != "http://": thumb = ondemand.baseUrl + thumb if mediatype == "V": # Get best video available if "h264" in item and item["h264"] != "": url = item["h264"] elif "wmv" in item and item["wmv"] != "": url = item["wmv"] else: url = item["mediaUri"] labels = { "title": item["name"], "plot": item["desc"], "date": item["date"] } # Get length, if present if item["length"] != "": labels["duration"] = int(item["length"][:2]) * 60 + int( item["length"][3:5]) liStyle = xbmcgui.ListItem(item["name"], thumbnailImage=thumb) liStyle.setInfo(type="Video", infoLabels=labels) if url != "": addLinkItem( { "mode": "play", "title": item["name"].encode('utf8'), "url": url, "thumbnail": thumb }, liStyle) else: addLinkItem( { "mode": "play", "title": item["name"].encode('utf8'), "uniquename": item["itemId"], "thumbnail": thumb }, liStyle) elif mediatype == "A": liStyle = xbmcgui.ListItem(item["name"], thumbnailImage=thumb) liStyle.setInfo(type="Audio", infoLabels={ "title": item["name"], "date": item["date"] }) addLinkItem( { "mode": "play", "title": item["name"].encode('utf8'), "uniquename": item["itemId"], "thumbnail": thumb, "mediatype": "RaiTv Media Audio Item" }, liStyle) elif mediatype == "P": (url, mediatype) = ondemand.getMediaUrl(item["itemId"]) podcast = Podcast() poditems = podcast.getItems(url) for poditem in poditems: if poditem["thumbnail"] == "": poditem["thumbnail"] = thumb labels = { "title": item["name"], "plot": item["desc"], "date": item["date"] } # Get length, if present if poditem["length"] != "": labels["duration"] = int(poditem["length"][:2]) * 60 + int( poditem["length"][3:5]) liStyle = xbmcgui.ListItem(poditem["title"], thumbnailImage=poditem["thumbnail"]) liStyle.setInfo(type="Audio", infoLabels=labels) addLinkItem( { "mode": "play", "title": poditem["title"].encode('utf8'), "url": poditem["url"], "thumbnail": poditem["thumbnail"], "mediatype": "RaiTv Media Audio Item" }, liStyle) #xbmcplugin.addSortMethod(handle, xbmcplugin.SORT_METHOD_DATE) xbmcplugin.endOfDirectory(handle=handle, succeeded=True)