def get_sources(item): """ get video_link and try to play it Keyword Arguments: item -- JenItem to try playing """ result = run_hook("get_sources", item) if result: return if item.startswith("<plugin>"): # link to plugin link = JenItem(item)["link"] sublinks = JenItem(link).getAll("sublink") if sublinks: if len(sublinks) > 1: link = choose_quality(link) else: link = sublinks[0] link = link.replace("&", "&") xbmc.executebuiltin("Container.update(" + link + ")") return item = JenItem(item) link = item["link"] if not link or link.replace("\t", "") == "": return meta = JenItem(item["meta"]) title = meta["title"] year = meta.get("year", "").split("-")[0].strip() imdb = meta.get("imdb", "") tvdb = meta.get("tvdb", "") season = meta.get("season", "") episode = meta.get("episode", "") tvshowtitle = meta.get("tvshowtitle", None) premiered = meta.get("premiered", "") try: premiered = premiered.split("-")[0].strip() except: if len(premiered) == 4: pass elif not premiered: pass else: koding.dolog("wrong premiered format") busy_dialog = xbmcgui.DialogProgress() dialog = xbmcgui.Dialog() icon = ADDON.getAddonInfo("icon") jenplayer = JenPlayer(resume=False) try: spec = {"identifier": imdb, "season": season or "0", "episode": episode or "0"} match = koding.Get_From_Table("watched", spec) if match: match = match[0] if match["currentTime"] and not match["currentTime"] == "0": if dialog.yesno( ADDON.getAddonInfo("name"), _("Previous playback detected"), yeslabel=_("Resume"), nolabel=_("Restart"), ): jenplayer = JenPlayer(resume=True) except: pass jenplayer.setItem(item) busy_dialog.create(xbmcaddon.Addon().getAddonInfo("name"), _("Processing Link")) preset = choose_quality(link) message = get_searching_message(preset) played = False infolabels = {} if preset: preset = preset.replace("&", "&") busy_dialog.update(0, message) listitem = None fetch_meta = ADDON.getSetting("metadata") == "true" listitem = xbmcgui.ListItem( path=link, iconImage=item.get("thumbnail", icon), thumbnailImage=item.get("thumbnail", icon), ) infolabels = {} if fetch_meta and imdb != "0": # only try valid items with imdb try: info, created = get_info([item.item_string]) if info and type(info) == dict: infolabels = info except: pass else: infolabels["title"] = title infolabels["name"] = title if "plotoutline" not in infolabels: infolabels["plotoutline"] = infolabels.get("plot", "") if item.get("content", "") == "song": listitem.setInfo( type="Music", infoLabels={ "title": meta.get("title", ""), "artist": meta.get("artist", ""), }, ) else: listitem.setInfo(type="video", infoLabels=infolabels) listitem.setLabel(item.get("title", item.get("name", ""))) if "search" in preset: exclude_scrapers_content = item.get("exclude_scrapers", "") if exclude_scrapers_content: exclude_scrapers = exclude_scrapers_content.split(";") else: exclude_scrapers = None # nanscraper link if item.get("content", "") == "song": artist = item.get("artist", "") played = Sources.get_music_sources( title, artist, preset=preset, dialog=busy_dialog, exclude=exclude_scrapers, listitem=listitem, player=jenplayer, ) else: played = Sources.get_sources( title, year, imdb, tvdb, season, episode, tvshowtitle, premiered, preset=preset, dialog=busy_dialog, listitem=listitem, exclude=exclude_scrapers, player=jenplayer, ) elif preset.startswith("http") or preset.startswith("plugin") or preset.endswith('.torrent') or preset.startswith('magnet'): # direct link if "/playlist" in preset and "youtube" in preset: busy_dialog.close() xbmc.executebuiltin("Container.update(" + preset + ")") return elif "plugin://plugin.video.youtube/play/?video_id=" in preset: xbmc.executebuiltin("PlayMedia(%s)" % preset) played = True elif item["content"] == "image": busy_dialog.close() xbmc.executebuiltin("ShowPicture(%s)" % preset) played = True else: played = koding.Play_Video( preset, showbusy=False, ignore_dp=True, item=listitem, player=jenplayer, resolver=resolveurl, ) else: # who knows busy_dialog.close() koding.dolog("unknown link type: " + repr(preset)) raise Exception() busy_dialog.close() if played: jenplayer.keep_alive()
def get_sources(item): """ get video_link and try to play it Keyword Arguments: item -- JenItem to try playing """ result = run_hook("get_sources", item) if result: return if item.startswith("<plugin>"): # link to plugin link = JenItem(item)["link"] sublinks = JenItem(link).getAll("sublink") if sublinks: if len(sublinks) > 1: link = choose_quality(link) else: link = sublinks[0] link = link.replace("&", "&") xbmc.executebuiltin('Container.update(' + link + ')') return item = JenItem(item) link = item["link"] if not link or link.replace("\t", "") == "": return meta = JenItem(item["meta"]) title = meta["title"] year = meta.get("year", '').split("-")[0].strip() imdb = meta.get("imdb", "") tvdb = meta.get("tvdb", "") season = meta.get("season", "") episode = meta.get("episode", "") tvshowtitle = meta.get("tvshowtitle", None) premiered = meta.get("premiered", "") try: premiered = premiered.split("-")[0].strip() except: if len(premiered) == 4: pass elif not premiered: pass else: koding.dolog("wrong premiered format") busy_dialog = xbmcgui.DialogProgress() dialog = xbmcgui.Dialog() icon = ADDON.getAddonInfo('icon') jenplayer = JenPlayer(resume=False) try: spec = { "identifier": imdb, "season": season or "0", "episode": episode or "0" } match = koding.Get_From_Table("watched", spec) if match: match = match[0] if match["currentTime"] and not match["currentTime"] == "0": if dialog.yesno(ADDON.getAddonInfo("name"), _("Previous playback detected"), yeslabel=_("Resume"), nolabel=_("Restart")): jenplayer = JenPlayer(resume=True) except: pass jenplayer.setItem(item) busy_dialog.create(xbmcaddon.Addon().getAddonInfo('name'), _("Processing Link")) preset = choose_quality(link) message = get_searching_message(preset) played = False infolabels = {} if preset: preset = preset.replace("&", "&") busy_dialog.update(0, message) listitem = None fetch_meta = ADDON.getSetting("metadata") == "true" listitem = xbmcgui.ListItem( path=link, iconImage=item.get("thumbnail", icon), thumbnailImage=item.get("thumbnail", icon)) infolabels = {} if fetch_meta and imdb != "0": # only try valid items with imdb try: info, created = get_info([item.item_string]) if info and type(info) == dict: infolabels = info except: pass else: infolabels["title"] = title infolabels["name"] = title if "plotoutline" not in infolabels: infolabels["plotoutline"] = infolabels.get("plot", "") if item.get("content", "") == "song": listitem.setInfo(type='Music', infoLabels={'title': meta.get("title", ""), 'artist': meta.get("artist", "")}) else: listitem.setInfo(type="video", infoLabels=infolabels) listitem.setLabel(item.get("title", item.get("name", ""))) if "search" in preset: exclude_scrapers_content = item.get("exclude_scrapers", "") if exclude_scrapers_content: exclude_scrapers = exclude_scrapers_content.split(";") else: exclude_scrapers = None # nanscraper link if item.get("content", "") == "song": artist = item.get("artist", "") played = Sources.get_music_sources(title, artist, preset=preset, dialog=busy_dialog, exclude=exclude_scrapers, listitem=listitem, player=jenplayer) else: played = Sources.get_sources( title, year, imdb, tvdb, season, episode, tvshowtitle, premiered, preset=preset, dialog=busy_dialog, listitem=listitem, exclude=exclude_scrapers, player=jenplayer) elif preset.startswith("http") or preset.startswith("plugin"): # direct link if "/playlist" in preset and "youtube" in preset: busy_dialog.close() xbmc.executebuiltin('Container.update(' + preset + ')') return elif "plugin://plugin.video.youtube/play/?video_id=" in preset: xbmc.executebuiltin("PlayMedia(%s)" % preset) played = True elif item["content"] == "image": busy_dialog.close() xbmc.executebuiltin("ShowPicture(%s)" % preset) played = True else: played = koding.Play_Video( preset, showbusy=False, ignore_dp=True, item=listitem, player=jenplayer, resolver=resolveurl) else: # who knows busy_dialog.close() koding.dolog("unknown link type: " + repr(preset)) raise Exception() busy_dialog.close() if played: jenplayer.keep_alive()