示例#1
0
def PlayVideo(type, url, id, indirect=None):
    oc = ObjectContainer()

    movie_id = re.match('http://www.netflix.com/Movie/.+/(?P<id>[0-9]+)',
                        url).groupdict()['id']
    player_url = 'http://www.netflix.com/WiPlayer?movieid=%s' % movie_id
    user_url = "http://api-public.netflix.com/users/%s" % US_Account.GetUserId(
    )

    params = {'movieid': movie_id, 'user': user_url}
    video_url = US_Account.GetAPIURL(player_url, params=params)

    # If the &resume=true parameter was specified, ensure that it's copied to the final webkit URL
    if url.endswith('&resume=true'):
        video_url = video_url + '&resume=true'
    Log("Final WebKit URL: " + video_url)

    oc.add(
        VideoClipObject(key=Callback(Lookup, type=type, id=id),
                        rating_key=id,
                        items=[
                            MediaObject(
                                parts=[PartObject(key=WebVideoURL(video_url))],
                                protocol='webkit')
                        ]))

    return oc
示例#2
0
def MainMenu():

    # Attempt to log in
    logged_in = US_Account.LoggedIn()
    if not logged_in:
        logged_in = US_Account.TryLogIn()

    oc = ObjectContainer(no_cache=True)

    if logged_in:

        oc.add(DirectoryObject(key=Callback(UserList), title='TV & Movies'))
        oc.add(
            DirectoryObject(key=Callback(
                MenuItem,
                url='http://api-public.netflix.com/users/%s/queues/instant' %
                US_Account.GetUserId(),
                title='Instant Queue',
                is_queue=True),
                            title='Instant Queue'))
        oc.add(
            InputDirectoryObject(key=Callback(Search),
                                 title='Search',
                                 prompt='Search for a Movie or TV Show...'))

    oc.add(PrefsObject(title='Preferences'))

    return oc
示例#3
0
def SetRating(key, rating):

    # The provided rating will be a value between 0 and 10. However, Netflix expects an interger
    # between 1 and 5. Therefore, we must translate...
    netflix_rating = int(rating / 2)
    US_Account.SetTitleRating(key, netflix_rating)
    pass
示例#4
0
def RemoveFromQueue(url):
    if US_Account.RemoveFromQueue(url):
        return ObjectContainer(header='Instant Queue',
                               message='The item was removed from your queue.')
    else:
        return ObjectContainer(
            header='Instant Queue',
            message='There was a problem removing your item from the queue.')
示例#5
0
def UserList():

    oc = ObjectContainer()

    user_id = US_Account.GetUserId()
    user_list_url = US_Account.GetAPIURL(
        'http://api-public.netflix.com/users/%s/lists' % user_id,
        params={
            'v': '2',
            'client': 'plex'
        })
    user_list = XML.ElementFromURL(user_list_url)

    # Add the found items
    for item in user_list.xpath('//lists/list/link'):
        url = item.get('href')
        title = item.get('title')
        oc.add(
            DirectoryObject(key=Callback(MenuItem, url=url, title=title),
                            title=title))

    return oc
示例#6
0
def MainMenu():

    # Attempt to log in
    logged_in = US_Account.LoggedIn()
    if not logged_in:
        logged_in = US_Account.TryLogIn()

    oc = ObjectContainer(no_cache=True)

    if logged_in:

        oc.add(DirectoryObject(key=Callback(UserList), title='TV & Movies'))
        oc.add(
            DirectoryObject(key=Callback(
                MenuItem,
                url='http://api-public.netflix.com/users/%s/queues/instant' %
                US_Account.GetUserId(),
                title='Instant Queue',
                is_queue=True),
                            title='Instant Queue'))
        oc.add(
            InputDirectoryObject(key=Callback(Search),
                                 title='Search',
                                 prompt='Search for a Movie or TV Show...'))

    else:

        # The user has not yet provided valid credentials. Therefore, we should allow them to be redirected
        # to sign up for a free trial.
        if Client.Platform in ('MacOSX', 'Windows'):
            oc.add(
                DirectoryObject(key=Callback(FreeTrial),
                                title='Sign up for free trial'))

    oc.add(PrefsObject(title='Preferences'))

    return oc
示例#7
0
def Lookup(type, id):
    oc = ObjectContainer()

    # Separate out the specified parameters from the original URL
    params = {}
    if id.find('?') > -1:
        original_params = String.ParseQueryString(id[id.find('?') + 1:])
        for key, value in original_params.items():
            params[key] = value[0]

    # Add the additional parameters to ensure that we get all of the required items expaned.
    params[
        'expand'] = '@title,@box_art,@synopsis,@directors,@seasons,@episodes'
    item_url = US_Account.GetAPIURL(id, params=params)
    item = XML.ElementFromURL(item_url)

    item_details = ParseCatalogueItem(item)
    video_url = PlaybackURL(item_details['url'], Prefs['playbackpreference'])

    if type == "Movie":
        oc.add(
            MovieObject(
                key=Callback(Lookup, type=type, id=id),
                rating_key=id,
                items=[
                    MediaObject(parts=[
                        PartObject(key=Callback(
                            PlayVideo, type=type, url=video_url, id=id))
                    ],
                                protocol='webkit')
                ],
                title=item_details['title'],
                thumb=item_details['thumb'][0],
                summary=item_details['summary'],
                genres=item_details['genres'],
                directors=item_details['directors'],
                duration=item_details['duration'],
                rating=item_details['rating'],
                content_rating=item_details['content_rating']))
    else:
        oc.add(
            EpisodeObject(
                key=Callback(Lookup, type=type, id=id),
                rating_key=id,
                items=[
                    MediaObject(parts=[
                        PartObject(key=Callback(
                            PlayVideo, type=type, url=video_url, id=id))
                    ],
                                protocol='webkit')
                ],
                title=item_details['title'],
                show=item_details['show'],
                season=item_details['season_index'],
                index=item_details['episode_index'],
                thumb=item_details['thumb'][0],
                summary=item_details['summary'],
                directors=item_details['directors'],
                duration=item_details['duration'],
                rating=item_details['rating'],
                content_rating=item_details['content_rating']))

    return oc
示例#8
0
def MenuItem(url,
             title,
             start_index=0,
             max_results=50,
             content=ContainerContent.Mixed,
             is_queue=False):
    oc = ObjectContainer(title2=title, content=content)

    # Separate out the specified parameters from the original URL
    params = {}
    if url.find('?') > -1:
        original_params = String.ParseQueryString(url[url.find('?') + 1:])
        for key, value in original_params.items():
            params[key] = value[0]

    # Add the paging parameters
    params['start_index'] = str(start_index)
    params['max_results'] = str(max_results)

    # Add the additional parameters to ensure that we get all of the required items expaned.
    params[
        'expand'] = '@title,@box_art,@synopsis,@directors,@seasons,@episodes'
    menu_item_url = US_Account.GetAPIURL(url, params=params)
    menu_item = XML.ElementFromURL(menu_item_url)

    show_url = None

    for item in menu_item.xpath('//catalog_title'):

        item_details = ParseCatalogueItem(item)

        # Movies
        if MOVIE_PATTERN.match(item_details['id']):

            if Prefs['playbackpreference'] != "Ask":
                video_url = PlaybackURL(item_details['url'],
                                        Prefs['playbackpreference'])
                oc.add(
                    MovieObject(
                        key=Callback(Lookup,
                                     type="Movie",
                                     id=item_details['id']),
                        items=[
                            MediaObject(parts=[
                                PartObject(key=Callback(PlayVideo,
                                                        type="Movie",
                                                        url=video_url,
                                                        id=item_details['id']))
                            ],
                                        protocol='webkit')
                        ],
                        rating_key=item_details['id'],
                        title=item_details['title'],
                        thumb=item_details['thumb'][0],
                        summary=item_details['summary'],
                        genres=item_details['genres'],
                        directors=item_details['directors'],
                        duration=item_details['duration'],
                        rating=item_details['rating'],
                        content_rating=item_details['content_rating']))
            else:
                oc.add(
                    DirectoryObject(key=Callback(
                        PlaybackSelection,
                        url=item_details['url'],
                        title=item_details['title'],
                        type="Movie",
                        id=item_details['id'],
                        thumb=item_details['thumb'][0],
                        summary=item_details['summary'],
                        directors=item_details['directors'],
                        duration=item_details['duration'],
                        rating=item_details['rating'],
                        content_rating=item_details['content_rating'],
                        genres=item_details['genres'],
                        is_queue=is_queue),
                                    title=item_details['title'],
                                    thumb=item_details['thumb'][0],
                                    summary=item_details['summary'],
                                    duration=item_details['duration']))

        # TV Shows
        elif TVSHOW_PATTERN.match(item_details['id']):
            oc.add(
                TVShowObject(key=Callback(MenuItem,
                                          url=item_details['episode_url'],
                                          title=item_details['title'],
                                          content=ContainerContent.Seasons,
                                          is_queue=is_queue),
                             rating_key=item_details['id'],
                             title=item_details['title'],
                             thumb=item_details['thumb'][0],
                             summary=item_details['summary'],
                             genres=item_details['genres'],
                             duration=item_details['duration'],
                             rating=item_details['rating'],
                             content_rating=item_details['content_rating']))

        # TV Show Seasons
        elif SEASON_PATTERN.match(item_details['id']):
            oc.add(
                SeasonObject(key=Callback(MenuItem,
                                          url=item_details['episode_url'],
                                          title=item_details['title'],
                                          content=ContainerContent.Episodes),
                             rating_key=item_details['id'],
                             title=item_details['title'],
                             thumb=item_details['thumb'][0],
                             summary=item_details['summary'],
                             episode_count=item_details['episode_count']))

        # TV Episodes
        elif EPISODE_PATTERN.match(item_details['id']):
            show_url = url

            if Prefs['playbackpreference'] != "Ask":
                video_url = PlaybackURL(item_details['url'],
                                        Prefs['playbackpreference'])
                oc.add(
                    EpisodeObject(
                        key=Callback(Lookup,
                                     type="Episode",
                                     id=item_details['id']),
                        items=[
                            MediaObject(parts=[
                                PartObject(key=Callback(PlayVideo,
                                                        type="Episode",
                                                        url=video_url,
                                                        id=item_details['id']))
                            ],
                                        protocol='webkit')
                        ],
                        rating_key=item_details['id'],
                        title=item_details['title'],
                        show=item_details['show'],
                        season=item_details['season_index'],
                        index=item_details['episode_index'],
                        thumb=item_details['thumb'][0],
                        summary=item_details['summary'],
                        directors=item_details['directors'],
                        duration=item_details['duration'],
                        rating=item_details['rating'],
                        content_rating=item_details['content_rating']))
            else:
                oc.add(
                    DirectoryObject(key=Callback(
                        PlaybackSelection,
                        url=item_details['url'],
                        title=item_details['title'],
                        type="Episode",
                        id=item_details['id'],
                        thumb=item_details['thumb'][0],
                        summary=item_details['summary'],
                        directors=item_details['directors'],
                        duration=item_details['duration'],
                        rating=item_details['rating'],
                        content_rating=item_details['content_rating'],
                        show=item_details['show'],
                        season=item_details['season_index'],
                        index=item_details['episode_index']),
                                    title=item_details['title'],
                                    thumb=item_details['thumb'][0],
                                    summary=item_details['summary'],
                                    duration=item_details['duration']))

    # Provide a way to remove a show from the Instant Queue.
    if Prefs['playbackpreference'] == "Ask" and is_queue and show_url:
        oc.add(
            DirectoryObject(
                key=Callback(RemoveFromQueue, url=show_url),
                title="Remove",
                summary="Remove this show from your Instant Queue."))

    # If there are further results, add an item to allow them to be browsed.
    start_index = int(start_index)
    max_results = int(max_results)
    number_of_results_node = menu_item.xpath('//number_of_results/text()')
    if len(number_of_results_node) > 0:
        number_of_results = int(number_of_results_node[0])
        if number_of_results > (start_index + max_results):
            oc.add(
                DirectoryObject(key=Callback(MenuItem,
                                             url=url,
                                             title=title,
                                             start_index=start_index +
                                             max_results,
                                             max_results=max_results),
                                title="Next..."))

    # Check to see if we have any results
    if len(oc) == 0:
        return ObjectContainer(header='No Results',
                               message='No results were found')

    return oc