Exemplo n.º 1
0
def root():
    xbmcplugin.addDirectoryItem(router.handle,
                                router.build_url(authenticate_trakt),
                                xbmcgui.ListItem('Authenticate Trakt'))
    xbmcplugin.addDirectoryItem(router.handle, router.build_url(refresh_liked),
                                xbmcgui.ListItem('Refresh Liked'))
    xbmcplugin.addDirectoryItem(router.handle, router.build_url(open_list_dir),
                                xbmcgui.ListItem('Open Lists'))
    xbmcplugin.endOfDirectory(router.handle)
Exemplo n.º 2
0
def root():
    xbmcplugin.addDirectoryItem(router.handle, router.build_url(movies.root),
                                xbmcgui.ListItem('Movies'), True)
    xbmcplugin.addDirectoryItem(router.handle, router.build_url(tv.root),
                                xbmcgui.ListItem('TV Shows'), True)
    if TRAKT_AUTHED:
        xbmcplugin.addDirectoryItem(router.handle,
                                    router.build_url(movies.trakt_personal),
                                    xbmcgui.ListItem('My Movies'), True)
        xbmcplugin.addDirectoryItem(router.handle,
                                    router.build_url(tv.trakt_personal),
                                    xbmcgui.ListItem('My TV Shows'), True)
    xbmcplugin.endOfDirectory(router.handle)
Exemplo n.º 3
0
def root():
    library.add_sources()
    xbmcplugin.setContent(router.handle, 'files')
    xbmcplugin.addDirectoryItem(router.handle, router.build_url(movies.root),
                                xbmcgui.ListItem('Movies'), True)
    xbmcplugin.addDirectoryItem(router.handle, router.build_url(tv.root),
                                xbmcgui.ListItem('TV Shows'), True)
    if TRAKT_AUTHED:
        xbmcplugin.addDirectoryItem(router.handle,
                                    router.build_url(movies.trakt_personal),
                                    xbmcgui.ListItem('My Movies'), True)
        xbmcplugin.addDirectoryItem(router.handle,
                                    router.build_url(tv.trakt_personal),
                                    xbmcgui.ListItem('My TV Shows'), True)
    xbmcplugin.endOfDirectory(router.handle)
Exemplo n.º 4
0
def debrid_downloads():
    user_debrid = user_debrids[0]
    torrents = user_debrid.downloads()
    downloading = []
    downloaded = []
    for cached, name, url in torrents:
        if cached:
            # Premiumize DL list is direct link
            if not isinstance(user_debrid, debrid.Premiumize):
                url = router.build_url(debrid_resolve, link=url, _debrid=0)
            downloaded.append(('[COLOR green]' + name + '[/COLOR]', url))
        else:
            downloading.append(('[COLOR red]' + name + '[/COLOR]', ''))
    ui.directory_view(downloading, more=True)
    ui.directory_view(downloaded, videos=True)
Exemplo n.º 5
0
def root(mode=None,
         scraper=None,
         query=None,
         season=None,
         episode=None,
         **kwargs):
    """Business logic. `movie` and `tv` are from external plugins."""

    # Set up scraper
    selected_scraper = scraper or router.addon.getSetting('scraper')
    cached_settings = get_json_cache(selected_scraper)
    scraper = getattr(scrapers, selected_scraper)()
    for attr in scraper.cache_attrs:
        if attr in cached_settings:
            setattr(scraper, attr, cached_settings[attr])
    if isinstance(scraper, scrapers.TorrentApi):
        find_magnets = functools.partial(scraper.find_magnets,
                                         **user_torrentapi_settings())
    else:
        find_magnets = scraper.find_magnets

    # Show root plugin directory
    searches = get_json_cache('searches').get('history', list())
    if mode is None:
        names_urls = []
        names_urls.append(('Downloads', router.build_url(debrid_downloads)))
        names_urls.append(('List', router.build_url(root, mode='list')))
        ui.directory_view(names_urls, folders=True, more=True)
        names_urls = []
        names_urls.append(('Search', router.build_url(root, mode='search')))
        names_urls.append(
            ('Search History (Select to clear)', router.build_url(delhistory)))
        ui.directory_view(names_urls, folders=False, more=True)
        names_urls = []
        for search in searches:
            names_urls.append(
                (search, router.build_url(root, mode='search', query=search)))
        ui.directory_view(names_urls, folders=True, cache=False)
        return

    # Scraping
    fn_filter = None
    if mode == 'search':
        if not query:
            query = ui.get_user_input()
            if not query:
                return
            url = router.build_url(root, mode='search', query=query)
            xbmc.executebuiltin('Container.Update({})'.format(url))
            return
        names_magnets = find_magnets(query=query)
        try:
            searches.remove(query)
        except ValueError:
            pass
        searches.insert(0, query)
        write_json_cache('searches', {'history': searches})
    if mode == 'list':
        names_magnets = find_magnets()
    if mode == 'movie':
        names_magnets = find_magnets(movie=True, **kwargs)
    if mode == 'tv':
        season = int(season)
        episode = int(episode)
        for query in episode_search_strings(season, episode):
            names_magnets = list(find_magnets(tv=True, query=query, **kwargs))
            if names_magnets:
                break
        else:
            # Do something to say nothing found TV specific
            pass
        fn_filter = episode_file_filter(season, episode)
    # Save anything cachable for future runs (e.g. tokens, cookies, etc.)
    write_json_cache(
        scraper.__class__.__name__,
        {attr: getattr(scraper, attr)
         for attr in scraper.cache_attrs})

    # Providing
    if not names_magnets:
        ui.notify('No results found')
        router.fail()
        return
    names, magnets = zip(*names_magnets)
    names = list(names)
    magnets = list(magnets)
    cached = [(False, False)] * len(magnets)
    for debrid_idx, user_debrid in enumerate(user_debrids):
        to_check = [(idx, magnets[idx]) for idx, cache in enumerate(cached)
                    if not cache[1]]
        if not to_check:
            break
        caches = user_debrid.check_availability(zip(*to_check)[1],
                                                fn_filter=fn_filter)
        for (idx, _), cache in zip(to_check, caches):
            if cache:
                cached[idx] = (debrid_idx, cache)
    cached_names_magnets = []
    uncached_names_magnets = []
    for name, magnet, (debrid_idx, cache) in zip(names, magnets, cached):
        if cache:
            cached_names_magnets.append(('[COLOR green]' + name + '[/COLOR]',
                                         magnet, cache, debrid_idx))
        else:
            uncached_names_magnets.append(
                ('[COLOR red]' + name + '[/COLOR]', magnet, cache, 0))
    if router.addon.getSettingBool('show_cached_only'):
        uncached_names_magnets = []

    # Display results
    if mode in ('movie', 'tv'):
        all_names_magnets = cached_names_magnets + uncached_names_magnets
        media_url = ''
        if all_names_magnets:
            selected = None
            if router.addon.getSettingBool(
                    'auto_select') and cached_names_magnets:
                for idx, name in enumerate(zip(*cached_names_magnets)[0]):
                    if '.hdr.' in name.lower():
                        selected = idx
                        break
                    if '.2160p.' in name.lower():
                        selected = idx
                        break
                    if '.1080p.' in name.lower():
                        selected = idx
                        break
                    if '.720p.' in name.lower():
                        selected = idx
                        break
                else:
                    selected = 0
            if selected is None:
                selected = ui.dialog_select(zip(*all_names_magnets)[0])
            if selected >= 0:
                _, magnet, cache, i = all_names_magnets[selected]
                user_debrid = user_debrids[i]
                if cache:
                    if isinstance(user_debrid, debrid.RealDebrid):
                        _fn_filter = cache
                    else:
                        _fn_filter = fn_filter
                    media_url = user_debrid.resolve_url(magnet,
                                                        fn_filter=_fn_filter)
                else:
                    ui.add_torrent(user_debrid, magnet, fn_filter=fn_filter)
        li = xbmcgui.ListItem(path=media_url)
        xbmcplugin.setResolvedUrl(router.handle, bool(media_url), li)
        xbmcgui.Window(10000).setProperty('foxymeta.nativeplay', 'True')
    if mode in ['list', 'search']:
        names_urls = [(name,
                       router.build_url(debrid_resolve,
                                        magnet=magnet,
                                        cache=cache,
                                        _debrid=i),
                       [('Add to cloud', 'RunPlugin({})'.format(
                           router.build_url(get_torrent, magnet=magnet)))])
                      for name, magnet, cache, i in cached_names_magnets]
        ui.directory_view(names_urls, videos=True, more=True, contexts=True)
        names_urls = [(name, router.build_url(get_torrent, magnet=magnet))
                      for name, magnet, cache, i in uncached_names_magnets]
        ui.directory_view(names_urls)