Пример #1
0
def list_channels(cat=None):
    list_items = []
    for channel in channel_list.get("eY2hhbm5lbHNfbGlzdA=="):
        if channel.get("cat_id") == cat:
            if (len([
                    stream for stream in channel.get("Qc3RyZWFtX2xpc3Q=")
                    if stream.get("AdG9rZW4=", "0") in new_channels.implemented
            ]) == 0):
                continue

            title = new_channels.custom_base64(channel.get("ZY19uYW1l"))
            icon = new_channels.custom_base64(channel.get("abG9nb191cmw=")[1:])
            image = "{0}|{1}".format(icon,
                                     urlencode({"User-Agent": user_agent}))
            c_id = channel.get("rY19pZA==")

            li = ListItem(title, offscreen=True)
            li.setProperty("IsPlayable", "true")
            li.setInfo(type="Video",
                       infoLabels={
                           "Title": title,
                           "mediatype": "video"
                       })
            li.setArt({"thumb": image, "icon": image})
            li.setContentLookup(False)
            url = plugin.url_for(play, c_id=c_id)
            list_items.append((url, li, False))

    xbmcplugin.addDirectoryItems(plugin.handle, list_items)
    xbmcplugin.setContent(plugin.handle, "videos")
    xbmcplugin.endOfDirectory(plugin.handle)
Пример #2
0
def process_directories(context, url, tree=None):
    LOG.debug('Processing secondary menus')

    content_type = 'files'
    if '/collection' in url:
        content_type = 'sets'

    xbmcplugin.setContent(get_handle(), content_type)

    server = context.plex_network.get_server_from_url(url)

    items = []
    append_item = items.append
    if PY3:
        directories = tree.iter('Directory')
    else:
        directories = tree.getiterator('Directory')

    for directory in directories:
        item = Item(server, url, tree, directory)
        append_item(create_directory_item(context, item))

    if items:
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(),
                              cacheToDisc=context.settings.cache_directory())
Пример #3
0
def process_albums(context, url, tree=None):
    xbmcplugin.setContent(get_handle(), 'albums')

    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_UNSORTED)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_ALBUM_IGNORE_THE)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_ARTIST_IGNORE_THE)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_LASTPLAYED)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_VIDEO_YEAR)

    # Get the URL and server name.  Get the XML and parse
    tree = get_xml(context, url, tree)
    if tree is None:
        return

    server = context.plex_network.get_server_from_url(url)

    items = []
    append_item = items.append
    albums = tree.getiterator('Directory')
    for album in albums:
        item = Item(server, url, tree, album)
        append_item(create_album_item(context, item))

    if items:
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(), cacheToDisc=context.settings.cache_directory())
Пример #4
0
def _list_content(context, server, url):
    tree = server.processed_xml(url)
    if tree is None:
        return

    items = []
    append_item = items.append

    if PY3:
        branches = tree.iter('Video')
    else:
        branches = tree.getiterator('Video')

    if not branches:
        if PY3:
            branches = tree.iter('Directory')
        else:
            branches = tree.getiterator('Directory')

    for content in branches:
        item = Item(server, url, tree, content)
        if content.get('type') == 'show':
            append_item(create_show_item(context, item, library=True))
        elif content.get('type') == 'movie':
            append_item(create_movie_item(context, item, library=True))

    if items:
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))
Пример #5
0
def run(context):
    context.plex_network = plex.Plex(context.settings, load=True)

    section_type = get_section_type(context)
    all_sections = context.plex_network.all_sections()

    content_type = None
    items = []

    LOG.debug('Using list of %s sections: %s' %
              (len(all_sections), all_sections))

    for section in all_sections:

        if section.get_type() == section_type:
            if content_type is None:
                content_type = get_content_type(section)

            items += _list_content(
                context,
                context.plex_network.get_server_from_uuid(
                    section.get_server_uuid()), section.get_path())

    if items:
        add_sort_methods(content_type)
        xbmcplugin.setContent(get_handle(), content_type)
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(), cacheToDisc=False)
Пример #6
0
def process_plex_plugins(context, url, tree=None):
    """
        Main function to parse plugin XML from PMS
        Will create dir or item links depending on what the
        main tag is.
        @input: plugin page URL
        @return: nothing, creates Kodi GUI listing
    """
    xbmcplugin.setContent(get_handle(), 'files')

    server = context.plex_network.get_server_from_url(url)
    tree = get_xml(context, url, tree)
    if tree is None:
        return

    if (tree.get('identifier') !=
            'com.plexapp.plugins.myplex') and ('node.plexapp.com' in url):
        LOG.debug('This is a myPlex URL, attempting to locate master server')
        server = get_master_server(context)

    items = []
    append_item = items.append
    plugins = tree.getiterator()
    for plugin in plugins:
        item = Item(server, tree, url, plugin)
        item = create_plex_plugin_item(context, item)
        if item:
            append_item(item)

    if items:
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(),
                              cacheToDisc=context.settings.cache_directory())
Пример #7
0
def process_music(context, url, tree=None):
    server = context.plex_network.get_server_from_url(url)

    tree = get_xml(context, url, tree)
    if tree is None:
        return

    items = []
    append_item = items.append
    if PY3:
        branches = tree.iter()
    else:
        branches = tree.getiterator()

    for music in branches:

        if music.get('key') is None:
            continue

        item = Item(server, url, tree, music)
        append_item(create_music_item(context, item))

    if items:
        content_type = items[-1][1].getProperty('content_type')
        if not content_type:
            content_type = 'artists'
        xbmcplugin.setContent(get_handle(), content_type)

        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(),
                              cacheToDisc=context.settings.cache_directory())
Пример #8
0
def vod():
    if current_time - vod_data_time > cache_time * 60 * 60:
        new_channels.get_api_key()
        vod_data = new_channels.get_vod_list()
        with io.open(vod_list_file, "w", encoding="utf-8") as f:
            f.write(
                json.dumps(vod_data,
                           indent=2,
                           sort_keys=True,
                           ensure_ascii=False))
        addon.setSetting("vod_data_time36", str(int(time.time())))
    else:
        with io.open(vod_list_file, "r", encoding="utf-8") as f:
            vod_data = json.loads(f.read())

    categories = vod_data.get("categories_list")
    list_items = []

    for c in categories:
        li = ListItem(c.get("cat_name"), offscreen=True)
        url = plugin.url_for(vod_list, cat=c.get("cat_id"))
        list_items.append((url, li, True))

    xbmcplugin.addDirectoryItems(plugin.handle, list_items)
    xbmcplugin.endOfDirectory(plugin.handle)
def run(context, url):
    context.plex_network = plex.Plex(context.settings, load=True)
    content_type = url.split('/')[2]
    LOG.debug('Displaying entries for %s' % content_type)
    servers = context.plex_network.get_server_list()
    servers_list = len(servers)

    items = []
    append_item = items.append
    # For each of the servers we have identified
    for media_server in servers:

        if media_server.is_secondary():
            continue

        details = {'title': media_server.get_name()}
        extra_data = {}
        url = None

        if content_type == 'video':
            extra_data['mode'] = MODES.PLEXPLUGINS
            url = media_server.join_url(media_server.get_url_location(),
                                        'video')
            if servers_list == 1:
                process_plex_plugins(context, url)
                return

        elif content_type == 'online':
            extra_data['mode'] = MODES.PLEXONLINE
            url = media_server.join_url(media_server.get_url_location(),
                                        'system/plexonline')
            if servers_list == 1:
                process_plex_online(context, url)
                return

        elif content_type == 'music':
            extra_data['mode'] = MODES.MUSIC
            url = media_server.join_url(media_server.get_url_location(),
                                        'music')
            if servers_list == 1:
                process_music(context, url)
                return

        elif content_type == 'photo':
            extra_data['mode'] = MODES.PHOTOS
            url = media_server.join_url(media_server.get_url_location(),
                                        'photos')
            if servers_list == 1:
                process_photos(context, url)
                return

        if url:
            gui_item = GUIItem(url, details, extra_data)
            append_item(create_gui_item(context, gui_item))

    if items:
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(),
                              cacheToDisc=context.settings.cache_directory())
Пример #10
0
def process_shows(context, url, tree=None):
    xbmcplugin.setContent(get_handle(), 'tvshows')

    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_UNSORTED)
    xbmcplugin.addSortMethod(
        get_handle(), xbmcplugin.SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_DATE)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_VIDEO_RATING)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_VIDEO_YEAR)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_MPAA_RATING)

    # Get the URL and server name.  Get the XML and parse
    tree = get_xml(context, url, tree)
    if tree is None:
        return

    server = context.plex_network.get_server_from_url(url)

    items = []
    append_item = items.append
    # For each directory tag we find
    if PY3:
        shows = tree.iter('Directory')
    else:
        shows = tree.getiterator('Directory')

    for show in shows:
        item = Item(server, url, tree, show)
        append_item(create_show_item(context, item))

    if items:
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(),
                              cacheToDisc=context.settings.cache_directory())
def list_channels(cat_id):
    list_items = []
    try:
        for channel in TV.get_category(cat_id):
            title = channel.title
            image = xbmc_curl_encode((channel.thumbnail, {
                "User-Agent": "okhttp/3.12.1"
            }))
            li = ListItem(title, offscreen=True)
            li.setProperty("IsPlayable", "true")
            li.setArt({"thumb": image, "icon": image})
            li.setInfo(type="Video",
                       infoLabels={
                           "Title": title,
                           "mediatype": "video"
                       })
            url = plugin.url_for(play,
                                 cat_id=channel.c_id,
                                 channel_id=channel._id)
            list_items.append((url, li, False))
        xbmcplugin.addDirectoryItems(plugin.handle, list_items)
        xbmcplugin.setContent(plugin.handle, "videos")
        xbmcplugin.endOfDirectory(plugin.handle)
    except (ValueError, RequestException) as e:
        """ No data """
        log(e.message)
        dialog = xbmcgui.Dialog()
        dialog.notification(plugin.name, "Remote Server Error",
                            xbmcgui.NOTIFICATION_ERROR)
        xbmcplugin.endOfDirectory(plugin.handle, False)
def process_plex_online(context, url):
    xbmcplugin.setContent(get_handle(), 'files')

    server = context.plex_network.get_server_from_url(url)

    tree = get_xml(context, url)
    if tree is None:
        return

    items = []
    append_item = items.append
    if PY3:
        plugins = tree.iter()
    else:
        plugins = tree.getiterator()

    for plugin in plugins:
        item = Item(server, url, tree, plugin)
        item = create_plex_online_item(context, item)
        if item:
            append_item(item)

    if items:
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(), cacheToDisc=context.settings.cache_directory())
Пример #13
0
def process_artists(context, url, tree=None):
    """
        Process artist XML and display data
        @input: url of XML page, or existing tree of XML page
        @return: nothing
    """
    xbmcplugin.setContent(get_handle(), 'artists')

    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_UNSORTED)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_ARTIST_IGNORE_THE)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_LASTPLAYED)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_VIDEO_YEAR)

    # Get the URL and server name.  Get the XML and parse
    tree = get_xml(context, url, tree)
    if tree is None:
        return

    server = context.plex_network.get_server_from_url(url)

    items = []
    append_item = items.append
    if PY3:
        artists = tree.iter('Directory')
    else:
        artists = tree.getiterator('Directory')

    for artist in artists:
        item = Item(server, url, tree, artist)
        append_item(create_artist_item(context, item))

    if items:
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(), cacheToDisc=context.settings.cache_directory())
def list_live():
    live_data = mytv.get_live_events()
    list_items = []
    for day, events in live_data.items():
        for event in events:
            if len(event["channel_list"]) == 0:
                continue
            event_time = time_from_zone(
                datetime.utcfromtimestamp(int(event["start"])).strftime("%c"),
                "%Y-%m-%d %H:%M")
            title = "[{0}] {1}".format(event_time, event["title"])
            li = ListItem(title, offscreen=True)
            li.setProperty("IsPlayable", "true")
            li.setInfo(type="Video",
                       infoLabels={
                           "Title": title,
                           "mediatype": "video"
                       })
            url = plugin.url_for(event_resolve,
                                 title=event["title"].encode("utf-8"))
            list_items.append((url, li, False))

    xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL)
    xbmcplugin.addDirectoryItems(plugin.handle, list_items)
    xbmcplugin.setContent(plugin.handle, "videos")
    xbmcplugin.endOfDirectory(plugin.handle)
Пример #15
0
def list_channels(cat=None):
    playback_mode = addon.getSetting("playback_mode")
    names = []
    list_items = []
    for channel in TV.get_channels_by_category(cat, cache_time):
        title = channel.name
        if title in names:
            continue
        else:
            names.append(title)
        image = channel.img
        li = ListItem(title)
        li.setProperty("IsPlayable", "true")
        li.setArt({"thumb": image, "icon": image})
        li.setInfo(type="Video", infoLabels={"Title": title, "mediatype": "video"})
        li.setContentLookup(False)
        if playback_mode == "HLS":
            url = plugin.url_for(play, cat=cat, channel_id=channel._id)
        elif playback_mode == "RTMFP":
            url = plugin.url_for(play_rtmfp, cat=cat, channel_id=channel._id)
            fallback_url = plugin.url_for(play_netgroup, cat=cat, channel_id=channel._id)
            li.addContextMenuItems([("Play RTMFP Netgroup (P2P)", "PlayMedia({0})".format(fallback_url))])
        else:
            url = plugin.url_for(play_netgroup, cat=cat, channel_id=channel._id)
            fallback_url = plugin.url_for(play_rtmfp, cat=cat, channel_id=channel._id)
            li.addContextMenuItems([("Play RTMFP", "PlayMedia({0})".format(fallback_url))])
        list_items.append((url, li, False))
    xbmcplugin.addDirectoryItems(plugin.handle, list_items)
    xbmcplugin.setContent(plugin.handle, "videos")
    xbmcplugin.endOfDirectory(plugin.handle)
def root():
    list_items = []
    for item in RB.get_categories():
        li = ListItem(item.title)
        url = plugin.url_for(list_channels, cat=item.category_id)
        list_items.append((url, li, True))
    xbmcplugin.addDirectoryItems(plugin.handle, list_items)
    xbmcplugin.endOfDirectory(plugin.handle)
Пример #17
0
def root():
    list_items = []
    for cat in TV.get_categories():
        li = ListItem(cat.cat_name, offscreen=True)
        url = plugin.url_for(list_channels, cat_id=cat.cat_id)
        list_items.append((url, li, True))
    xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL)
    xbmcplugin.addDirectoryItems(plugin.handle, list_items)
    xbmcplugin.endOfDirectory(plugin.handle)
Пример #18
0
def process_tracks(context, url, tree=None):
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_UNSORTED)
    xbmcplugin.addSortMethod(get_handle(),
                             xbmcplugin.SORT_METHOD_TITLE_IGNORE_THE)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_DURATION)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_SONG_RATING)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_TRACKNUM)

    tree = get_xml(context, url, tree)
    if tree is None:
        return

    playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
    playlist.clear()

    server = context.plex_network.get_server_from_url(url)

    content_counter = {
        'photo': 0,
        'track': 0,
        'video': 0,
    }
    items = []
    append_item = items.append
    if PY3:
        branches = tree.iter()
    else:
        branches = tree.getiterator()

    for branch in branches:
        tag = branch.tag.lower()
        item = Item(server, url, tree, branch)
        if tag == 'track':
            append_item(create_track_item(context, item))
        elif tag == 'photo':  # mixed content audio playlist
            append_item(create_photo_item(context, item))
        elif tag == 'video':  # mixed content audio playlist
            append_item(create_movie_item(context, item))

        if isinstance(content_counter.get(tag), int):
            content_counter[tag] += 1

    if items:
        content_type = 'songs'
        if context.settings.mixed_content_type() == 'majority':
            majority = max(content_counter, key=content_counter.get)
            if majority == 'photo':
                content_type = 'images'
            elif majority == 'video':
                content_type = 'movies'

        xbmcplugin.setContent(get_handle(), content_type)
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(),
                              cacheToDisc=context.settings.cache_directory())
Пример #19
0
def process_movies(context, url, tree=None):
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_UNSORTED)
    xbmcplugin.addSortMethod(
        get_handle(), xbmcplugin.SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_DATEADDED)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_DATE)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_VIDEO_RATING)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_VIDEO_YEAR)
    xbmcplugin.addSortMethod(get_handle(),
                             xbmcplugin.SORT_METHOD_VIDEO_RUNTIME)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_MPAA_RATING)

    # get the server name from the URL, which was passed via the on screen listing..

    server = context.plex_network.get_server_from_url(url)

    tree = get_xml(context, url, tree)
    if tree is None:
        return

    content_counter = {
        'photo': 0,
        'track': 0,
        'video': 0,
    }
    # Find all the video tags, as they contain the data we need to link to a file.
    start_time = time.time()
    items = []
    append_item = items.append
    branches = tree.getiterator()
    for branch in branches:
        item = Item(server, url, tree, branch)
        if branch.tag.lower() == 'video':
            append_item(create_movie_item(context, item))
        elif branch.tag.lower() == 'track':  # mixed content video playlist
            append_item(create_track_item(context, item))
        elif branch.tag.lower() == 'photo':  # mixed content video playlist
            append_item(create_photo_item(context, item))

    if items:
        content_type = 'movies'
        if context.settings.mixed_content_type() == 'majority':
            majority = max(content_counter, key=content_counter.get)
            if majority == 'photo':
                content_type = 'images'
            elif majority == 'track':
                content_type = 'songs'

        xbmcplugin.setContent(get_handle(), content_type)
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    LOG.debug('PROCESS: It took %s seconds to process %s items' %
              (time.time() - start_time, len(items)))

    xbmcplugin.endOfDirectory(get_handle(),
                              cacheToDisc=context.settings.cache_directory())
def run(context, url):
    context.plex_network = plex.Plex(context.settings, load=True)
    server = context.plex_network.get_server_from_url(url)

    tree = get_xml(context, url)
    if tree is None:
        return

    items = []
    append_item = items.append
    if PY3:
        directories = tree.iter('Directory')
    else:
        directories = tree.getiterator('Directory')

    for channels in directories:

        if channels.get('local', '') == '0' or channels.get('size',
                                                            '0') == '0':
            continue

        extra_data = {
            'fanart_image': get_fanart_image(context, server, channels),
            'thumb': get_thumb_image(context, server, channels)
        }

        details = {'title': channels.get('title', i18n('Unknown'))}

        suffix = channels.get('key').split('/')[1]

        if channels.get('unique', '') == '0':
            details['title'] = '%s (%s)' % (details['title'], suffix)

        # Alter data sent into get_link_url, as channels use path rather than key
        path_data = {
            'key': channels.get('key'),
            'identifier': channels.get('key')
        }
        p_url = get_link_url(server, url, path_data)

        extra_data['mode'] = MODES.GETCONTENT
        if suffix == 'photos':
            extra_data['mode'] = MODES.PHOTOS
        elif suffix == 'video':
            extra_data['mode'] = MODES.PLEXPLUGINS
        elif suffix == 'music':
            extra_data['mode'] = MODES.MUSIC

        gui_item = GUIItem(p_url, details, extra_data)
        append_item(create_gui_item(context, gui_item))

    if items:
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(),
                              cacheToDisc=context.settings.cache_directory())
Пример #21
0
def vod():
    mytv.update_vod_channels()
    list_items = []
    for category in mytv.get_vod_categories():
        li = ListItem(category.cat_name, offscreen=True)
        url = plugin.url_for(vod_list, cat=category.cat_id)
        list_items.append((url, li, True))

    xbmcplugin.addDirectoryItems(plugin.handle, list_items)
    xbmcplugin.endOfDirectory(plugin.handle)
Пример #22
0
def root():
    categories = ["channels", "news", "shows", "movies", "sports", "music"]
    list_items = []
    for c in categories:
        li = ListItem(c)
        url = plugin.url_for(list_channels, cat=c)
        list_items.append((url, li, True))

    xbmcplugin.addDirectoryItems(plugin.handle, list_items)
    xbmcplugin.endOfDirectory(plugin.handle)
Пример #23
0
def run(context, content_filter=None, display_shared=False):
    context.plex_network = plex.Plex(context.settings, load=True)
    xbmcplugin.setContent(get_handle(), 'files')

    server_list = context.plex_network.get_server_list()
    LOG.debug('Using list of %s servers: %s' % (len(server_list), server_list))

    items = []
    append_item = items.append

    menus = context.settings.show_menus()

    server_section_menus, playlist_section_menus = \
        server_section_menus_items(context, server_list, content_filter, display_shared, menus)

    if server_section_menus:
        items += combined_sections_item(context)

    items += server_section_menus

    if display_shared:
        if items:
            xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

        xbmcplugin.endOfDirectory(get_handle(),
                                  cacheToDisc=context.settings.cache_directory())
        return

    if menus.get('playlists') and context.plex_network.is_myplex_signedin():
        items += playlist_section_menus

    if menus.get('composite_playlist') and context.plex_network.is_myplex_signedin():
        items += composite_playlist_item(context)

    # For each of the servers we have identified
    if menus.get('queue') and context.plex_network.is_myplex_signedin():
        details = {
            'title': i18n('myPlex Queue')
        }
        extra_data = {
            'type': 'Folder',
            'mode': MODES.MYPLEXQUEUE
        }
        gui_item = GUIItem('http://myplexqueue', details, extra_data)
        append_item(create_gui_item(context, gui_item))

    items += server_additional_menu_items(context, server_list, content_filter, menus)
    items += action_menu_items(context)

    if items:
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(), cacheToDisc=context.settings.cache_directory())
def root():
    list_items = []
    for cat in TV.get_categories():
        image = xbmc_curl_encode((cat.c_image, {
            "User-Agent": "okhttp/3.12.1"
        }))
        li = ListItem(cat.c_name, offscreen=True)
        li.setArt({"thumb": image, "icon": image})
        url = plugin.url_for(list_channels, cat_id=cat.c_id)
        list_items.append((url, li, True))
    xbmcplugin.addDirectoryItems(plugin.handle, list_items)
    xbmcplugin.endOfDirectory(plugin.handle)
def run(context):
    context.plex_network = plex.Plex(context.settings, load=True)
    xbmcplugin.setContent(get_handle(), 'files')

    server_list = context.plex_network.get_server_list()
    LOG.debug('Using list of %s servers: %s' % (len(server_list), server_list))

    items = get_menu_items(context)

    if items:
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(),
                              cacheToDisc=context.settings.cache_directory())
def process_seasons(context, url, rating_key=None, library=False):
    xbmcplugin.setContent(get_handle(), 'seasons')

    if not url.startswith(('http', 'file')) and rating_key:
        # Get URL, XML and parse
        server = context.plex_network.get_server_from_uuid(url)
        url = server.join_url(server.get_url_location(),
                              'library/metadata/%s/children' % str(rating_key))
    else:
        server = context.plex_network.get_server_from_url(url)

    tree = get_xml(context, url)
    if tree is None:
        return

    will_flatten = False
    if context.settings.flatten_seasons() == '1':
        # check for a single season
        if int(tree.get('size', 0)) == 1:
            LOG.debug('Flattening single season show')
            will_flatten = True

    all_season_disabled = context.settings.all_season_disabled()

    items = []
    append_item = items.append
    # For all the directory tags
    if PY3:
        seasons = tree.iter('Directory')
    else:
        seasons = tree.getiterator('Directory')

    for season in seasons:

        if will_flatten:
            url = server.join_url(server.get_url_location(), season.get('key'))
            process_episodes(context, url)
            return

        if all_season_disabled and season.get('index') is None:
            continue

        item = Item(server, url, tree, season)
        append_item(create_season_item(context, item, library=library))

    if items:
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(),
                              cacheToDisc=context.settings.cache_directory())
Пример #27
0
def process_photos(context, url, tree=None):
    server = context.plex_network.get_server_from_url(url)

    tree = get_xml(context, url, tree)
    if tree is None:
        return

    content_counter = {
        'photo': 0,
        'track': 0,
        'video': 0,
    }
    items = []
    append_item = items.append

    if PY3:
        branches = tree.iter()
    else:
        branches = tree.getiterator()

    for branch in branches:
        item = Item(server, url, tree, branch)
        tag = branch.tag.lower()
        if tag == 'photo':
            append_item(create_photo_item(context, item))
        elif tag == 'directory':
            append_item(create_directory_item(context, item))
        elif tag == 'track':  # mixed content photo playlist
            append_item(create_track_item(context, item))
        elif tag == 'video':  # mixed content photo playlist
            append_item(create_movie_item(context, item))

        if isinstance(content_counter.get(tag), int):
            content_counter[tag] += 1

    if items:
        content_type = 'images'
        if context.settings.mixed_content_type() == 'majority':
            majority = max(content_counter, key=content_counter.get)
            if majority == 'track':
                content_type = 'songs'
            elif majority == 'video':
                content_type = 'movies'

        xbmcplugin.setContent(get_handle(), content_type)
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(),
                              cacheToDisc=context.settings.cache_directory())
Пример #28
0
def process_episodes(context, url, tree=None, rating_key=None, library=False):
    xbmcplugin.setContent(get_handle(), 'episodes')

    if not url.startswith(('http', 'file')) and rating_key:
        # Get URL, XML and parse
        server = context.plex_network.get_server_from_uuid(url)
        url = server.join_url(server.get_url_location(),
                              'library/metadata/%s/children' % str(rating_key))
    else:
        server = context.plex_network.get_server_from_url(url)

    tree = get_xml(context, url, tree)
    if tree is None:
        return

    if tree.get('mixedParents') == '1' or context.settings.episode_sort_method(
    ) == 'plex':
        xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_UNSORTED)
    else:
        xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_EPISODE)
        xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_UNSORTED)

    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_DATE)
    xbmcplugin.addSortMethod(
        get_handle(), xbmcplugin.SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_DATEADDED)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_VIDEO_RATING)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_VIDEO_YEAR)
    xbmcplugin.addSortMethod(get_handle(),
                             xbmcplugin.SORT_METHOD_VIDEO_RUNTIME)
    xbmcplugin.addSortMethod(get_handle(), xbmcplugin.SORT_METHOD_MPAA_RATING)

    items = []
    append_item = items.append
    if PY3:
        episodes = tree.iter('Video')
    else:
        episodes = tree.getiterator('Video')

    for episode in episodes:
        item = Item(server, url, tree, episode)
        append_item(create_episode_item(context, item, library=library))

    if items:
        xbmcplugin.addDirectoryItems(get_handle(), items, len(items))

    xbmcplugin.endOfDirectory(get_handle(),
                              cacheToDisc=context.settings.cache_directory())
Пример #29
0
def run(context):
    context.plex_network = plex.Plex(context.settings, load=True)

    params = context.params
    for param in ['video_type']:  # check for expected parameters
        if param not in params:
            return

    if not params.get('query'):
        params['query'] = _get_search_query()
    params['query'] = _quote(params['query'])

    context.params = params

    succeeded = False
    search_results = search(context)
    log_results = list(map(lambda x: decode_utf8(ETree.tostring(x[1])), search_results))
    LOG.debug('Found search results: %s' % '\n\n'.join(log_results))

    if search_results:
        LOG.debug('Found a server with the requested content %s' % params['query'])

        items = []
        append_item = items.append
        url = ''

        for server_uuid, tree, search_result in search_results:
            server = context.plex_network.get_server_from_uuid(server_uuid)
            if context.params.get('video_type') == 'movie':
                item = Item(server, url, tree, search_result)
                append_item(create_movie_item(context, item))

            elif context.params.get('video_type') == 'episode':
                item = Item(server, url, tree, search_result)
                append_item(create_episode_item(context, item))

        if items:
            xbmcplugin.addDirectoryItems(get_handle(), items, len(items))
            succeeded = True
            if context.params.get('video_type') == 'movie':
                xbmcplugin.setContent(get_handle(), 'movies')
            elif context.params.get('video_type') == 'episode':
                xbmcplugin.setContent(get_handle(), 'episodes')
    else:
        LOG.debug('Content not found on any server')

    xbmcplugin.endOfDirectory(get_handle(), succeeded=succeeded,
                              cacheToDisc=context.settings.cache_directory())
Пример #30
0
def list_channels(cat=None):
    mytv.update_live_channels()
    image_headers = {"User-Agent": mytv.user_agent}
    list_items = []
    for channel in mytv.get_live_channels_by_category(int(cat)):
        li = ListItem(channel.name, offscreen=True)
        image = xbmc_curl_encode((channel.image_path, image_headers))
        li.setProperty("IsPlayable", "true")
        li.setInfo(type="Video", infoLabels={"Title": channel.name, "mediatype": "video"})
        li.setArt({"thumb": image, "icon": image})
        url = plugin.url_for(play, c_id=channel.channel_id)
        list_items.append((url, li, False))

    xbmcplugin.addDirectoryItems(plugin.handle, list_items)
    xbmcplugin.setContent(plugin.handle, "videos")
    xbmcplugin.endOfDirectory(plugin.handle)