Ejemplo n.º 1
0
def sort_players(players, filters={}):
    result = []
    for player in players:
        filtered = False
        checked = False
        for filter_key, filter_value in filters.items():
            value = player.filters.get(filter_key)
            if value:
                checked = True
                if to_unicode(value) != to_unicode(filter_value):
                    filtered = True

        if not filtered:
            needs_browsing = False
            for command_group in player.commands:
                for command in command_group:
                    if command.get('steps'):
                        needs_browsing = True
                        break

            result.append((not checked, needs_browsing, player.order,
                           player.clean_title.lower(), player))

    result.sort()
    return [x[-1] for x in result]
Ejemplo n.º 2
0
def resolve_player(player, lister, params):
    results = []
    for command_group in player.commands:
        if xbmc.abortRequested or not lister.is_active(): return
        command_group_results = []
        for command in command_group:
            if xbmc.abortRequested or not lister.is_active(): return
            lang = command.get("language", "en")
            if not lang in params: continue
            parameters = params[lang]
            try:
                link = apply_parameters(to_unicode(command["link"]),
                                        parameters)
            except:
                print_exc()
                continue
            if link == "movies" and player.media == "movies":
                video = get_movie_from_library(parameters['imdb'])
                if video:
                    command_group_results.append(video)
            elif link == "tvshows" and player.media == "tvshows":
                video = get_episode_from_library(parameters['id'],
                                                 parameters['season'],
                                                 parameters['episode'])
                if not video:
                    video = get_episode_from_library(parameters['tmdb'],
                                                     parameters['season'],
                                                     parameters['episode'])
                if video:
                    command_group_results.append(video)
            elif not command.get("steps"):
                command_group_results.append({
                    'label':
                    player.title,
                    'path':
                    urlencode_path(link),
                    'action':
                    command.get("action", "PLAY")
                })
            else:
                steps = [to_unicode(step) for step in command["steps"]]
                files, dirs = lister.get(link, steps, parameters)
                if command.get("action", "PLAY") == "ACTIVATE":
                    files += dirs
                if files:
                    command_group_results += [{
                        'label':
                        f['label'],
                        'path':
                        player.postprocess(f['path']),
                        'action':
                        command.get("action", "PLAY")
                    } for f in files]
            if command_group_results:
                break
        results += command_group_results
    if results:
        return player.title, results
Ejemplo n.º 3
0
def resolve_player(player, lister, params):
    results = []
    for command_group in player.commands:
        if xbmc.abortRequested or not lister.is_active():
            return
        command_group_results = []
        for command in command_group:
            if xbmc.abortRequested or not lister.is_active():
                return
            lang = command.get("language", "en")
            if not lang in params:
                continue
            parameters = params[lang]
            try:
                link = apply_parameters(to_unicode(command["link"]), parameters)
            except:
                print_exc()
                continue
            if link == "movies" and player.media == "movies":
                video = get_movie_from_library(parameters["imdb"])
                if video:
                    command_group_results.append(video)
            elif link == "tvshows" and player.media == "tvshows":
                video = get_episode_from_library(parameters["id"], parameters["season"], parameters["episode"])
                if not video:
                    video = get_episode_from_library(parameters["tmdb"], parameters["season"], parameters["episode"])
                if video:
                    command_group_results.append(video)
            elif not command.get("steps"):
                command_group_results.append(
                    {"label": player.title, "path": urlencode_path(link), "action": command.get("action", "PLAY")}
                )
            else:
                steps = [to_unicode(step) for step in command["steps"]]
                files, dirs = lister.get(link, steps, parameters)
                if command.get("action", "PLAY") == "ACTIVATE":
                    files += dirs
                if files:
                    command_group_results += [
                        {
                            "label": f["label"],
                            "path": player.postprocess(f["path"]),
                            "action": command.get("action", "PLAY"),
                        }
                        for f in files
                    ]
            if command_group_results:
                break
        results += command_group_results
    if results:
        return player.title, results
Ejemplo n.º 4
0
def play_music(artist_name, track_name, album_name, mode = "default"):
    # Get players to use
    if mode == 'select':
        play_plugin = ADDON_SELECTOR.id
    elif mode == 'context':
        play_plugin = plugin.get_setting(SETTING_MUSIC_DEFAULT_PLAYER_FROM_CONTEXT)
    elif mode == 'library':
        play_plugin = plugin.get_setting(SETTING_MUSIC_DEFAULT_PLAYER_FROM_LIBRARY)
    elif mode == 'default':
        play_plugin = plugin.get_setting(SETTING_MUSIC_DEFAULT_PLAYER)
    else:
        play_plugin = mode
    players = active_players("music")
    players = [p for p in players if p.id == play_plugin] or players
    if not players:
        xbmc.executebuiltin("Action(Info)")
        action_cancel()
        return

    # Get parameters
    params = {}
    for lang in get_needed_langs(players):
        params[lang] = get_music_parameters(artist_name, album_name, track_name)
        params[lang] = to_unicode(params[lang])

    # Go for it
    link = on_play_video(mode, players, params)
    if link:
        action_play({
            'label': "{0} - {1} - {2}".format(artist_name, album_name, track_name),
            'path': link,
            'is_playable': True,
            'info_type': 'music',
        })
Ejemplo n.º 5
0
def play_channel(channel, mode="default"):
    # Get players to use
    if mode == 'select':
        play_plugin = ADDON_SELECTOR.id
    else:
        play_plugin = plugin.get_setting(SETTING_LIVE_DEFAULT_PLAYER)
    players = active_players("live", filters={"channel": channel})
    players = [p for p in players if p.id == play_plugin] or players
    if not players:
        xbmc.executebuiltin("Action(Info)")
        action_cancel()
        return

    # Get parameters
    params = {}
    for lang in get_needed_langs(players):
        params[lang] = get_channel_parameters(channel)
        params[lang] = to_unicode(params[lang])

    # Go for it
    link = on_play_video(mode, players, params)
    if link:
        action_play({
            'label': channel,
            'path': link,
            'is_playable': True,
            'info_type': 'video',
        })
Ejemplo n.º 6
0
def play_channel_from_guide(channel, program, language, mode):
    # Get channelers to use
    if mode == 'select':
        play_plugin = ADDON_PICKER.id
    elif mode == 'default':
        play_plugin = plugin.get_setting(SETTING_LIVE_DEFAULT_CHANNELER)
    else:
        play_plugin = mode
    channelers = active_channelers("live")
    channelers = [p for p in channelers if p.id == play_plugin] or channelers
    if not channelers:
        plugin.notify(msg=_('Install live addons'),
                      title=_('First'),
                      delay=1000,
                      image=get_icon_path("live"))
        action_cancel()
        return
    # Get parameters
    params = {}
    for lang in get_needed_langs(channelers):
        params[lang] = get_channel_parameters(channel, program, language)
        params[lang] = to_unicode(params[lang])
    # Go for it
    link = on_play_video(mode, channelers, params)
    if link:
        action_play({
            'label': channel,
            'path': link,
            'is_playable': True,
            'info_type': 'video',
        })
Ejemplo n.º 7
0
def play_channel_from_guide(channel, program, language, mode):
    # Get channelers to use
    if mode == 'select':
        play_plugin = ADDON_PICKER.id
    elif mode == 'default':
        play_plugin = plugin.get_setting(SETTING_LIVE_DEFAULT_CHANNELER, unicode)
    else:
        play_plugin = mode
    channelers = active_channelers("live")
    channelers = [p for p in channelers if p.id == play_plugin] or channelers
    if not channelers:
        dialogs.notify(msg="{0} {1} {2}".format(_("No cache").replace(_("Cache").lower(),_("TV")), _("Player").lower(), _("Enabled").lower()), title=_("Error"), delay=5000, image=get_icon_path("live"))
        action_cancel()
        return
    # Get parameters
    params = {}
    for lang in get_needed_langs(channelers):
        params[lang] = get_channel_parameters(channel, program, language)
        params[lang] = to_unicode(params[lang])
    # Go for it
    link = on_play_video(mode, channelers, params)
    if link:
        action_play({
            'label': channel,
            'path': link,
            'is_playable': True,
            'info_type': 'video',
        })
Ejemplo n.º 8
0
def play_channel(channel, mode="default"):
    # Get players to use
    if mode == 'select':
        play_plugin = ADDON_SELECTOR.id
    else:
        play_plugin = plugin.get_setting(SETTING_LIVE_DEFAULT_PLAYER)
    players = active_players("live", filters = {"channel": channel})
    players = [p for p in players if p.id == play_plugin] or players
    if not players:
        xbmc.executebuiltin( "Action(Info)")
        action_cancel()
        return

    # Get parameters
    params = {}
    for lang in get_needed_langs(players):
        params[lang] = get_channel_parameters(channel)
        params[lang] = to_unicode(params[lang])

    # Go for it
    link = on_play_video(mode, players, params)
    if link:
        action_play({
            'label': channel,
            'path': link,
            'is_playable': True,
            'info_type': 'video',
        })
Ejemplo n.º 9
0
def play_movie(tmdb_id, mode):
    import_tmdb()
    # Get players to use
    if mode == 'select':
        play_plugin = ADDON_SELECTOR.id
    elif mode == 'context':
        play_plugin = plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER_FROM_CONTEXT, unicode)
    elif mode == 'library':
        play_plugin = get_movie_player_plugin_from_library(tmdb_id)
        if not play_plugin or play_plugin == "default":
            play_plugin = plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER_FROM_LIBRARY, unicode)
    elif mode == 'default':
        play_plugin = plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER, unicode)
    else:
        play_plugin = mode
    if mode != 'context': players = active_players("movies")
    else: players = get_players("movies")
    players = [p for p in players if p.id == play_plugin] or players
    if not players or len(players) == 0:
        xbmc.executebuiltin( "Action(Info)")
        action_cancel()
        return
    # Get movie data from TMDB
    movie = tmdb.Movies(tmdb_id).info(language=LANG, append_to_response="external_ids,alternative_titles,credits,images,keywords,releases,videos,translations,similar,reviews,lists,rating")
    movie_info = get_movie_metadata(movie)
    # Get movie ids from Trakt
    trakt_ids = get_trakt_ids("tmdb", tmdb_id, movie['original_title'],
                    "movie", parse_year(movie['release_date']))
    # Get parameters
    params = {}
    for lang in get_needed_langs(players):
        if lang == LANG:
            tmdb_data = movie
        else:
                        tmdb_data = tmdb.Movies(tmdb_id).info(language=lang, append_to_response="external_ids,alternative_titles,credits,images,keywords,releases,videos,translations,similar,reviews,lists,rating")
        params[lang] = get_movie_parameters(tmdb_data)
        if trakt_ids != None:
            params[lang].update(trakt_ids)
        params[lang]['info'] = movie_info
        params[lang] = to_unicode(params[lang])
    # Go for it
    link = on_play_video(mode, players, params, trakt_ids)
    if link:
        movie = tmdb.Movies(tmdb_id).info(language=LANG)
        action_play({
            'label': movie_info['title'],
            'path': link,
            'info': movie_info,
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': movie_info['poster'],
            'poster': movie_info['poster'],
            'properties' : {'fanart_image' : movie_info['fanart']},
        })
Ejemplo n.º 10
0
def play_movie(tmdb_id, mode):
    import_tmdb()
    # Get players to use
    if mode == 'select':
        play_plugin = ADDON_SELECTOR.id
    elif mode == 'context':
        play_plugin = plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER_FROM_CONTEXT, unicode)
    elif mode == 'library':
        play_plugin = get_movie_player_plugin_from_library(tmdb_id)
        if not play_plugin or play_plugin == "default":
            play_plugin = plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER_FROM_LIBRARY, unicode)
    elif mode == 'default':
        play_plugin = plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER, unicode)
    else:
        play_plugin = mode
    if mode == 'default' or mode == 'select': players = active_players("movies")
    else: players = get_players("movies")
    players = [p for p in players if p.id == play_plugin] or players
    if not players:
        xbmc.executebuiltin( "Action(Info)")
        action_cancel()
        return
    # Get movie data from TMDB
    movie = tmdb.Movies(tmdb_id).info(language=LANG, append_to_response="external_ids,videos")
    movie_info = get_movie_metadata(movie)
    # Get movie ids from Trakt
    trakt_ids = get_trakt_ids("tmdb", tmdb_id, movie['original_title'],
                    "movie", parse_year(movie['release_date']))
    # Get parameters
    params = {}
    for lang in get_needed_langs(players):
        if lang == LANG:
            tmdb_data = movie
        else:
            tmdb_data = tmdb.Movies(tmdb_id).info(language=lang)
        params[lang] = get_movie_parameters(tmdb_data)
        if trakt_ids != None:
            params[lang].update(trakt_ids)
        params[lang]['info'] = movie_info
        params[lang] = to_unicode(params[lang])
    # Go for it
    link = on_play_video(mode, players, params, trakt_ids)
    if link:
        movie = tmdb.Movies(tmdb_id).info(language=LANG)
        action_play({
            'label': movie_info['title'],
            'path': link,
            'info': movie_info,
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': movie_info['poster'],
            'poster': movie_info['poster'],
            'properties' : {'fanart_image' : movie_info['fanart']},
        })
Ejemplo n.º 11
0
def sort_channelers(channelers, filters = {}):
    result = []
    for channeler in channelers:
        filtered = False
        checked = False
        for filter_key, filter_value in filters.items():    
            value = channeler.filters.get(filter_key)
            if value:
                checked = True
                if to_unicode(value) != to_unicode(filter_value):
                    filtered = True
        if not filtered:
            needs_browsing = False
            for command_group in channeler.commands:
                for command in command_group:
                    if command.get('steps'):
                        needs_browsing = True
                        break
            result.append((not checked, needs_browsing, channeler.order, channeler.clean_title.lower(), channeler))
    result.sort()
    return [x[-1] for x in result]
Ejemplo n.º 12
0
def play_movie(tmdb_id, mode):  
    import_tmdb()
        
    # Get players to use
    if mode == 'select':
        play_plugin = ADDON_SELECTOR.id
    elif mode == 'library':
        play_plugin = plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER_FROM_LIBRARY)
    else:
        play_plugin = plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER)
    players = active_players("movies")
    players = [p for p in players if p.id == play_plugin] or players
    if not players:
        xbmc.executebuiltin( "Action(Info)")
        action_cancel()
        return
    
    # Get movie data from TMDB
    movie = tmdb.Movies(tmdb_id).info(language=LANG)
    movie_info = get_movie_metadata(movie)

    # Get movie ids from Trakt
    trakt_ids = get_trakt_ids("tmdb", tmdb_id, movie['original_title'],
                    "movie", parse_year(movie['release_date']))
    
    # Get parameters
    params = {}
    for lang in get_needed_langs(players):
        if lang == LANG:
            tmdb_data = movie
        else:
            tmdb_data = tmdb.Movies(tmdb_id).info(language=lang)
        params[lang] = get_movie_parameters(tmdb_data)
        params[lang].update(trakt_ids)
        params[lang]['info'] = movie_info
        params[lang] = to_unicode(params[lang])

    # Go for it
    link = on_play_video(mode, players, params, trakt_ids)
    if link:
        movie = tmdb.Movies(tmdb_id).info(language=LANG)
        action_play({
            'label': movie_info['title'],
            'path': link,
            'info': movie_info,
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': movie_info['poster'],
            'poster': movie_info['poster'],
            'properties' : {'fanart_image' : movie_info['fanart']},
        })
Ejemplo n.º 13
0
def play_movie_from_guide(tmdb_id, mode):
    import_tmdb()
    if mode == 'select':
        play_plugin = ADDON_PICKER.id
    elif mode == 'default':
        play_plugin = plugin.get_setting(SETTING_MOVIES_DEFAULT_CHANNELER,
                                         unicode)
    else:
        play_plugin = mode
    channelers = active_channelers("movies")
    channelers = [p for p in channelers if p.id == play_plugin] or channelers
    if not channelers:
        xbmc.executebuiltin("Action(Info)")
        action_cancel()
        return
    movie = tmdb.Movies(tmdb_id).info(language=LANG,
                                      append_to_response="external_ids,videos")
    movie_info = get_movie_metadata(movie)
    trakt_ids = get_trakt_ids("tmdb", tmdb_id, movie['original_title'],
                              "movie", parse_year(movie['release_date']))
    params = {}
    for lang in get_needed_langs(channelers):
        if lang == LANG:
            tmdb_data = movie
        else:
            tmdb_data = tmdb.Movies(tmdb_id).info(language=lang)
        params[lang] = get_movie_parameters(tmdb_data)
        if trakt_ids != None:
            params[lang].update(trakt_ids)
        params[lang]['info'] = movie_info
        params[lang] = to_unicode(params[lang])
    link = on_play_video(mode, channelers, params, trakt_ids)
    if link:
        movie = tmdb.Movies(tmdb_id).info(language=LANG)
        action_play({
            'label': movie_info['title'],
            'path': link,
            'info': movie_info,
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': movie_info['poster'],
            'poster': movie_info['poster'],
            'properties': {
                'fanart_image': movie_info['fanart']
            },
        })
Ejemplo n.º 14
0
def play_movie_from_guide(tmdb_id, mode):  
    import_tmdb()
    if mode == 'select':
        play_plugin = ADDON_PICKER.id
    elif mode == 'default':
        play_plugin = plugin.get_setting(SETTING_MOVIES_DEFAULT_CHANNELER)
    else:
        play_plugin = mode
    channelers = active_channelers("movies")
    channelers = [p for p in channelers if p.id == play_plugin] or channelers
    if not channelers:
        xbmc.executebuiltin( "Action(Info)")
        action_cancel()
        return
    movie = tmdb.Movies(tmdb_id).info(language=LANG)
    movie_info = get_movie_metadata(movie)
    trakt_ids = get_trakt_ids("tmdb", tmdb_id, movie['original_title'],
                    "movie", parse_year(movie['release_date']))
    params = {}
    for lang in get_needed_langs(channelers):
        if lang == LANG:
            tmdb_data = movie
        else:
            tmdb_data = tmdb.Movies(tmdb_id).info(language=lang)
        params[lang] = get_movie_parameters(tmdb_data)
        if trakt_ids != None:
            params[lang].update(trakt_ids)
        params[lang]['info'] = movie_info
        params[lang] = to_unicode(params[lang])
    link = on_play_video(mode, channelers, params, trakt_ids)
    if link:
        movie = tmdb.Movies(tmdb_id).info(language=LANG)
        action_play({
            'label': movie_info['title'],
            'path': link,
            'info': movie_info,
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': movie_info['poster'],
            'poster': movie_info['poster'],
            'properties' : {'fanart_image' : movie_info['fanart']},
        })
Ejemplo n.º 15
0
def play_channel(channel, program, language, mode):
    # Get players to use
    if mode == 'select':
        play_plugin = ADDON_SELECTOR.id
    elif mode == 'context':
        play_plugin = plugin.get_setting(
            SETTING_LIVE_DEFAULT_PLAYER_FROM_CONTEXT)
    elif mode == 'library':
        play_plugin = plugin.get_setting(
            SETTING_LIVE_DEFAULT_PLAYER_FROM_LIBRARY)
    elif mode == 'default':
        play_plugin = plugin.get_setting(SETTING_LIVE_DEFAULT_PLAYER)
    else:
        play_plugin = mode
    players = active_players("live")
    players = [p for p in players if p.id == play_plugin] or players
    if not players:
        plugin.notify(msg=_('Enable live players'),
                      title=_('First'),
                      delay=1000,
                      image=get_icon_path("live"))
        action_cancel()
        return
    # Get parameters
    params = {}
    for lang in get_needed_langs(players):
        params[lang] = get_channel_parameters(channel, program, language)
        params[lang] = to_unicode(params[lang])
    # Go for it
    link = on_play_video(mode, players, params)
    if link:
        action_play({
            'label': channel,
            'path': link,
            'is_playable': True,
            'info_type': 'video',
        })
Ejemplo n.º 16
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']},
        })
Ejemplo n.º 17
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']},
        })
Ejemplo n.º 18
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'])},
        })
Ejemplo 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'])},
        })
Ejemplo n.º 20
0
 def prep_search_str(self, text):
     t_text = to_unicode(text)
     for chr in t_text:
         if ord(chr) >= 1488 and ord(chr) <= 1514:
             return to_utf8(text[::-1])
     return to_utf8(text)
Ejemplo 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, 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']},
        })
Ejemplo n.º 22
0
def play_movie(tmdb_id, mode):  
    import_tmdb()
        
    # Get active players
    players = active_players("movies")
    if not players:
        xbmc.executebuiltin( "Action(Info)")
        action_cancel()
        return

    # Get player to use
    if mode == 'select':
        play_plugin = ADDON_SELECTOR.id
    elif mode == 'library':
        play_plugin = plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER_FROM_LIBRARY)
    else:
        play_plugin = plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER)
    
    # Use just selected player if exists (selectors excluded)
    players = [p for p in players if p.id == play_plugin] or players

    # Get movie data from TMDB
    movie = tmdb.Movies(tmdb_id).info(language=LANG)
    movie_info = get_movie_metadata(movie)

    # Get movie ids from Trakt
    trakt_ids = get_trakt_ids("tmdb", tmdb_id, movie['original_title'],
                    "movie", parse_year(movie['release_date']))
    
    # Preload params
    params = {}
    for lang in get_needed_langs(players):
        if lang == LANG:
            tmdb_data = movie
        else:
            tmdb_data = tmdb.Movies(tmdb_id).info(language=lang)
        params[lang] = get_movie_parameters(tmdb_data)
        params[lang].update(trakt_ids)
        params[lang]['info'] = movie_info
        params[lang] = to_unicode(params[lang])
        
    # BETA
    action_cancel()
        
    # Get single video selection        
    use_simple_selector = plugin.get_setting(SETTING_USE_SIMPLE_SELECTOR, converter=bool)
    selection = get_video_link(players, params, mode, use_simple_selector)
    if not selection:
        #action_cancel()
        return
        
    # Get selection details
    link = selection['path']
    action = selection.get('action', '')
    
    plugin.log.info('Playing url: %s' % link.encode('utf-8'))

    # Activate link
    if action == "ACTIVATE":
        action_activate(link)
    else:
        movie = tmdb.Movies(tmdb_id).info(language=LANG)
        listitem = {
            'label': movie_info['title'],
            'path': link,
            'info': movie_info,
            'is_playable': True,
            'info_type': 'video',
            'thumbnail': movie_info['poster'],
            'poster': movie_info['poster'],
            'properties' : {'fanart_image' : movie_info['fanart']},
        }
        
        if trakt_ids:
            set_property('script.trakt.ids', json.dumps(trakt_ids))

        if action == "PLAY":
            action_play(listitem)
        else:
            action_resolve(listitem)
Ejemplo n.º 23
0
def resolve_player(player, lister, params):
    results = []
    
    for command_group in player.commands:  
        if xbmc.abortRequested or not lister.is_active():
            return
        
        command_group_results = []
        for command in command_group:
            if xbmc.abortRequested or not lister.is_active():
                return
            
            lang = command.get("language", "en")
            if not lang in params:
                continue
                
            parameters = params[lang]
            try:
                link = to_unicode(command["link"]).format(**parameters)
            except:
                print_exc()
                continue
                
            if link == "movies" and player.media == "movies":
                video = get_movie_from_library(parameters['imdb'])
                
                if video:
                    command_group_results.append(video)
            
            elif link == "tvshows" and player.media == "tvshows":
                video = get_episode_from_library(parameters['id'], parameters['season'], parameters['episode'])

                if not video:
                    video = get_episode_from_library(parameters['tmdb'], parameters['season'], parameters['episode'])

                if video:
                    command_group_results.append(video)
                    
            elif not command.get("steps"):
                command_group_results.append(
                    {
                        'label': player.title,
                        'path': urlencode_path(link),  # TODO: or replace(" ", "%20")?
                        'action': command.get("action", "RESOLVE")
                    }
                )
                
            else:
                steps = [to_unicode(step) for step in command["steps"]]
                files, dirs = lister.get(link, steps, parameters)
                if command.get("action", "RESOLVE") == "ACTIVATE":
                    files += dirs

                if files:
                    command_group_results += [
                        {
                            'label': f['label'],
                            'path': player.postprocess(f['path']),
                            'action': command.get("action", "RESOLVE")
                        } for f in files]
            
            if command_group_results:
                break

        results += command_group_results
        
    if results:
        return player.title, results
Ejemplo n.º 24
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'])},
        })
Ejemplo n.º 25
0
    def _has_match(item, pattern, parameters):
        # Match by season info label
        season_infolabel_match = False
        if item.get('season'):
            item_season = str(item.get('season'))
            param_season = str(parameters.get('season', ''))
            if item_season == param_season:
                season_infolabel_match = True
        if pattern == "{season}" and season_infolabel_match:
            return True
        
        # Match by episode info label
        episode_infolabel_match = False
        if item.get('episode'):
            item_episode = str(item.get('episode'))
            param_episode = str(parameters.get('episode', ''))
            if item_episode == param_episode:
                episode_infolabel_match = True
        if pattern == "{episode}" and episode_infolabel_match:
            return True
        
        # Match by season and episode info labels
        if pattern == "{season}x{episode}" and \
         season_infolabel_match and episode_infolabel_match:
            return True
                
        # Match by label
        label = item['label']
        pattern = to_unicode(pattern)
        # Custom $$ shortcut for unicode word boundary
        pattern = pattern.replace("$$", r"($|^|\s|\]|\[)")
                
        # Detect season number if searching for season 1
        #   to later allow first season to have no number
        first_season = False
        if '{season}' in pattern and '1' == str(parameters.get('season')):
            pattern = pattern.replace('{season}', '(?P<season>\d*)')
            first_season = True
            
        # Apply parameters to pattern
        pattern = apply_parameters(pattern, parameters)    
        
        # Remove special chars
        for c in IGNORE_CHARS:
            #pattern = pattern.replace("\\"+c, ' ')
            label = label.replace(c, ' ')

        # Make sure both label and pattern are unicode
        pattern = to_unicode(to_utf8(pattern))               
        label = to_unicode(to_utf8(label))
        
        plugin.log.debug("matching pattern {0} to label {1}".format(to_utf8(pattern), to_utf8(label)))
         
        # Test for a match
        r = re.compile(pattern, re.I|re.UNICODE)
        match = r.match(label)
        if ", The" in label and match is None:
            label = u"The " + label.replace(", The", "")
            match = r.match(label)
        
        # If full match
        if match is not None and match.end() == len(label):
            # Special handling of first season
            if first_season and not match.group('season') in ('1', '', '01', None):
                return False
            
            # Matched!
            plugin.log.debug("match: " + to_utf8(label))
            return True
            
        return False
Ejemplo n.º 26
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'])},
        })
Ejemplo n.º 27
0
    def _has_match(item, pattern, parameters):
        # Match by season info label
        season_infolabel_match = False
        if item.get('season'):
            item_season = str(item.get('season'))
            param_season = str(parameters.get('season', ''))
            if item_season == param_season:
                season_infolabel_match = True
        if pattern == "{season}" and season_infolabel_match:
            return True

        # Match by episode info label
        episode_infolabel_match = False
        if item.get('episode'):
            item_episode = str(item.get('episode'))
            param_episode = str(parameters.get('episode', ''))
            if item_episode == param_episode:
                episode_infolabel_match = True
        if pattern == "{episode}" and episode_infolabel_match:
            return True

        # Match by season and episode info labels
        if pattern == "{season}x{episode}" and \
         season_infolabel_match and episode_infolabel_match:
            return True

        # Match by label
        label = item['label']
        pattern = to_unicode(pattern)
        # Custom $$ shortcut for unicode word boundary
        pattern = pattern.replace("$$", r"($|^|\s|\]|\[)")

        # Detect season number if searching for season 1
        #   to later allow first season to have no number
        first_season = False
        if '{season}' in pattern and '1' == str(parameters.get('season')):
            pattern = pattern.replace('{season}', '(?P<season>\d*)')
            first_season = True

        # Apply parameters to pattern
        pattern = apply_parameters(pattern, parameters)

        # Remove special chars
        for c in IGNORE_CHARS:
            #pattern = pattern.replace("\\"+c, ' ')
            label = label.replace(c, ' ')

        # Make sure both label and pattern are unicode
        pattern = to_unicode(to_utf8(pattern))
        label = to_unicode(to_utf8(label))

        plugin.log.debug("matching pattern {0} to label {1}".format(
            to_utf8(pattern), to_utf8(label)))

        # Test for a match
        r = re.compile(pattern, re.I | re.UNICODE)
        match = r.match(label)
        if ", The" in label and match is None:
            label = u"The " + label.replace(", The", "")
            match = r.match(label)

        # If full match
        if match is not None and match.end() == len(label):
            # Special handling of first season
            if first_season and not match.group('season') in ('1', '', '01',
                                                              None):
                return False

            # Matched!
            plugin.log.debug("match: " + to_utf8(label))
            return True

        return False
Ejemplo n.º 28
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'])},
        })
Ejemplo n.º 29
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 active players
    players = active_players("tvshows", filters = {'network': show.get('network')})
    if not players:
        xbmc.executebuiltin( "Action(Info)")
        action_cancel()
        return

    # Get player 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:
            play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY)
    else:
        play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER)
        
    # Use just selected player if exists (selectors excluded)
    players = [p for p in players if p.id == play_plugin] or players

    # Get show ids from Trakt
    trakt_ids = get_trakt_ids("tvdb", id, show['seriesname'],
                    "show", show.get('year', 0))

    # Preload params
    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
        params[lang] = get_episode_parameters(tvdb_data, season, episode)
        params[lang].update(trakt_ids)
        params[lang]['info'] = show_info
        params[lang] = to_unicode(params[lang])

    # BETA
    action_cancel()

    # Get single video selection
    use_simple_selector = plugin.get_setting(SETTING_USE_SIMPLE_SELECTOR, converter=bool)
    selection = get_video_link(players, params, mode, use_simple_selector)
    if not selection:
        #action_cancel()
        return
        
    # Get selection details
    link = selection['path']
    action = selection.get('action', '')
    
    plugin.log.info('Playing url: %s' % link.encode('utf-8'))

    # Activate link
    if action == "ACTIVATE":
        action_activate(link)
    else:
        # Build list item (needed just for playback from widgets)
        season_info = get_season_metadata_tvdb(show_info, show[season], banners=False)
        episode_info = get_episode_metadata_tvdb(season_info, show[season][episode])
        listitem = {
            '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']},
        }
    
        # set properties
        if trakt_ids:
            set_property('script.trakt.ids', json.dumps(trakt_ids))
        set_property("data", json.dumps({'dbid': dbid, 'tvdb': id, 
            'season': season, 'episode': episode}))
        
        # Play
        if action == "PLAY":
            action_play(listitem)
        else:
            action_resolve(listitem)
Ejemplo n.º 30
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:
            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
        params[lang] = get_episode_parameters(tvdb_data, season, episode)
        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']
            },
        })
Ejemplo n.º 31
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']},
        })
Ejemplo n.º 32
0
 def prep_search_str(self, text):
     t_text = to_unicode(text)
     for chr in t_text:
         if ord(chr) >= 1488 and ord(chr) <= 1514:
             return to_utf8(text[::-1])
     return to_utf8(text)
Ejemplo n.º 33
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'])},
        })