Esempio n. 1
0
def get_video_link(players, params, mode, use_simple=False):
    lister = Lister()
    # Extend parameters
    for lang, lang_params in params.items():
        for key, value in lang_params.items():
            if isinstance(value, basestring):
                params[lang][key + "_+"] = value.replace(" ", "+")
                params[lang][key + "_-"] = value.replace(" ", "-")
                params[lang][key + "_escaped"] = value.replace(" ", "%2520")
                params[lang][key + "_escaped+"] = value.replace(" ", "%252B")
    pDialog = None
    selection = None
    try:
        if len(players) > 1 and use_simple:
            index = dialogs.select(_("Play using..."), [player.title for player in players])
            if index == -1: return None
            players = [players[index]]
        resolve_f = lambda p : resolve_player(p, lister, params)
        if len(players) > 1:
            pool_size = plugin.get_setting(SETTING_POOL_SIZE, int)
            populator = lambda : execute(resolve_f, players, lister.stop_flag, pool_size)
            selection = dialogs.select_ext(_("Play using..."), populator, len(players))
        else:
            result = resolve_f(players[0])
            if result:
                title, links = result
                if len(links) == 1: selection = links[0]
                else:
                    index = dialogs.select(_("Play using..."), [x['label'] for x in links])
                    if index > -1: selection = links[index]
            else: dialogs.ok(_("Error"), _("%s not found") % _("Video"))
    finally: lister.stop()
    return selection
Esempio n. 2
0
def movies_play_by_name(name, lang="en"):
    """ Activate tv search """
    import_tmdb()
    from meta.utils.text import parse_year

    items = tmdb.Search().movie(query=name, language=lang, page=1)["results"]

    if not items:
        dialogs.ok(
            _("Movie not found"),
            "{0} {1}".format(_("No movie information found on TMDB for"),
                             name))
        return

    if len(items) > 1:
        selection = dialogs.select(_("Choose Movie"), [
            "{0} ({1})".format(to_utf8(s["title"]),
                               parse_year(s["release_date"])) for s in items
        ])
    else:
        selection = 0

    if selection != -1:
        id = items[selection]["id"]
        movies_play("tmdb", id, "default")
Esempio n. 3
0
def get_tvdb_id_from_name(name, lang):
    import_tvdb()

    search_results = tvdb.search(name, language=lang)

    if not search_results:
        dialogs.ok(
            _("Show not found"),
            "{0} {1} in tvdb".format(_("no show information found for"),
                                     to_utf8(name)))
        return

    items = []
    for show in search_results:
        if "firstaired" in show:
            show["year"] = int(show['firstaired'].split("-")[0].strip())
        else:
            show["year"] = 0
        items.append(show)

    if len(items) > 1:
        selection = dialogs.select(_("Choose Show"), [
            "{0} ({1})".format(to_utf8(s["seriesname"]), s["year"])
            for s in items
        ])
    else:
        selection = 0
    if selection != -1:
        return items[selection]["id"]
Esempio n. 4
0
def get_tvdb_id_from_imdb_id(imdb_id):
    import_tvdb()
    tvdb_id = tvdb.search_by_imdb(imdb_id)
    if not tvdb_id:
        dialogs.ok(_("Show not found"), "{0} {1} in tvdb".format(_("no show information found for"), imdb_id))
        return
    return tvdb_id
Esempio n. 5
0
def get_episode_parameters(show, season, episode):
    import_tmdb()
    
    if season in show and episode in show[season]:
        episode_obj = show[season][episode]
    else:
        dialogs.ok(_("Episode info not found"), "No tvdb information found for {0} - S{1}E{2}".format(
            show['seriesname'], season, episode))
        return
    
    # Get parameters
    parameters = {'id': show['id'], 'season': season, 'episode': episode}
    
    network = show.get('network', '')
    
    parameters['network'] = network
    if network:
        parameters['network_clean'] = re.sub("(\(.*?\))", "", network).strip()
    else:
        parameters['network_clean'] = network
        
    parameters['showname'] = show['seriesname']
    #parameters['clearname'], _ = xbmc.getCleanMovieTitle(parameters['showname'])
    parameters['clearname'] = re.sub("(\(.*?\))", "", show['seriesname']).strip()

    parameters['absolute_number'] = episode_obj.get('absolute_number')
    parameters['title'] = episode_obj.get('episodename', str(episode))
    parameters['firstaired'] = episode_obj.get('firstaired')
    parameters['year'] = show.get('year', 0)
    parameters['imdb'] = show.get('imdb_id', '')    

    try:
        genre = [x for x in show['genre'].split('|') if not x == '']
    except:
        genre = []
    parameters['genre'] = " / ".join(genre)

    is_anime = False
    if parameters['absolute_number'] and \
     parameters['absolute_number'] != '0' and \
     "animation" in parameters['genre'].lower():
        tmdb_results = tmdb.Find(show['id']).info(external_source="tvdb_id") or {}
        for tmdb_show in tmdb_results.get("tv_results", []):
            if "JP" in tmdb_show['origin_country']:
                is_anime = True
        
    if is_anime:
        parameters['name'] = u'{showname} {absolute_number}'.format(**parameters)
    else:
        parameters['name'] = u'{showname} S{season:02d}E{episode:02d}'.format(**parameters)

    return parameters
Esempio n. 6
0
def get_video_link(players, params, mode, use_simple=False):
    lister = Lister()

    # Extend parameters
    for lang, lang_params in params.items():
        for key, value in lang_params.items():
            if isinstance(value, basestring):
                params[lang][key + "_+"] = value.replace(" ", "+")
                params[lang][key + "_-"] = value.replace(" ", "-")
                params[lang][key + "_escaped"] = value.replace(" ", "%2520")
                params[lang][key + "_escaped+"] = value.replace(" ", "%252B")

    pDialog = None
    selection = None
    try:
        if len(players) > 1 and use_simple:
            index = dialogs.select(_("Choose Your Channel..."),
                                   [player.title for player in players])
            if index == -1:
                return None
            players = [players[index]]

        resolve_f = lambda p: resolve_player(p, lister, params)

        if len(players) > 1:
            pDialog = xbmcgui.DialogProgress()
            pDialog.create('Meta', 'Working...')
            dialogs.wait_for_dialog("progressdialog", 5)
            pool_size = plugin.get_setting(SETTING_POOL_SIZE, converter=int)
            populator = lambda: execute(resolve_f, players, lister.stop_flag,
                                        pool_size)
            selection = dialogs.select_ext(_("Choose Your Channel..."),
                                           populator, len(players))

        else:
            result = resolve_f(players[0])
            if result:
                title, links = result
                if len(links) == 1:
                    selection = links[0]
                else:
                    index = dialogs.select(_("Choose Your Channel..."),
                                           [x['label'] for x in links])
                    if index > -1:
                        selection = links[index]
            else:
                dialogs.ok(_("Error"), _("Video not found :("))
    finally:
        lister.stop()

    return selection
Esempio n. 7
0
def guide_movies_play_by_name(name, lang="en"):
    import_tmdb()
    from meta.utils.text import parse_year
    items = tmdb.Search().movie(query=name, language=lang, page=1)["results"]
    if not items:
        return dialogs.ok(
            _("%s not found") % _("Movie"),
            "{0} {1}".format(_("No movie information found on TMDB for"),
                             name))
    if len(items) > 1:
        selection = dialogs.select(
            "{0}".format(
                _("Choose thumbnail").replace(
                    _("Thumbnail").lower(),
                    _("Movie").lower())), [
                        "{0} ({1})".format(to_utf8(s["title"]),
                                           parse_year(s["release_date"]))
                        for s in items
                    ])
    else:
        selection = 0
    if selection != -1:
        id = items[selection]["id"]
        guide_movies_play("tmdb", id, "default")
        if plugin.get_setting(SETTING_MOVIES_PLAYED_BY_ADD, bool) == True:
            movies_add_to_library("tmdb", id)
Esempio n. 8
0
def movies_play_by_name(name, lang = "en"):
    """ Activate movie search """
    import_tmdb()
    from meta.utils.text import parse_year

    items = tmdb.Search().movie(query=name, language=lang, page=1)["results"]

    if items == []:
        dialogs.ok(_("Movie not found"), "{0} {1}".format(_("No movie information found on TMDB for"),name))
        return

    if len(items) > 1:
        selection = dialogs.select(_("Choose Movie"), ["{0} ({1})".format(
            to_utf8(s["title"]),
            parse_year(s["release_date"])) for s in items])
    else:
        selection = 0
    if selection != -1:
        id = items[selection]["id"]
        movies_play("tmdb", id, "default")
Esempio n. 9
0
def guide_movies_play_by_name(name, lang = "en"):
    import_tmdb()
    from meta.utils.text import parse_year
    items = tmdb.Search().movie(query=name, language=lang, page=1)["results"]
    if not items: return dialogs.ok(_("Movie not found"), "{0} {1}".format(_("No movie information found on TMDB for"), name))
    if len(items) > 1:
        selection = dialogs.select(_("Choose Movie"), ["{0} ({1})".format(
            to_utf8(s["title"]),
            parse_year(s["release_date"])) for s in items])
    else: selection = 0
    if selection != -1:
        id = items[selection]["id"]
        guide_movies_play("tmdb", id, "default")
        if plugin.get_setting(SETTING_MOVIES_PLAYED_BY_ADD, converter=bool) == True: movies_add_to_library("tmdb", id)
Esempio n. 10
0
def get_video_link(players, params, mode, use_simple=False):
    lister = Lister()
    
    pDialog = None
    selection = None
    try:
        if len(players) > 1 and use_simple:
            index = dialogs.select(_("Play with..."), [player.title for player in players])
            if index == -1:
                return None
            players = [players[index]]
            
        resolve_f = lambda p : resolve_player(p, lister, params)
        
        if len(players) > 1:
            pDialog = xbmcgui.DialogProgress()
            pDialog.create('Meta', 'Working...')
            dialogs.wait_for_dialog("progressdialog", 5)
            populator = lambda : execute(resolve_f, players, lister.stop_flag)
            selection = dialogs.select_ext(_("Play with..."), populator, len(players))
            
        else:
            result = resolve_f(players[0])
            if result:
                title, links = result
                if len(links) == 1:
                    selection = links[0]
                else:
                    index = dialogs.select(_("Play with..."), [x['label'] for x in links])
                    if index > -1:
                        selection = links[index]
            else:
                dialogs.ok(_("Error"), _("Video not found :("))
    finally:
        lister.stop()

    return selection
Esempio n. 11
0
def movies_play_by_name(name, lang = "en"):
    """ Activate tv search """
    import_tmdb()
    from meta.utils.text import parse_year
    items = tmdb.Search().movie(query=name, language=lang, page=1)["results"]
    if not items: return dialogs.ok(_("%s not found") % _("Movie"), "{0} {1}".format(_("No movie information found on TMDB for"), name))
    if len(items) > 1:
        selection = dialogs.select("{0}".format(_("Choose thumbnail").replace(_("Thumbnail").lower(),_("Movie").lower())), ["{0} ({1})".format(
            to_utf8(s["title"]),
            parse_year(s["release_date"])) for s in items])
    else: selection = 0
    if selection != -1:
        id = items[selection]["id"]
        movies_play("tmdb", id, "context")
        if plugin.get_setting(SETTING_MOVIES_PLAYED_BY_ADD, bool) == True: movies_add_to_library("tmdb", id)
Esempio n. 12
0
def get_tvdb_id_from_name(name, lang):
    import_tvdb()

    search_results = tvdb.search(name, language=lang)

    if search_results == []:
        dialogs.ok(_("Show not found"), "{0} {1} in tvdb".format(_("no show information found for"), to_utf8(name)))
        return

    items = []
    for show in search_results:
        if "firstaired" in show:
            show["year"] = int(show['firstaired'].split("-")[0].strip())
        else:
            show["year"] = 0
        items.append(show)

    if len(items) > 1:
        selection = dialogs.select(_("Choose Show"), ["{0} ({1})".format(
            to_utf8(s["seriesname"]), s["year"]) for s in items])
    else:
        selection = 0
    if selection != -1:
        return items[selection]["id"]
Esempio n. 13
0
def play_episode_from_guide(id, season, episode, mode):  
    import_tvdb()
    id = int(id)
    season = int(season)
    episode = int(episode)
    dbid = xbmc.getInfoLabel("ListItem.DBID")
    try:
        dbid = int(dbid)
    except:
        dbid = None
    show = tvdb[id]
    show_info = get_tvshow_metadata_tvdb(show, banners=False)
    if mode == 'select':
        play_plugin = ADDON_PICKER.id
    elif mode == 'default':
        play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_CHANNELER, unicode)
    else:
        play_plugin = mode
    channelers = active_channelers("tvshows", filters = {'network': show.get('network')})
    channelers = [p for p in channelers if p.id == play_plugin] or channelers
    if not channelers:
        xbmc.executebuiltin( "Action(Info)")
        action_cancel()
        return
    trakt_ids = get_trakt_ids("tvdb", id, show['seriesname'],
                    "show", show.get('year', 0))
    params = {}
    for lang in get_needed_langs(channelers):
        if lang == LANG:
            tvdb_data = show
        else:
            tvdb_data = create_tvdb(lang)[id]
        if tvdb_data['seriesname'] is None:
            continue
        episode_parameters = get_episode_parameters(tvdb_data, season, episode)
        if episode_parameters is not None:
            params[lang] = episode_parameters
        else:
            msg = "{0} {1} - S{1}E{2}".format(_("No tvdb information found for"), show['seriesname'], season, episode)
            dialogs.ok(_("%s not found") % _("Episode information"), msg)
            return
        if trakt_ids != None:
            params[lang].update(trakt_ids)
        params[lang]['info'] = show_info
        params[lang] = to_unicode(params[lang])
    link = on_play_video(mode, channelers, params, trakt_ids)
    if link:
        set_property("data", json.dumps({'dbid': dbid, 'tvdb': id, 
            'season': season, 'episode': episode}))
        season_info = get_season_metadata_tvdb(show_info, show[season], banners=False)
        episode_info = get_episode_metadata_tvdb(season_info, show[season][episode])
        action_play({
            'label': episode_info['title'],
            'path': link,
            'info': episode_info,
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': episode_info['poster'],
            'poster': episode_info['poster'],
            'properties' : {'fanart_image' : episode_info['fanart']},
        })
Esempio n. 14
0
def trakt_play_episode(id, season, episode, mode):
    from trakt import trakt
    id = int(id)
    season = int(season)
    episode = int(episode)
    show = None
    preason = None
    prepisode = None
    dbid = xbmc.getInfoLabel("ListItem.DBID")
    try: dbid = int(dbid)
    except: dbid = None
    show = trakt.get_show(id)
    if 'name' in show: show_title = show['name']
    elif 'title' in show: show_title = show['title']
    if show:
        if show['first_aired']: year = show['first_aired'][:4]
        else: year = None
        trakt_ids = get_trakt_ids("trakt", id, show_title, "show", year)
        preason = trakt.get_season(id, season)
        if preason:
            prepisode = trakt.get_episode(id, season, episode)
        elif not preason and season > 1900: 
            seasons = trakt.get_seasons(id)
            for item in seasons:
                if item['first_aired'] != None:
                    if int(item['first_aired'][:4]) == season: 
                        season_number = item['number']
                        preason = trakt.get_season(id, season_number)
    if not prepisode or not preason or not show: return tvmaze_play_episode(show_title, season, episode, mode)
    show_info = get_tvshow_metadata_trakt(show)
    season_info = get_season_metadata_trakt(show_info, preason)
    episode_info = get_episode_metadata_trakt(season_info, prepisode)
    title = show_info['name']
    if show_info['poster'] != None and show_info['poster'] != "": show_poster = show_info['poster']
    else: show_poster = ""
    if show_info['fanart'] != None and show_info['fanart'] != "": show_fanart = show_info['fanart']
    else: show_fanart = ""
    items = []
    if mode == 'select': play_plugin = ADDON_SELECTOR.id
    elif mode == 'context': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_CONTEXT, unicode)
    elif mode == 'library':
        play_plugin = get_tv_player_plugin_from_library(id)
        if not play_plugin or play_plugin == "default": play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY, unicode)
    elif mode == 'default': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER, unicode)
    else: play_plugin = mode
    if mode == 'default' or mode == 'select': players = active_players("tvshows")
    else: players = get_players("tvshows")
    players = [p for p in players if p.id == play_plugin] or players
    if not players: return xbmc.executebuiltin( "Action(Info)")
    params = {}
    for lang in get_needed_langs(players):
        if show['name'] is None: continue
        episode_parameters = get_trakt_episode_parameters(show, preason, prepisode)
        if episode_parameters is not None: params[lang] = episode_parameters
        else:
            if trakt_ids["tmdb"] != None and trakt_ids["tmdb"] != "" and tried != "tmdb": 
                tried = "tmdb"
                return tvdb_play_episode(trakt_ids["tvdb"], season, episode, mode)
            elif tried == "tmdb":
                msg = "{0} {1} - S{2}E{3}".format(_("No TVDb or TMDb information found for"), show_info['name'], season, episode)
                dialogs.ok(_("%s not found") % _("Episode information"), msg)
                return
            else:
                msg = "{0} {1} - S{2}E{3}".format(_("No TMDb information found for"), show_info['name'], season, episode)
                dialogs.ok(_("%s not found") % _("Episode information"), msg)
                return
        if trakt_ids != None: params[lang].update(trakt_ids)
        params[lang]['info'] = show_info
        params[lang] = to_unicode(params[lang])
    link = on_play_video(mode, players, params, trakt_ids)
    if link:
        set_property("data", json.dumps({'dbid': dbid, 'trakt': id, 'season': season, 'episode': episode}))
        episode_metadata = get_episode_metadata_trakt(season_info, prepisode)
        action_play({
            'label': episode_info['title'],
            'path': link,
            'info': episode_info,
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': episode_info['poster'],
            'poster': episode_info['poster'],
            'properties' : {'fanart_image' : str(show_info['fanart'])},
        })
Esempio n. 15
0
def tvmaze_play_episode(id, season, episode, mode, title=None):
    title = ""
    try: id = int(id)
    except: title = id
    if title and title != "":
        url = "http://api.tvmaze.com/search/shows?q=%s" % id
        response = urllib.urlopen(url)
        shows = json.loads(response.read())
        if len(shows) > 0:
            show = shows[0]
            id = show['show']['id']
    url = "http://api.tvmaze.com/shows/%d?embed[]=seasons&embed[]=episodes" % int(id)
    response = urllib.urlopen(url)
    show = json.loads(response.read())
    season = int(season)
    episode = int(episode)
    dbid = xbmc.getInfoLabel("ListItem.DBID")
    try: dbid = int(dbid)
    except: dbid = None
    if show['externals']:
        if show['externals']['thetvdb']: trakt_ids = get_trakt_ids("tvdb", show['externals']['thetvdb'], show['name'], "show", show['premiered'][:4])
        elif show['externals']['imdb']: trakt_ids = get_trakt_ids("imdb", show['externals']['imdb'], show['name'], "show", show['premiered'][:4])
        else: trakt_ids = get_trakt_ids(query=show['name'], type="show", year=show['premiered'][:4])
    else: trakt_ids = get_trakt_ids(query=show['name'], type="show", year=show['premiered'][:4])
    show_info = get_tvshow_metadata_tvmaze(show)
    preasons = show['_embedded']['seasons']
    for item in preasons:
        if item['number'] == season: 
            preason = item
            season = preasons.index(item) + 1
        elif item['premiereDate'] and item['endDate']:
            if int(item['premiereDate'][:4]) <= season and int(item['endDate'][:4]) >= season: 
                preason = item
                season = preasons.index(item) + 1
    prepisodes = show['_embedded']['episodes']
    for item in prepisodes:
        if item['number'] == episode: prepisode = item
    season_info = get_season_metadata_tvmaze(show_info, preason)
    episode_info = get_episode_metadata_tvmaze(season_info, prepisode)
    if show_info['poster'] != None and show_info['poster'] != "": show_poster = show_info['poster']
    else: show_poster = ""
    if show_info['fanart'] != None and show_info['fanart'] != "": show_fanart = show_info['fanart']
    else: show_fanart = ""
    items = []
    if mode == 'select': play_plugin = ADDON_SELECTOR.id
    elif mode == 'context': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_CONTEXT, unicode)
    elif mode == 'library':
        play_plugin = get_tv_player_plugin_from_library(id)
        if not play_plugin or play_plugin == "default": play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY, unicode)
    elif mode == 'default': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER, unicode)
    else: play_plugin = mode
    if mode == 'default' or mode == 'select': players = active_players("tvshows")
    else: players = get_players("tvshows")
    players = [p for p in players if p.id == play_plugin] or players
    if not players: return xbmc.executebuiltin( "Action(Info)")
    params = {}
    for lang in get_needed_langs(players):
        if show['name'] is None: continue
        episode_parameters = get_tvmaze_episode_parameters(show, preason, prepisode)
        if episode_parameters is not None: params[lang] = episode_parameters
        else:
            if trakt_ids["tmdb"] != None and trakt_ids["tmdb"] != "" and tried != "tmdb": 
                tried = "tmdb"
                return tvdb_play_episode(trakt_ids["tvdb"], season, episode, mode)
            elif tried == "tmdb":
                msg = "{0} {1} - S{2}E{3}".format(_("No TVDb or TMDb information found for"), show_info['name'], season, episode)
                dialogs.ok(_("%s not found") % _("Episode information"), msg)
                return
            else:
                msg = "{0} {1} - S{2}E{3}".format(_("No TMDb information found for"), show_info['name'], season, episode)
                dialogs.ok(_("%s not found") % _("Episode information"), msg)
                return
        if trakt_ids != None: params[lang].update(trakt_ids)
        params[lang]['info'] = show_info
        params[lang] = to_unicode(params[lang])
    link = on_play_video(mode, players, params, trakt_ids)
    if link:
        set_property("data", json.dumps({'dbid': dbid, 'tvdb': trakt_ids['tvdb'], 'season': season, 'episode': episode}))
        episode_metadata = get_episode_metadata_tvmaze(season_info, prepisode)
        action_play({
            'label': episode_info['title'],
            'path': link,
            'info': [],
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': episode_info['poster'],
            'poster': episode_info['poster'],
            'properties' : {'fanart_image' : str(show_info['fanart'])},
        })
Esempio n. 16
0
def tmdb_play_episode(id, season, episode, mode):
    tried = "tvdb"
    import_tmdb()
    id = int(id)
    season = int(season)
    episode = int(episode)
    dbid = xbmc.getInfoLabel("ListItem.DBID")
    try: dbid = int(dbid)
    except: dbid = None
    show = tmdb.TV(id).info(language=LANG, append_to_response="external_ids,images,similar,videos")
    if 'first_air_date' in show and show['first_air_date'] != None: year = show['first_air_date'][:4]
    else: year = None
    trakt_ids = get_trakt_ids("tmdb", id)
    if "status_code" in show: return trakt_play_episode(trakt_ids["trakt"], season, episode, mode)
    if 'name' in show: title = show['name']
    else: title = None
    show_info = get_tvshow_metadata_tmdb(show)
    title = show_info['name']
    preason = tmdb.TV_Seasons(id, season).info(language=LANG, append_to_response="external_ids,images,similar,videos")
    if "The resource you requested could not be found" in str(preason): return trakt_play_episode(trakt_ids["trakt"], season, episode, mode)
    season_info = get_season_metadata_tmdb(show_info, preason)
    prepisode = tmdb.TV_Episodes(id, season, episode).info(language=LANG, append_to_response="external_ids,images,similar,videos")
    if prepisode == "{u'status_code': 34, u'status_message': u'The resource you requested could not be found.'}": return trakt_play_episode(trakt_ids["tmdb"], season, episode, mode)
    episode_info = get_episode_metadata_tmdb(season_info, prepisode)
    if show_info['poster'] != None and show_info['poster'] != "": show_poster = show_info['poster']
    else: show_poster = ""
    if show_info['fanart'] != None and show_info['fanart'] != "": show_fanart = show_info['fanart']
    else: show_fanart = ""
    episodes = preason['episodes']
    items = []
    if mode == 'select': play_plugin = ADDON_SELECTOR.id
    elif mode == 'context': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_CONTEXT, unicode)
    elif mode == 'library':
        play_plugin = get_tv_player_plugin_from_library(id)
        if not play_plugin or play_plugin == "default": play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY, unicode)
    elif mode == 'default': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER, unicode)
    else: play_plugin = mode
    if mode == 'default' or mode == 'select': players = active_players("tvshows")
    else: players = get_players("tvshows")
    players = [p for p in players if p.id == play_plugin] or players
    if not players: return xbmc.executebuiltin( "Action(Info)")
    trakt_ids = get_trakt_ids("tmdb", id, show_info['name'], "show", show['first_air_date'][:4])
    params = {}
    for lang in get_needed_langs(players):
        if show['name'] is None: continue
        episode_parameters = get_tmdb_episode_parameters(show, preason, prepisode)
        if episode_parameters is not None: params[lang] = episode_parameters
        else:
            if trakt_ids["trakt"] != None and trakt_ids["trakt"] != "":
                return trakt_play_episode(trakt_ids["trakt"], season, episode, mode)
            else:
                msg = "{0} {1} - S{2}E{3}".format(_("No TMDb information found for"), show_info['name'], season, episode)
                dialogs.ok(_("%s not found") % _("Episode information"), msg)
                return
        if trakt_ids != None: params[lang].update(trakt_ids)
        params[lang]['info'] = show_info
        params[lang] = to_unicode(params[lang])
    link = on_play_video(mode, players, params, trakt_ids)
    if link:
        set_property("data", json.dumps({'dbid': dbid, 'tmdb': id, 'season': season, 'episode': episode}))
        episode_metadata = get_episode_metadata_tmdb(season_info, prepisode)
        action_play({
            'label': episode_info['title'],
            'path': link,
            'info': [],
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': episode_info['poster'],
            'poster': episode_info['poster'],
            'properties' : {'fanart_image' : str(show_info['fanart'])},
        })
Esempio n. 17
0
def play_episode(id, season, episode, mode):
    import_tvdb()
    id = int(id)
    season = int(season)
    episode = int(episode)
    # Get database id
    dbid = xbmc.getInfoLabel("ListItem.DBID")
    try:
        dbid = int(dbid)
    except:
        dbid = None
    # Get show data from TVDB
    show = tvdb[id]
    show_info = get_tvshow_metadata_tvdb(show, banners=False)
    # Get players to use
    if mode == 'select':
        play_plugin = ADDON_SELECTOR.id
    elif mode == 'context':
        play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_CONTEXT, unicode)
    elif mode == 'library':
        play_plugin = get_tv_player_plugin_from_library(id)
        if not play_plugin or play_plugin == "default":
            play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY, unicode)
    elif mode == 'default':
        play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER, unicode)
    else:
        play_plugin = mode
    if mode == 'default' or mode == 'select': players = active_players("tvshows", filters = {'network': show.get('network')})
    else: players = get_players("tvshows", filters = {'network': show.get('network')})
    players = [p for p in players if p.id == play_plugin] or players
    if not players: return xbmc.executebuiltin( "Action(Info)")
    # Get show ids from Trakt
    trakt_ids = get_trakt_ids("tvdb", id, show['seriesname'], "show", show.get('year', 0))
    # Get parameters
    params = {}
    for lang in get_needed_langs(players):
        if lang == LANG:
            tvdb_data = show
        else:
            tvdb_data = create_tvdb(lang)[id]
        if tvdb_data['seriesname'] is None:
            continue
        episode_parameters = get_episode_parameters(tvdb_data, season, episode)
        if episode_parameters is not None:
            params[lang] = episode_parameters
        else:
            if trakt_ids["tmdb"] != None and trakt_ids["tmdb"] != "":
                return tmdb_play_episode(trakt_ids["tmdb"], season, episode, mode)
            elif trakt_ids["tvdb"] == None or trakt_ids["tvdb"] == "":
                msg = "{0} {1} - S{2}E{3}".format(_("No TVDb information found for"), show_info['name'], season, episode)
                return dialogs.ok(_("%s not found") % _("Episode information"), msg)
            else:
                msg = "{0} {1} - S{2}E{3}".format(_("No TVDb or TMDb information found for"), show_info['name'], season, episode)
                return dialogs.ok(_("%s not found") % _("Episode information"), msg)
        if trakt_ids != None: params[lang].update(trakt_ids)
        params[lang]['info'] = show_info
        params[lang] = to_unicode(params[lang])
    # Go for it
    link = on_play_video(mode, players, params, trakt_ids)
    if link:
        # set properties
        set_property("data", json.dumps({'dbid': dbid, 'tvdb': id, 
            'season': season, 'episode': episode}))
        # Play
        season_info = get_season_metadata_tvdb(show_info, show[season], banners=False)
        episode_info = get_episode_metadata_tvdb(season_info, show[season][episode])
        action_play({
            'label': episode_info['title'],
            'path': link,
            'info': episode_info,
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': episode_info['poster'],
            'poster': episode_info['poster'],
            'properties' : {'fanart_image' : episode_info['fanart']},
        })
Esempio n. 18
0
def trakt_play_episode(id, season, episode, mode):
    from trakt import trakt
    id = int(id)
    season = int(season)
    episode = int(episode)
    show = None
    preason = None
    prepisode = None
    dbid = xbmc.getInfoLabel("ListItem.DBID")
    try: dbid = int(dbid)
    except: dbid = None
    show = trakt.get_show(id)
    if 'name' in show: show_title = show['name']
    elif 'title' in show: show_title = show['title']
    if show:
        if show['first_aired']: year = show['first_aired'][:4]
        else: year = None
        trakt_ids = get_trakt_ids("trakt", id, show_title, "show", year)
        preason = trakt.get_season(id, season)
        if preason:
            prepisode = trakt.get_episode(id, season, episode)
        elif not preason and season > 1900: 
            seasons = trakt.get_seasons(id)
            for item in seasons:
                if item['first_aired'] != None:
                    if int(item['first_aired'][:4]) == season: 
                        season_number = item['number']
                        preason = trakt.get_season(id, season_number)
    if not prepisode or not preason or not show: return tvmaze_play_episode(show_title, season, episode, mode)
    show_info = get_tvshow_metadata_trakt(show)
    season_info = get_season_metadata_trakt(show_info, preason)
    episode_info = get_episode_metadata_trakt(season_info, prepisode)
    title = show_info['name']
    if show_info['poster'] != None and show_info['poster'] != "": show_poster = show_info['poster']
    else: show_poster = ""
    if show_info['fanart'] != None and show_info['fanart'] != "": show_fanart = show_info['fanart']
    else: show_fanart = ""
    items = []
    if mode == 'select': play_plugin = ADDON_SELECTOR.id
    elif mode == 'context': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_CONTEXT, unicode)
    elif mode == 'library':
        play_plugin = get_tv_player_plugin_from_library(id)
        if not play_plugin or play_plugin == "default": play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY, unicode)
    elif mode == 'default': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER, unicode)
    else: play_plugin = mode
    if mode == 'default' or mode == 'select': players = active_players("tvshows")
    else: players = get_players("tvshows")
    players = [p for p in players if p.id == play_plugin] or players
    if not players: return xbmc.executebuiltin( "Action(Info)")
    params = {}
    for lang in get_needed_langs(players):
        if show['name'] is None: continue
        episode_parameters = get_trakt_episode_parameters(show, preason, prepisode)
        if episode_parameters is not None: params[lang] = episode_parameters
        else:
            if trakt_ids["tmdb"] != None and trakt_ids["tmdb"] != "" and tried != "tmdb": 
                tried = "tmdb"
                return tvdb_play_episode(trakt_ids["tvdb"], season, episode, mode)
            elif tried == "tmdb":
                msg = "{0} {1} - S{2}E{3}".format(_("No TVDb or TMDb information found for"), show_info['name'], season, episode)
                dialogs.ok(_("%s not found") % _("Episode information"), msg)
                return
            else:
                msg = "{0} {1} - S{2}E{3}".format(_("No TMDb information found for"), show_info['name'], season, episode)
                dialogs.ok(_("%s not found") % _("Episode information"), msg)
                return
        if trakt_ids != None: params[lang].update(trakt_ids)
        params[lang]['info'] = show_info
        params[lang] = to_unicode(params[lang])
    link = on_play_video(mode, players, params, trakt_ids)
    if link:
        set_property("data", json.dumps({'dbid': dbid, 'trakt': id, 'season': season, 'episode': episode}))
        episode_metadata = get_episode_metadata_trakt(season_info, prepisode)
        action_play({
            'label': episode_info['title'],
            'path': link,
            'info': episode_info,
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': episode_info['poster'],
            'poster': episode_info['poster'],
            'properties' : {'fanart_image' : str(show_info['fanart'])},
        })
Esempio n. 19
0
def tvmaze_play_episode(id, season, episode, mode, title=None):
    title = ""
    try: id = int(id)
    except: title = id
    if title and title != "":
        url = "http://api.tvmaze.com/search/shows?q=%s" % id
        response = urllib.urlopen(url)
        shows = json.loads(response.read())
        if len(shows) > 0:
            show = shows[0]
            id = show['show']['id']
    url = "http://api.tvmaze.com/shows/%d?embed[]=seasons&embed[]=episodes" % int(id)
    response = urllib.urlopen(url)
    show = json.loads(response.read())
    season = int(season)
    episode = int(episode)
    dbid = xbmc.getInfoLabel("ListItem.DBID")
    try: dbid = int(dbid)
    except: dbid = None
    if show['externals']:
        if show['externals']['thetvdb']: trakt_ids = get_trakt_ids("tvdb", show['externals']['thetvdb'], show['name'], "show", show['premiered'][:4])
        elif show['externals']['imdb']: trakt_ids = get_trakt_ids("imdb", show['externals']['imdb'], show['name'], "show", show['premiered'][:4])
        else: trakt_ids = get_trakt_ids(query=show['name'], type="show", year=show['premiered'][:4])
    else: trakt_ids = get_trakt_ids(query=show['name'], type="show", year=show['premiered'][:4])
    show_info = get_tvshow_metadata_tvmaze(show)
    preasons = show['_embedded']['seasons']
    for item in preasons:
        if item['number'] == season: 
            preason = item
            season = preasons.index(item) + 1
        elif item['premiereDate'] and item['endDate']:
            if int(item['premiereDate'][:4]) <= season and int(item['endDate'][:4]) >= season: 
                preason = item
                season = preasons.index(item) + 1
    prepisodes = show['_embedded']['episodes']
    for item in prepisodes:
        if item['number'] == episode: prepisode = item
    season_info = get_season_metadata_tvmaze(show_info, preason)
    episode_info = get_episode_metadata_tvmaze(season_info, prepisode)
    if show_info['poster'] != None and show_info['poster'] != "": show_poster = show_info['poster']
    else: show_poster = ""
    if show_info['fanart'] != None and show_info['fanart'] != "": show_fanart = show_info['fanart']
    else: show_fanart = ""
    items = []
    if mode == 'select': play_plugin = ADDON_SELECTOR.id
    elif mode == 'context': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_CONTEXT, unicode)
    elif mode == 'library':
        play_plugin = get_tv_player_plugin_from_library(id)
        if not play_plugin or play_plugin == "default": play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY, unicode)
    elif mode == 'default': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER, unicode)
    else: play_plugin = mode
    if mode == 'default' or mode == 'select': players = active_players("tvshows")
    else: players = get_players("tvshows")
    players = [p for p in players if p.id == play_plugin] or players
    if not players: return xbmc.executebuiltin( "Action(Info)")
    params = {}
    for lang in get_needed_langs(players):
        if show['name'] is None: continue
        episode_parameters = get_tvmaze_episode_parameters(show, preason, prepisode)
        if episode_parameters is not None: params[lang] = episode_parameters
        else:
            if trakt_ids["tmdb"] != None and trakt_ids["tmdb"] != "" and tried != "tmdb": 
                tried = "tmdb"
                return tvdb_play_episode(trakt_ids["tvdb"], season, episode, mode)
            elif tried == "tmdb":
                msg = "{0} {1} - S{2}E{3}".format(_("No TVDb or TMDb information found for"), show_info['name'], season, episode)
                dialogs.ok(_("%s not found") % _("Episode information"), msg)
                return
            else:
                msg = "{0} {1} - S{2}E{3}".format(_("No TMDb information found for"), show_info['name'], season, episode)
                dialogs.ok(_("%s not found") % _("Episode information"), msg)
                return
        if trakt_ids != None: params[lang].update(trakt_ids)
        params[lang]['info'] = show_info
        params[lang] = to_unicode(params[lang])
    link = on_play_video(mode, players, params, trakt_ids)
    if link:
        set_property("data", json.dumps({'dbid': dbid, 'tvdb': trakt_ids['tvdb'], 'season': season, 'episode': episode}))
        episode_metadata = get_episode_metadata_tvmaze(season_info, prepisode)
        action_play({
            'label': episode_info['title'],
            'path': link,
            'info': [],
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': episode_info['poster'],
            'poster': episode_info['poster'],
            'properties' : {'fanart_image' : str(show_info['fanart'])},
        })
Esempio n. 20
0
def play_episode(id, season, episode, mode):  
    import_tvdb()
    
    id = int(id)
    season = int(season)
    episode = int(episode)
    
    # Get database id
    dbid = xbmc.getInfoLabel("ListItem.DBID")
    try:
        dbid = int(dbid)
    except:
        dbid = None
        
    # Get show data from TVDB
    show = tvdb[id]
    show_info = get_tvshow_metadata_tvdb(show, banners=False)

    # Get players to use
    if mode == 'select':
        play_plugin = ADDON_SELECTOR.id
    elif mode == 'library':
        play_plugin = get_player_plugin_from_library(id)
        if not play_plugin or play_plugin == "default":
            play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY)
    else:
        play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER)
    players = active_players("tvshows", filters = {'network': show.get('network')})
    players = [p for p in players if p.id == play_plugin] or players
    if not players:
        xbmc.executebuiltin( "Action(Info)")
        action_cancel()
        return
    
    # Get show ids from Trakt
    trakt_ids = get_trakt_ids("tvdb", id, show['seriesname'],
                    "show", show.get('year', 0))

    # Get parameters
    params = {}
    for lang in get_needed_langs(players):
        if lang == LANG:
            tvdb_data = show
        else:
            tvdb_data = create_tvdb(lang)[id]
        if tvdb_data['seriesname'] is None:
            continue
        episode_parameters = get_episode_parameters(tvdb_data, season, episode)
        if episode_parameters is not None:
            params[lang] = episode_parameters
        else:
            msg = "{0} {1} - S{1}E{2}".format(_("No tvdb information found for"), show['seriesname'], season, episode)
            dialogs.ok(_("Episode info not found"), msg)
            return
        
        params[lang].update(trakt_ids)
        params[lang]['info'] = show_info
        params[lang] = to_unicode(params[lang])

    # Go for it
    link = on_play_video(mode, players, params, trakt_ids)
    if link:
        # set properties
        set_property("data", json.dumps({'dbid': dbid, 'tvdb': id, 
            'season': season, 'episode': episode}))
    
        # Play
        season_info = get_season_metadata_tvdb(show_info, show[season], banners=False)
        episode_info = get_episode_metadata_tvdb(season_info, show[season][episode])
        action_play({
            'label': episode_info['title'],
            'path': link,
            'info': episode_info,
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': episode_info['poster'],
            'poster': episode_info['poster'],
            'properties' : {'fanart_image' : episode_info['fanart']},
        })
Esempio n. 21
0
def play_episode_from_guide(id, season, episode, mode):  
    import_tvdb()
    id = int(id)
    season = int(season)
    episode = int(episode)
    dbid = xbmc.getInfoLabel("ListItem.DBID")
    try:
        dbid = int(dbid)
    except:
        dbid = None
    show = tvdb[id]
    show_info = get_tvshow_metadata_tvdb(show, banners=False)
    if mode == 'select':
        play_plugin = ADDON_PICKER.id
    elif mode == 'default':
        play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_CHANNELER)
    else:
        play_plugin = mode
    channelers = active_channelers("tvshows", filters = {'network': show.get('network')})
    channelers = [p for p in channelers if p.id == play_plugin] or channelers
    if not channelers:
        xbmc.executebuiltin( "Action(Info)")
        action_cancel()
        return
    trakt_ids = get_trakt_ids("tvdb", id, show['seriesname'],
                    "show", show.get('year', 0))
    params = {}
    for lang in get_needed_langs(channelers):
        if lang == LANG:
            tvdb_data = show
        else:
            tvdb_data = create_tvdb(lang)[id]
        if tvdb_data['seriesname'] is None:
            continue
        episode_parameters = get_episode_parameters(tvdb_data, season, episode)
        if episode_parameters is not None:
            params[lang] = episode_parameters
        else:
            msg = "{0} {1} - S{1}E{2}".format(_("No tvdb information found for"), show['seriesname'], season, episode)
            dialogs.ok(_("Episode info not found"), msg)
            return
        if trakt_ids != None:
            params[lang].update(trakt_ids)
        params[lang]['info'] = show_info
        params[lang] = to_unicode(params[lang])
    link = on_play_video(mode, channelers, params, trakt_ids)
    if link:
        set_property("data", json.dumps({'dbid': dbid, 'tvdb': id, 
            'season': season, 'episode': episode}))
        season_info = get_season_metadata_tvdb(show_info, show[season], banners=False)
        episode_info = get_episode_metadata_tvdb(season_info, show[season][episode])
        action_play({
            'label': episode_info['title'],
            'path': link,
            'info': episode_info,
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': episode_info['poster'],
            'poster': episode_info['poster'],
            'properties' : {'fanart_image' : episode_info['fanart']},
        })
Esempio n. 22
0
def tmdb_play_episode(id, season, episode, mode):
    tried = "tvdb"
    import_tmdb()
    id = int(id)
    season = int(season)
    episode = int(episode)
    dbid = xbmc.getInfoLabel("ListItem.DBID")
    try: dbid = int(dbid)
    except: dbid = None
    show = tmdb.TV(id).info(language=LANG, append_to_response="external_ids,images,similar,videos")
    if 'first_air_date' in show and show['first_air_date'] != None: year = show['first_air_date'][:4]
    else: year = None
    trakt_ids = get_trakt_ids("tmdb", id)
    if "status_code" in show: return trakt_play_episode(trakt_ids["trakt"], season, episode, mode)
    if 'name' in show: title = show['name']
    else: title = None
    show_info = get_tvshow_metadata_tmdb(show)
    title = show_info['name']
    preason = tmdb.TV_Seasons(id, season).info(language=LANG, append_to_response="external_ids,images,similar,videos")
    if "The resource you requested could not be found" in str(preason): return trakt_play_episode(trakt_ids["trakt"], season, episode, mode)
    season_info = get_season_metadata_tmdb(show_info, preason)
    prepisode = tmdb.TV_Episodes(id, season, episode).info(language=LANG, append_to_response="external_ids,images,similar,videos")
    if prepisode == "{u'status_code': 34, u'status_message': u'The resource you requested could not be found.'}": return trakt_play_episode(trakt_ids["tmdb"], season, episode, mode)
    episode_info = get_episode_metadata_tmdb(season_info, prepisode)
    if show_info['poster'] != None and show_info['poster'] != "": show_poster = show_info['poster']
    else: show_poster = ""
    if show_info['fanart'] != None and show_info['fanart'] != "": show_fanart = show_info['fanart']
    else: show_fanart = ""
    episodes = preason['episodes']
    items = []
    if mode == 'select': play_plugin = ADDON_SELECTOR.id
    elif mode == 'context': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_CONTEXT, unicode)
    elif mode == 'library':
        play_plugin = get_tv_player_plugin_from_library(id)
        if not play_plugin or play_plugin == "default": play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY, unicode)
    elif mode == 'default': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER, unicode)
    else: play_plugin = mode
    if mode == 'default' or mode == 'select': players = active_players("tvshows")
    else: players = get_players("tvshows")
    players = [p for p in players if p.id == play_plugin] or players
    if not players: return xbmc.executebuiltin( "Action(Info)")
    trakt_ids = get_trakt_ids("tmdb", id, show_info['name'], "show", show['first_air_date'][:4])
    params = {}
    for lang in get_needed_langs(players):
        if show['name'] is None: continue
        episode_parameters = get_tmdb_episode_parameters(show, preason, prepisode)
        if episode_parameters is not None: params[lang] = episode_parameters
        else:
            if trakt_ids["trakt"] != None and trakt_ids["trakt"] != "":
                return trakt_play_episode(trakt_ids["trakt"], season, episode, mode)
            else:
                msg = "{0} {1} - S{2}E{3}".format(_("No TMDb information found for"), show_info['name'], season, episode)
                dialogs.ok(_("%s not found") % _("Episode information"), msg)
                return
        if trakt_ids != None: params[lang].update(trakt_ids)
        params[lang]['info'] = show_info
        params[lang] = to_unicode(params[lang])
    link = on_play_video(mode, players, params, trakt_ids)
    if link:
        set_property("data", json.dumps({'dbid': dbid, 'tmdb': id, 'season': season, 'episode': episode}))
        episode_metadata = get_episode_metadata_tmdb(season_info, prepisode)
        action_play({
            'label': episode_info['title'],
            'path': link,
            'info': [],
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': episode_info['poster'],
            'poster': episode_info['poster'],
            'properties' : {'fanart_image' : str(show_info['fanart'])},
        })