Пример #1
0
def viewAnimeplusMenu(params):
    '''
    Directory for the Animeplus website.
    Represents http://www.animeplus.tv
    '''
    def _animeplusItem(view, color, title, route):
        item = xbmcgui.ListItem('[B][COLOR %s]%s[/COLOR][/B]' % (color, title))
        item.setInfo('video', {'title': title, 'plot': title})
        return (buildURL({
            'view': view,
            'api': requestHelper.API_ANIMEPLUS,
            'route': route
        }), item, True)

    cache.saveCacheIfDirty()

    listItems = (_animeplusItem('CATALOG_MENU', 'lavender', 'Latest Updates',
                                '/GetUpdates/'),
                 _animeplusItem('CATALOG_MENU', 'lightsalmon',
                                'New Anime Movies', '/GetNewMovies'),
                 _animeplusItem('CATALOG_MENU', 'lightsalmon',
                                'All Anime Movies', '/GetAllMovies'),
                 _animeplusItem('CATALOG_MENU', 'lightsalmon',
                                'Popular Anime Movies', '/GetPopularMovies'),
                 _animeplusItem('CATALOG_MENU', 'orange', 'New Subbed Anime',
                                '/GetNewShows'),
                 _animeplusItem('CATALOG_MENU', 'orange', 'All Subbed Anime',
                                '/GetAllShows'),
                 _animeplusItem('CATALOG_MENU', 'orange',
                                'Popular Subbed Anime', '/GetPopularShows'),
                 _animeplusItem('SEARCH_MENU', 'lavender', 'Search', ''))
    xbmcplugin.addDirectoryItems(int(sys.argv[1]), listItems)
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
Пример #2
0
def viewResolve(params):
    '''
    Resolves and plays the chosen episode, based on the API and ID supplied in 'params'.
    '''
    cache.saveCacheIfDirty(
    )  # Save the cache, only if necessary, before watching a video.

    stream = None

    if 'stream' in params:
        # BACKWARDS COMPATIBILITY: Toonmania2 0.4.4.
        # If the stream is already included in the parameters, no need to retrieve it in here again.
        stream = params['stream']
    elif 'providerURL' in params:
        stream = resolveProviderURL(params['providerURL'])
    else:
        providers = None
        if 'providers' in params:
            # Dictionary of providers and their **unresolved** URLs, used with autoplay off.
            from ast import literal_eval
            providers = literal_eval(params['providers'])
        else:
            providers = getEpisodeProviders(params['api'], params['episodeID'])

        if providers:
            if ADDON_SETTINGS['autoplay']:
                from random import choice
                randomKey = choice(tuple(providers.iterkeys()))
                stream = resolveProviderURL(providers[randomKey][0])
            else:
                index = xbmcgui.Dialog().select(
                    'Select Provider',
                    tuple(name for name in providers.iterkeys()))
                if index >= 0:
                    chosenKey = next(
                        key
                        for keyIndex, key in enumerate(providers.iterkeys())
                        if keyIndex == index)
                    stream = resolveProviderURL(providers[chosenKey][0])
                else:
                    # User cancelled the 'Select Provider' dialog.
                    xbmcplugin.setResolvedUrl(int(sys.argv[1]), False,
                                              xbmcgui.ListItem('None'))
                    return

    if stream:
        item = xbmcgui.ListItem(params['name'])
        setupListItem(item, params['showTitle'], params['name'], True,
                      int(params['season']), int(params['episode']),
                      params.get('genres', '').split(','),
                      params.get('thumb', ''), params['plot'],
                      params.get('date', ''))
        item.setPath(stream)
        xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
    else:
        logStreamError(params['api'], params['showTitle'], params['episodeID'])
        xbmcplugin.setResolvedUrl(int(sys.argv[1]), False,
                                  xbmcgui.ListItem('None'))
Пример #3
0
def viewMenu(params):
    '''
    Directory for the main add-on menu.
    '''
    cache.saveCacheIfDirty()

    listItems = (
        (buildURL({'view': 'ANIMETOON_MENU'}),
         xbmcgui.ListItem(
             '[B][COLOR orange]Cartoons & Dubbed Anime[/COLOR][/B]'), True),
        (buildURL({'view': 'ANIMEPLUS_MENU'}),
         xbmcgui.ListItem('[B][COLOR orange]Subbed Anime[/COLOR][/B]'), True),
        (buildURL({'view': 'SETTINGS'}),
         xbmcgui.ListItem('[B][COLOR lavender]Settings[/COLOR][/B]'), False))
    xbmcplugin.addDirectoryItems(int(sys.argv[1]), listItems)
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
Пример #4
0
def viewMenu(params):
    '''
    Directory for the main add-on menu.
    '''
    cache.saveCacheIfDirty()

    def _menuItem(view, title, isFolder):
        return (buildURL({'view': view}), xbmcgui.ListItem(title), isFolder)

    listItems = (_menuItem(
        'ANIMETOON_MENU',
        '[B][COLOR orange]Cartoons & Dubbed Anime[/COLOR][/B]', True),
                 _menuItem('ANIMEPLUS_MENU',
                           '[B][COLOR orange]Subbed Anime[/COLOR][/B]', True),
                 _menuItem('SETTINGS',
                           '[B][COLOR lavender]Settings[/COLOR][/B]', False))
    xbmcplugin.addDirectoryItems(int(sys.argv[1]), listItems)
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
Пример #5
0
def _viewSearchResults(params, text):
    '''
    Sub directory as an intermediary step before showing the search results catalog.
    This lets you favourite your search results so you can come back to them later.
    '''
    searchResults = tuple(catalogHelper.nameSearchEntries(
        params['api'], text))  # Does the actual web requests.
    if searchResults:

        cache.saveCacheIfDirty()

        # Use a comma-separated list of the result show\movie IDs as parameter.
        # See CatalogHelper.makeCatalogEntry() for info on catalog entry structure.
        searchIDs = ','.join(entryID for entryID in searchResults)

        # Go straight to the 'ALL' catalog section instead of the main catalog menu, because the name search
        # results are usually fewer so it's more convenient.
        # *** The API should be kept the same as the one used in the search. ***
        params.update({
            'view': 'CATALOG_SECTION',
            'section': 'ALL',
            'page': '0',
            'route': '_searchResults',
            'searchIDs': searchIDs
        })
        from string import capwords
        item = xbmcgui.ListItem('[COLOR orange][B]' + capwords(text) +
                                '[/COLOR][/B] Search Results')
        item.setArt({
            'icon': 'DefaultFolder.png',
            'thumb': 'DefaultFolder.png'
        })
        xbmcplugin.addDirectoryItem(int(sys.argv[1]), buildURL(params), item,
                                    True)
    else:
        xbmcplugin.addDirectoryItem(int(sys.argv[1]), '',
                                    xbmcgui.ListItem('No Items Found'), False)
    xbmcplugin.endOfDirectory(int(sys.argv[1]))

    # Use the same layout settings as the main catalog menu.
    useCatalogLayout, layoutType = ADDON_SETTINGS['layoutCatalog']
    if useCatalogLayout:
        xbmc.executebuiltin('Container.SetViewMode(' + layoutType + ')')
Пример #6
0
def _viewSearchResults(params, text):
    '''
    Sub directory as an intermediary step before showing the search results catalog.
    This lets you favourite your search results so you can come back to them later.
    '''
    searchData = requestHelper.nameSearchEntries(
        params['api'], text)  # Does the actual web requests.
    if searchData:
        # Make an item leading to the the 'ALL' catalog section instead of the main catalog menu, because
        # the name search results are usually fewer.
        params.update({
            'view': 'CATALOG_SECTION',
            'section': 'ALL',
            'page': '0',
            'route': '_searchResults',
            'searchData': repr(searchData)
        })

        # See if the user wants a favouritable search results item.
        if isSettingTrue('show_search_parent'):
            cache.saveCacheIfDirty()
            from string import capwords
            item = xbmcgui.ListItem('[COLOR orange][B]' + capwords(text) +
                                    '[/B][/COLOR] Search Results')
            item.setArt({
                'icon': 'DefaultFolder.png',
                'thumb': 'DefaultFolder.png'
            })
            xbmcplugin.addDirectoryItem(int(sys.argv[1]), buildURL(params),
                                        item, True)
        else:
            # Show the results right now.
            viewCatalogSection(params)
            return
    else:
        xbmcplugin.addDirectoryItem(int(sys.argv[1]), '',
                                    xbmcgui.ListItem('No Items Found'), False)
    xbmcplugin.endOfDirectory(int(sys.argv[1]))

    # Use the same layout settings as the main catalog menu.
    useCatalogLayout, layoutType = ADDON_SETTINGS['layoutCatalog']
    if useCatalogLayout:
        xbmc.executebuiltin('Container.SetViewMode(' + layoutType + ')')
Пример #7
0
def viewAnimetoonMenu(params):
    '''
    Directory for the Animetoon website.
    '''
    cache.saveCacheIfDirty()

    def _animetoonItem(view, color, title, route):
        item = xbmcgui.ListItem('[B][COLOR %s]%s[/COLOR][/B]' % (color, title))
        item.setInfo('video', {'title': title, 'plot': title})
        return (buildURL({
            'view': view,
            'api': requestHelper.API_ANIMETOON,
            'route': route
        }), item, True)

    listItems = (_animetoonItem('CATALOG_MENU', 'lavender', 'Latest Updates',
                                '/GetUpdates/'),
                 _animetoonItem('CATALOG_MENU', 'darkorange', 'New Movies',
                                '/GetNewMovies'),
                 _animetoonItem('CATALOG_MENU', 'darkorange', 'All Movies',
                                '/GetAllMovies'),
                 _animetoonItem('CATALOG_MENU', 'darkorange', 'Popular Movies',
                                '/GetPopularMovies'),
                 _animetoonItem('CATALOG_MENU', 'lightsalmon', 'New Cartoons',
                                '/GetNewCartoon'),
                 _animetoonItem('CATALOG_MENU', 'lightsalmon', 'All Cartoons',
                                '/GetAllCartoon'),
                 _animetoonItem('CATALOG_MENU', 'lightsalmon',
                                'Popular Cartoons', '/GetPopularCartoon'),
                 _animetoonItem('CATALOG_MENU', 'orange', 'New Dubbed Anime',
                                '/GetNewDubbed'),
                 _animetoonItem('CATALOG_MENU', 'orange', 'All Dubbed Anime',
                                '/GetAllDubbed'),
                 _animetoonItem('CATALOG_MENU', 'orange',
                                'Popular Dubbed Anime', '/GetPopularDubbed'),
                 _animetoonItem('SEARCH_MENU', 'lavender', 'Search', ''))
    xbmcplugin.addDirectoryItems(int(sys.argv[1]), listItems)
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
Пример #8
0
def viewCatalogSection(params):
    '''
    Directory for listing items from a specific section of the catalog
    (section "C" for example, for C-titled entries).
    '''
    xbmcplugin.setContent(int(sys.argv[1]), 'tvshows')

    cache.saveCacheIfDirty()

    catalog = catalogHelper.getCatalog(params)

    def _catalogSectionItems(iterable):
        api = params['api']

        if ADDON_SETTINGS['showThumbs']:
            requestHelper.setAPISource(
                api
            )  # Sets the right base thumb URL for the makeThumbURL() below.

        for entry in iterable:
            # entry = (id, name, description, genres, dateReleased), see CatalogHelper.makeCatalogEntry() for more info.
            item = xbmcgui.ListItem(entry[1])
            thumb = requestHelper.makeThumbURL(
                entry[0]) if ADDON_SETTINGS['showThumbs'] else ''
            date = entry[4] if entry[4] else ''
            setupListItem(item,
                          entry[1],
                          entry[1],
                          False,
                          0,
                          0,
                          entry[3],
                          thumb=thumb,
                          plot=entry[2],
                          date=date)
            yield (buildURL({
                'view': 'LIST_EPISODES',
                'api': api,
                'id': entry[0],
                'genres': ','.join(entry[3]) if entry[3] else '',
                'thumb': thumb,
                'plot': entry[2],
                'date': date
            }), item, True)

    sectionKey = params['section']

    if ADDON_SETTINGS['showThumbs']:
        # Display items in pages so the thumbs are loaded in chunks to not overburden the source website.

        page = int(params['page'])  # Zero-based index.
        pageSize = ADDON_SETTINGS['pageSize']
        start = page * pageSize
        stop = start + pageSize

        if sectionKey == 'ALL':
            # Create pages for the pseudo-section "ALL":
            # Flatten all sections into an iterable, which is then islice'd to get the current directory page.
            flatSections = chain.from_iterable(
                catalog[sectionKey]
                for sectionKey in sorted(catalog.iterkeys()))
            itemsIterable = (entry
                             for entry in islice(flatSections, start, stop))
            totalSectionPages = int(
                ceil(
                    sum(len(section) for section in catalog.itervalues()) /
                    float(pageSize)))
        else:
            # Do an islice of a specific section.
            itemsIterable = (
                entry for entry in islice(catalog[sectionKey], start, stop))
            totalSectionPages = int(
                ceil(len(catalog[sectionKey]) /
                     float(pageSize)))  # The 'float' is for Python 2.

        page += 1
        if totalSectionPages > 1 and page < totalSectionPages:
            params.update({'page': str(page)})
            nextPage = (buildURL(params),
                        xbmcgui.ListItem('Next Page (' + str(page + 1) + '/' +
                                         str(totalSectionPages) + ')'), True)
            xbmcplugin.addDirectoryItems(
                int(sys.argv[1]),
                tuple(_catalogSectionItems(itemsIterable)) + (nextPage, ))
        else:
            xbmcplugin.addSortMethod(int(sys.argv[1]),
                                     xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
            xbmcplugin.addDirectoryItems(
                int(sys.argv[1]), tuple(_catalogSectionItems(itemsIterable)))
    else:
        if sectionKey == 'ALL':
            itemsIterable = (entry for entry in chain.from_iterable(
                catalog[sectionKey]
                for sectionKey in sorted(catalog.iterkeys())))
        else:
            itemsIterable = (entry for entry in catalog[sectionKey])
        xbmcplugin.addSortMethod(int(sys.argv[1]),
                                 xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
        xbmcplugin.addDirectoryItems(
            int(sys.argv[1]), tuple(_catalogSectionItems(itemsIterable)))

    xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=False)

    # Custom layout.
    useShowsLayout, layoutType = ADDON_SETTINGS['layoutShows']
    if useShowsLayout:
        xbmc.executebuiltin('Container.SetViewMode(' + layoutType + ')')