Exemplo n.º 1
0
def index():
    try:
        providers_count = len(PROVIDERS['movie'])
        if not providers_count > 0:
            raise AnErrorOccurred(30315)

        if providers_count == 1:
            sys_kwargs = _get_kwargs()[1]
            item = call_provider(PROVIDERS['movie'][0]).catalogs(**sys_kwargs)
            plugin.redirect(
                plugin.url_for(
                    item.pop('endpoint'),
                    **_build_kwargs(item.pop("kwargs", {}), sys_kwargs,
                                    **{'provider': PROVIDERS['movie'][0]})))
        # If we have more end one provider we createt a provider index
        else:
            sys_kwargs = _get_kwargs()[1]
            for provider in PROVIDERS['movie']:
                item = call_provider(provider).catalogs(**sys_kwargs)
                item["path"] = plugin.url_for(
                    item.pop('endpoint'),
                    **_build_kwargs(item.pop("kwargs", {}), sys_kwargs,
                                    **{'provider': provider}))
                yield item
    except AnErrorOccurred as e:
        errorNotify(e.errno)
    except:
        errorNotify(30308)
Exemplo n.º 2
0
def search():
    try:
        query = plugin.keyboard("", __addon__.getLocalizedString(30001))
        if query:
            plugin.redirect(plugin.url_for("search_query", **_get_kwargs({'query': query, 'page': 1})[0]))
    except:
        errorNotify(30308)
Exemplo n.º 3
0
def catalogs():
    try:
        kwargs, sys_kwargs = _get_kwargs()
        for item in call_provider(sys_kwargs['provider']).catalogs(**kwargs):
            item["path"] = plugin.url_for(item.pop('endpoint'), **_build_kwargs(item.pop("kwargs", {}), sys_kwargs))
            yield item
    except:
        errorNotify(30308)
Exemplo n.º 4
0
def catalogs():
    try:
        kwargs, sys_kwargs = _get_kwargs()
        for item in call_provider(sys_kwargs['provider']).catalogs(**kwargs):
            item["path"] = plugin.url_for(
                item.pop('endpoint'),
                **_build_kwargs(item.pop("kwargs", {}), sys_kwargs))
            yield item
    except:
        errorNotify(30308)
Exemplo n.º 5
0
def index():
    try:
        providers_count = len(PROVIDERS['movie'])
        if not providers_count > 0:
            raise AnErrorOccurred(30315)

        if providers_count == 1:
            sys_kwargs = _get_kwargs()[1]
            item = call_provider(PROVIDERS['movie'][0]).catalogs(**sys_kwargs)
            plugin.redirect(plugin.url_for(item.pop('endpoint'), **_build_kwargs(item.pop("kwargs", {}), sys_kwargs, **{'provider': PROVIDERS['movie'][0]})))
        # If we have more end one provider we createt a provider index
        else:
            sys_kwargs = _get_kwargs()[1]
            for provider in PROVIDERS['movie']:
                item = call_provider(provider).catalogs(**sys_kwargs)
                item["path"] = plugin.url_for(item.pop('endpoint'), **_build_kwargs(item.pop("kwargs", {}), sys_kwargs, **{'provider': provider}))
                yield item
    except AnErrorOccurred as e:
        errorNotify(e.errno)
    except:
        errorNotify(30308)
Exemplo n.º 6
0
def search():
    try:
        query = plugin.keyboard("", __addon__.getLocalizedString(30001))
        if query:
            plugin.redirect(
                plugin.url_for("search_query",
                               **_get_kwargs({
                                   'query': query,
                                   'page': 1
                               })[0]))
    except:
        errorNotify(30308)
Exemplo n.º 7
0
def browse(provider, separate, page):
    try:
        page = int(page)
        kwargs = _get_kwargs()[0]
        mediaprovider = call_provider(provider)

        with closing(SafeDialogProgress(delay_close=0)) as dialog:
            dialog.create(__addon__.getAddonInfo('name'))
            # Update progress
            dialog.update(0, line1=__addon__.getLocalizedString(30007))

            # Setting content type
            plugin.set_content(mediaprovider.provides)

            # Getting items
            result = None
            with conFutures.ThreadPoolExecutor(max_workers=1) as pool:
                future = pool.submit(mediaprovider.browse, *(separate, page), **kwargs)
                while not future.done():
                    if xbmc.abortRequested or dialog.iscanceled():
                        pool.shutdown(wait=False)
                        return
                    xbmc.sleep(100)
                result = future.result()

            if not result:
                raise AnErrorOccurred(30305)
            items = result.pop('items', [])
            if not items:
                raise AnErrorOccurred(30307)
            itemsCount = len(items)

            # Build status
            status = {
                'jobs': (itemsCount+1)*2,
                'done': 1
            }

            # Update progress
            dialog.update(int(status['done']*100/status['jobs']), line1=__addon__.getLocalizedString(30018))

            # Getting meta data and subtitles
            def on_status_update(future):
                data = future.result()
                status['done'] = status['done']+1
                if not data:
                    dialog.update(int(status['done']*100/status['jobs']))
                if data.get('stream_info', {}).get('subtitle', {}).get('language', None):
                    dialog.update(int(status['done']*100/status['jobs']), line1=data["label"], line2=u'{lang} subtitle'.format(lang=data['stream_info']['subtitle']['language']))
                else:
                    dialog.update(int(status['done']*100/status['jobs']), line1=data["label"], line2='Metadata')

            futures = []
            providers = {'metadata': call_provider(PROVIDERS['meta_tmdb']), 'subtitles': call_provider(PROVIDERS['subtitle_yify'])}
            refresh = _isSettingsChanged()
            with conFutures.ThreadPoolExecutor(max_workers=2) as pool:
                for item in items:
                    futures.append(pool.submit(_shelf_mediainfo, *('metadata', item, providers['metadata'], refresh,)))
                    futures.append(pool.submit(_shelf_mediainfo, *('subtitles', item, providers['subtitles'], refresh,)))
                [future.add_done_callback(on_status_update) for future in futures]
                while not all(future.done() for future in futures):
                    if xbmc.abortRequested or dialog.iscanceled():
                        pool.shutdown(wait=False)
                        return
                    xbmc.sleep(100)

            # Build item
            mediainfo = map(lambda i: i.result(), futures)
            for i in xrange(itemsCount):
                # Update item with mediainfo
                items[i].update(mediainfo[i*2]) # Metadata
                items[i].update(mediainfo[i*2+1]) # Subtitle

                # Set video width and hight
                width = 1920
                height = 1080
                if not items[i]['torrents'].get('1080p', None):
                    width = 1280
                    height = 720
                items[i].setdefault("stream_info", {}).setdefault("video", {}).update({"width": width, "height": height})
                
                # Create player url
                play_kwargs = {
                    'torrents': items[i].pop('torrents'),
                    'subtitle': items[i].pop('subtitle', None),
                    'item': items[i]
                }
                items[i]["path"] = plugin.url_for('play', **play_kwargs)

                # The item is now playable
                items[i]["is_playable"] = True

            # Add next page, but we stop at page 20... yes 20 pages sounds all right
            if page < int(result.get("pages", 1)) and page < 21:
                plugin.log.debug('(Main) page: '+str(page))
                items.append({
                    "label": '>> '+__addon__.getLocalizedString(30009),
                    "path": plugin.url_for('browse', **_build_kwargs(kwargs, {'provider':provider,'separate':separate,'page':page+1}))
                })

            # Update progress
            dialog.update(100, line1=__addon__.getLocalizedString(30017), line2=' ')

            return items

    except AnErrorOccurred as e:
        errorNotify(e.errno)
    except:
        errorNotify(30308)
    return
Exemplo n.º 8
0
def browse(provider, separate, page):
    try:
        page = int(page)
        kwargs = _get_kwargs()[0]
        mediaprovider = call_provider(provider)

        with closing(SafeDialogProgress(delay_close=0)) as dialog:
            dialog.create(__addon__.getAddonInfo('name'))
            # Update progress
            dialog.update(0, line1=__addon__.getLocalizedString(30007))

            # Setting content type
            plugin.set_content(mediaprovider.provides)

            # Getting items
            result = None
            with conFutures.ThreadPoolExecutor(max_workers=1) as pool:
                future = pool.submit(mediaprovider.browse, *(separate, page),
                                     **kwargs)
                while not future.done():
                    if xbmc.abortRequested or dialog.iscanceled():
                        pool.shutdown(wait=False)
                        return
                    xbmc.sleep(100)
                result = future.result()

            if not result:
                raise AnErrorOccurred(30305)
            items = result.pop('items', [])
            if not items:
                raise AnErrorOccurred(30307)
            itemsCount = len(items)

            # Build status
            status = {'jobs': (itemsCount + 1) * 2, 'done': 1}

            # Update progress
            dialog.update(int(status['done'] * 100 / status['jobs']),
                          line1=__addon__.getLocalizedString(30018))

            # Getting meta data and subtitles
            def on_status_update(future):
                data = future.result()
                status['done'] = status['done'] + 1
                if not data:
                    dialog.update(int(status['done'] * 100 / status['jobs']))
                if data.get('stream_info', {}).get('subtitle',
                                                   {}).get('language', None):
                    dialog.update(
                        int(status['done'] * 100 / status['jobs']),
                        line1=data["label"],
                        line2=u'{lang} subtitle'.format(
                            lang=data['stream_info']['subtitle']['language']))
                else:
                    dialog.update(int(status['done'] * 100 / status['jobs']),
                                  line1=data["label"],
                                  line2='Metadata')

            futures = []
            providers = {
                'metadata': call_provider(PROVIDERS['meta_tmdb']),
                'subtitles': call_provider(PROVIDERS['subtitle_yify'])
            }
            refresh = _isSettingsChanged()
            with conFutures.ThreadPoolExecutor(max_workers=2) as pool:
                for item in items:
                    futures.append(
                        pool.submit(
                            _shelf_mediainfo,
                            *(
                                'metadata',
                                item,
                                providers['metadata'],
                                refresh,
                            )))
                    futures.append(
                        pool.submit(
                            _shelf_mediainfo,
                            *(
                                'subtitles',
                                item,
                                providers['subtitles'],
                                refresh,
                            )))
                [
                    future.add_done_callback(on_status_update)
                    for future in futures
                ]
                while not all(future.done() for future in futures):
                    if xbmc.abortRequested or dialog.iscanceled():
                        pool.shutdown(wait=False)
                        return
                    xbmc.sleep(100)

            # Build item
            mediainfo = map(lambda i: i.result(), futures)
            for i in xrange(itemsCount):
                # Update item with mediainfo
                items[i].update(mediainfo[i * 2])  # Metadata
                items[i].update(mediainfo[i * 2 + 1])  # Subtitle

                # Set video width and hight
                width = 1920
                height = 1080
                if not items[i]['torrents'].get('1080p', None):
                    width = 1280
                    height = 720
                items[i].setdefault("stream_info", {}).setdefault("video",
                                                                  {}).update({
                                                                      "width":
                                                                      width,
                                                                      "height":
                                                                      height
                                                                  })

                # Create player url
                play_kwargs = {
                    'torrents': items[i].pop('torrents'),
                    'subtitle': items[i].pop('subtitle', None),
                    'item': items[i]
                }
                items[i]["path"] = plugin.url_for('play', **play_kwargs)

                # The item is now playable
                items[i]["is_playable"] = True

            # Add next page, but we stop at page 20... yes 20 pages sounds all right
            if page < int(result.get("pages", 1)) and page < 21:
                plugin.log.debug('(Main) page: ' + str(page))
                items.append({
                    "label":
                    '>> ' + __addon__.getLocalizedString(30009),
                    "path":
                    plugin.url_for(
                        'browse',
                        **_build_kwargs(
                            kwargs, {
                                'provider': provider,
                                'separate': separate,
                                'page': page + 1
                            }))
                })

            # Update progress
            dialog.update(100,
                          line1=__addon__.getLocalizedString(30017),
                          line2=' ')

            return items

    except AnErrorOccurred as e:
        errorNotify(e.errno)
    except:
        errorNotify(30308)
    return