Example #1
0
def play():
    try:
        kwargs = dict((k, v[0]) for k, v in plugin.request.args.items())

        play3d = False
        if kwargs['torrents'].get('3D') and int(
                __addon__.getSetting("play3d")) > 0:
            play3d = True
            if __addon__.getSetting("play3d") == '1':
                play3d = xbmcgui.Dialog().yesno(
                    heading=__addon__.getLocalizedString(30010),
                    line1=__addon__.getLocalizedString(30011))

        if play3d:
            url = from_meta_data(kwargs['torrents']['3D'], "quality 3D")
        elif kwargs['torrents'].get('1080p'):
            url = from_meta_data(kwargs['torrents']['1080p'], "quality 1080p")
        else:
            url = from_meta_data(kwargs['torrents']['720p'], "quality 720p")

        subtitle_provider = None
        if kwargs['subtitle']:
            subtitle_provider = call_provider(PROVIDERS['subtitle_yify'])

        Player().play(url, kwargs["item"], kwargs['subtitle'],
                      subtitle_provider)

    except Error as e:
        torrentError(e)
    except AnErrorOccurred as e:
        errorNotify(e.errno)
    except:
        errorNotify(30308)
Example #2
0
def play():
    try:
        kwargs = dict((k, v[0]) for k, v in plugin.request.args.items())

        play3d = False
        if kwargs['torrents'].get('3D') and int(__addon__.getSetting("play3d")) > 0:
            play3d = True
            if __addon__.getSetting("play3d") == '1':
                play3d = xbmcgui.Dialog().yesno(heading=__addon__.getLocalizedString(30010), line1=__addon__.getLocalizedString(30011))

        if play3d:
            url = from_meta_data(kwargs['torrents']['3D'], "quality 3D")
        elif kwargs['torrents'].get('1080p'):
            url = from_meta_data(kwargs['torrents']['1080p'], "quality 1080p")
        else:
            url = from_meta_data(kwargs['torrents']['720p'], "quality 720p")

        subtitle_provider = None
        if kwargs['subtitle']:
            subtitle_provider = call_provider(PROVIDERS['subtitle_yify'])

        Player().play(url, kwargs["item"], kwargs['subtitle'], subtitle_provider)

    except Error as e:
        torrentError(e)
    except AnErrorOccurred as e:
        errorNotify(e.errno)
    except:
        errorNotify(30308)
Example #3
0
def browse(provider, item, page):
    try:
        kwargs, sys_kwargs = _filter_kwargs()
        content = 'movies'
        items = []
        with closing(SafeDialogProgress(delay_close=0)) as dialog:
            dialog.create(plugin.name)
            dialog.update(percent=0,
                          line1=plugin.addon.getLocalizedString(30007))

            movies = sys_kwargs['module'].browse(item, page, **kwargs)

            jobs = len(movies) * 2 + 1
            done = 1
            dialog.update(percent=int(done * 100 / jobs),
                          line2=plugin.addon.getLocalizedString(30007))

            def on_future_done(future):
                done = done + 1
                data = future.result()
                dialog.update(percent=int(done * 100 / jobs),
                              line2="{prefix}{label}".format(
                                  prefix=data.get('kodipopcorn_subtitle', ''),
                                  label=data.get("label", '')))

            subtitle = import_module(PROVIDERS['subtitle.yify'])
            meta = import_module(PROVIDERS['meta.tmdb'])
            with futures.ThreadPoolExecutor(max_workers=2) as pool:
                subtitle_list = [
                    pool.submit(
                        subtitle.get, id=item.get(
                            "info",
                            {}).get("code")).add_done_callback(on_future_done)
                    for item in movies
                ]
                meta_list = [
                    pool.submit(meta.get, id=item.get(
                        "info",
                        {}).get("code")).add_done_callback(on_future_done)
                    for item in movies
                ]
                while not all(future.done()
                              for future in subtitle_list) and not all(
                                  future.done() for future in meta_list):
                    if dialog.iscanceled():
                        return
                    xbmc.sleep(100)

            subtitles = map(lambda future: future.result(), subtitle_list)
            metadata = map(lambda future: future.result(), meta_list)
            for i, movie in enumerate(movies):
                # Update the movie with subtitle and meta data
                movie.update(subtitles[i])
                movie.update(metadata[i])

                # Catcher content type and remove it from movie
                # NOTE: This is not the best way to dynamic set the content type, since the content type can not be set for each movie
                if movie.get("kodipopcorn_content"):
                    content = movie.pop('kodipopcorn_content')

                # Catcher quality, build magnet label and remove quality from movie
                quality = fQuality = ''
                if movie.get("kodipopcorn_quality"):
                    quality = movie.pop('kodipopcorn_quality')
                    fQuality = " [{quality}]".format(quality=quality)

                # Build magnet label
                fYear = ''
                if movie.get("year"):
                    fYear = " ({year})".format(year=movie["year"])

                # Builds targets for the player
                kwargs = {}
                if movie.get("kodipopcorn_subtitle"):
                    kwargs['subtitle'] = movie.pop('kodipopcorn_subtitle')
                kwargs.update({
                    'url':
                    from_meta_data(movie.pop('kodipopcorn_hash'),
                                   movie["label"] + fYear + fQuality),
                    'info':
                    movie
                })

                # Update the final information for the movie
                if quality and not quality == '720p':
                    movie["label"] = "{label} ({quality})".format(
                        label=movie["label"], quality=quality)
                movie["path"] = plugin.url_for('play', **kwargs)

                items.append(movie)
        if items:
            plugin.set_content(content)
            return items
        raise AnErrorOccurred(30307)
    except AnErrorOccurred as e:
        plugin.notify("{default} {strerror}".format(
            default=plugin.addon.getLocalizedString(30306),
            strerror=plugin.addon.getLocalizedString(e.errno)),
                      delay=15000)
    except:
        plugin.notify(
            "{default}".format(default=plugin.addon.getLocalizedString(30306)),
            delay=15000)
Example #4
0
def show_data(callback):
    import xbmc
    import xbmcgui
    from contextlib import nested, closing
    from itertools import izip, chain
    from concurrent import futures
    from kodipopcorntime.providers import tmdb, yifysubs
    from kodipopcorntime.utils import url_get_json, SafeDialogProgress

    Plugin.set_content("movies")
    args = dict((k, v[0]) for k, v in Plugin.request.args.items())

    current_page = int(args["page"])
    limit = int(args["limit"])

    with closing(SafeDialogProgress(delay_close=0)) as dialog:
        dialog.create(Plugin.name)
        dialog.update(percent=0, line1=Plugin.addon.getLocalizedString(30007), line2="", line3="")

        search_result = {}
        for url in BASE_URLS:
            search_result = url_get_json("%s/api/v2/list_movies.json" % url, params=args, headers={"Referer": url,})
            if search_result:
                break

        if not search_result:
            Plugin.notify(Plugin.addon.getLocalizedString(30304))
            Plugin.log.error('Could not connect to %s/movie/%s?api_key=%s' %(BASE_URL, imdb_id, API_KEY))
            yield {
                    "label": Plugin.addon.getLocalizedString(30305)
                }
            return

        movies = search_result.get("data").get("movies") or []
        movie_count = int(search_result.get("data")["movie_count"])
        if not movies:
            if callback == "search_query":
                yield {
                        "label": Plugin.addon.getLocalizedString(30008),
                        "icon": path.join(Plugin.addon.getAddonInfo('path'), 'resources', 'icons', 'Search.png'),
                        "thumbnail": path.join(Plugin.addon.getAddonInfo('path'), 'resources', 'icons', 'Search.png'),
                        "path": Plugin.url_for("search")
                    }
            return

        state = {"done": 0}
        def on_movie(future):
            data = future.result()
            state["done"] += 1
            dialog.update(
                percent=int(state["done"] * 100.0 / len(movies)),
                line2=data.get("title") or data.get("MovieTitleClean") or "",
            )

        with futures.ThreadPoolExecutor(max_workers=2) as pool_tmdb:
            tmdb_list = [pool_tmdb.submit(tmdb.get, movie["imdb_code"]) for movie in movies]
            [future.add_done_callback(on_movie) for future in tmdb_list]
            while not all(job.done() for job in tmdb_list):
                if dialog.iscanceled():
                    return
                xbmc.sleep(100)

        tmdb_list = map(lambda job: job.result(), tmdb_list)
        for movie, tmdb_meta in izip(movies, tmdb_list):
            if tmdb_meta:

                tmdb_meta = tmdb.get_list_item(tmdb_meta)
                sub = yifysubs.get_sub_items(movie["imdb_code"])
                if sub == None:
                    sub = ["none", ""]

                for torrent in movie["torrents"]:
                    item = tmdb_meta.copy()

                    if args.get("quality") == "all" and torrent["quality"] != "720p":
                        item["label"] = "%s (%s)" % (item["label"], torrent["quality"])

                    if item.get("info").get("duration") == 0:
                        item["info"]["duration"] = movie["runtime"]

                    item.update({
                        "path": Plugin.url_for("play", sub=sub[0], uri=from_meta_data(torrent["hash"], movie["title_long"], torrent["quality"])),
                        "is_playable": True,
                    })

                    item.setdefault("info", {}).update({
                        "code": movie["imdb_code"],
                        "size": torrent["size_bytes"],
                    })

                    width = 1920
                    height = 1080
                    if torrent["quality"] == "720p":
                        width = 1280
                        height = 720
                    item.setdefault("stream_info", {}).update({
                        "video": {
                            "codec": "h264",
                            "width": width,
                            "height": height,
                        },
                        "audio": {
                            "codec": "aac",
                            "language": "en",
                        },
                        "subtitle": {
                            "language": sub[1],
                        },
                    })

                    yield item

        if current_page < (movie_count / limit):
            next_args = args.copy()
            next_args["page"] = int(next_args["page"]) + 1
            yield {
                "label": Plugin.addon.getLocalizedString(30009),
                "path": Plugin.url_for(callback, **next_args),
            }
Example #5
0
def show_data(callback):
    import xbmc
    import xbmcgui
    from contextlib import nested, closing
    from itertools import izip, chain
    from concurrent import futures
    from kodipopcorntime.scrapers import tmdb, yifysubs
    from kodipopcorntime.utils import url_get_json, SafeDialogProgress

    plugin.set_content("movies")
    args = dict((k, v[0]) for k, v in plugin.request.args.items())

    current_page = int(args["page"])
    limit = int(args["limit"])

    with closing(SafeDialogProgress(delay_close=0)) as dialog:
        dialog.create(plugin.name)
        dialog.update(percent=0, line1="Fetching movie information...", line2="", line3="")

        try:
            search_result = url_get_json("%s/api/v2/list_movies.json" % BASE_URL, params=args, headers=HEADERS)
        except:
            plugin.notify("Unable to connect to %s." % BASE_URL)
            raise
        movies = search_result.get("data").get("movies") or []
        movie_count = int(search_result.get("data")["movie_count"])

        if not movies:
            return

        state = {"done": 0}
        def on_movie(future):
            data = future.result()
            state["done"] += 1
            dialog.update(
                percent=int(state["done"] * 100.0 / len(movies)),
                line2=data.get("title") or data.get("MovieTitleClean") or "",
            )

        with futures.ThreadPoolExecutor(max_workers=2) as pool_tmdb:
            tmdb_list = [pool_tmdb.submit(tmdb.get, movie["imdb_code"]) for movie in movies]
            [future.add_done_callback(on_movie) for future in tmdb_list]
            while not all(job.done() for job in tmdb_list):
                if dialog.iscanceled():
                    return
                xbmc.sleep(100)

        tmdb_list = map(lambda job: job.result(), tmdb_list)
        for movie, tmdb_meta in izip(movies, tmdb_list):
            if tmdb_meta:
                sub = yifysubs.get_sub_items(movie["imdb_code"])
                if sub == None:
                    sub = ["none", ""]

                for torrent in movie["torrents"]:
                    item = tmdb.get_list_item(tmdb_meta)

                    if args.get("quality") == "all" and torrent["quality"] != "720p":
                        item["label"] = "%s (%s)" % (item["label"], torrent["quality"])

                    if item.get("info").get("duration") == 0:
                        item["info"]["duration"] = movie["runtime"]

                    item.update({
                        "path": plugin.url_for("play", sub=sub[0], uri=from_meta_data(torrent["hash"], movie["title_long"], torrent["quality"])),
                        "is_playable": True,
                    })

                    item.setdefault("info", {}).update({
                        "code": movie["imdb_code"],
                        "size": torrent["size_bytes"],
                    })

                    width = 1920
                    height = 1080
                    if torrent["quality"] == "720p":
                        width = 1280
                        height = 720
                    item.setdefault("stream_info", {}).update({
                        "video": {
                            "codec": "h264",
                            "width": width,
                            "height": height,
                        },
                        "audio": {
                            "codec": "aac",
                            "language": "en",
                        },
                        "subtitle": {
                            "language": sub[1],
                        },
                    })

                    yield item

        if current_page < (movie_count / limit):
            next_args = args.copy()
            next_args["page"] = int(next_args["page"]) + 1
            yield {
                "label": ">> Next page",
                "path": plugin.url_for(callback, **next_args),
            }
Example #6
0
def browse(provider, item, page):
    try:
        kwargs, sys_kwargs = _filter_kwargs()
        content = 'movies'
        items = []
        with closing(SafeDialogProgress(delay_close=0)) as dialog:
            dialog.create(plugin.name)
            dialog.update(percent=0, line1=plugin.addon.getLocalizedString(30007))

            movies = sys_kwargs['module'].browse(item, page, **kwargs)

            jobs = len(movies)*2+1
            done = 1
            dialog.update(percent=int(done*100/jobs), line2=plugin.addon.getLocalizedString(30007))

            def on_future_done(future):
                done = done+1
                data = future.result()
                dialog.update(percent=int(done*100/jobs), line2="{prefix}{label}".format(prefix=data.get('kodipopcorn_subtitle', ''), label=data.get("label", '')))

            subtitle = import_module(PROVIDERS['subtitle.yify'])
            meta = import_module(PROVIDERS['meta.tmdb'])
            with futures.ThreadPoolExecutor(max_workers=2) as pool:
                subtitle_list = [pool.submit(subtitle.get, id=item.get("info", {}).get("code")).add_done_callback(on_future_done) for item in movies]
                meta_list = [pool.submit(meta.get, id=item.get("info", {}).get("code")).add_done_callback(on_future_done) for item in movies]
                while not all(future.done() for future in subtitle_list) and not all(future.done() for future in meta_list):
                    if dialog.iscanceled():
                        return
                    xbmc.sleep(100)

            subtitles = map(lambda future: future.result(), subtitle_list)
            metadata = map(lambda future: future.result(), meta_list)
            for i, movie in enumerate(movies):
                # Update the movie with subtitle and meta data
                movie.update(subtitles[i])
                movie.update(metadata[i])

                # Catcher content type and remove it from movie
                # NOTE: This is not the best way to dynamic set the content type, since the content type can not be set for each movie
                if movie.get("kodipopcorn_content"):
                    content = movie.pop('kodipopcorn_content')

                # Catcher quality, build magnet label and remove quality from movie
                quality=fQuality=''
                if movie.get("kodipopcorn_quality"):
                    quality = movie.pop('kodipopcorn_quality')
                    fQuality = " [{quality}]".format(quality=quality)

                # Build magnet label
                fYear = ''
                if movie.get("year"):
                    fYear = " ({year})".format(year=movie["year"])

                # Builds targets for the player
                kwargs = {}
                if movie.get("kodipopcorn_subtitle"):
                    kwargs['subtitle'] = movie.pop('kodipopcorn_subtitle')
                kwargs.update({
                    'url': from_meta_data(movie.pop('kodipopcorn_hash'), movie["label"]+fYear+fQuality),
                    'info': movie
                })

                # Update the final information for the movie
                if quality and not quality == '720p':
                    movie["label"] = "{label} ({quality})".format(label=movie["label"], quality=quality)
                movie["path"] = plugin.url_for('play', **kwargs)

                items.append(movie)
        if items:
            plugin.set_content(content)
            return items
        raise AnErrorOccurred(30307)
    except AnErrorOccurred as e:
        plugin.notify("{default} {strerror}".format(default=plugin.addon.getLocalizedString(30306), strerror=plugin.addon.getLocalizedString(e.errno)), delay=15000)
    except:
        plugin.notify("{default}".format(default=plugin.addon.getLocalizedString(30306)), delay=15000)
Example #7
0
def show_data(callback):
    import xbmc
    import xbmcgui
    from contextlib import nested, closing
    from itertools import izip, chain
    from concurrent import futures
    from kodipopcorntime.scrapers import tmdb, yifysubs
    from kodipopcorntime.utils import url_get_json, SafeDialogProgress

    plugin.set_content("movies")
    args = dict((k, v[0]) for k, v in plugin.request.args.items())

    current_page = int(args["page"])
    limit = int(args["limit"])

    with closing(SafeDialogProgress(delay_close=0)) as dialog:
        dialog.create(plugin.name)
        dialog.update(percent=0,
                      line1="Fetching movie information...",
                      line2="",
                      line3="")

        try:
            search_result = url_get_json("%s/api/v2/list_movies.json" %
                                         BASE_URL,
                                         params=args,
                                         headers=HEADERS)
        except:
            plugin.notify("Unable to connect to %s." % BASE_URL)
            raise
        movies = search_result.get("data").get("movies") or []
        movie_count = int(search_result.get("data")["movie_count"])

        if not movies:
            return

        state = {"done": 0}

        def on_movie(future):
            data = future.result()
            state["done"] += 1
            dialog.update(
                percent=int(state["done"] * 100.0 / len(movies)),
                line2=data.get("title") or data.get("MovieTitleClean") or "",
            )

        with futures.ThreadPoolExecutor(max_workers=2) as pool_tmdb:
            tmdb_list = [
                pool_tmdb.submit(tmdb.get, movie["imdb_code"])
                for movie in movies
            ]
            [future.add_done_callback(on_movie) for future in tmdb_list]
            while not all(job.done() for job in tmdb_list):
                if dialog.iscanceled():
                    return
                xbmc.sleep(100)

        tmdb_list = map(lambda job: job.result(), tmdb_list)
        for movie, tmdb_meta in izip(movies, tmdb_list):
            if tmdb_meta:
                sub = yifysubs.get_sub_items(movie["imdb_code"])
                if sub == None:
                    sub = ["none", ""]

                for torrent in movie["torrents"]:
                    item = tmdb.get_list_item(tmdb_meta)

                    if args.get("quality"
                                ) == "all" and torrent["quality"] != "720p":
                        item["label"] = "%s (%s)" % (item["label"],
                                                     torrent["quality"])

                    if item.get("info").get("duration") == 0:
                        item["info"]["duration"] = movie["runtime"]

                    item.update({
                        "path":
                        plugin.url_for("play",
                                       sub=sub[0],
                                       uri=from_meta_data(
                                           torrent["hash"],
                                           movie["title_long"],
                                           torrent["quality"])),
                        "is_playable":
                        True,
                    })

                    item.setdefault("info", {}).update({
                        "code":
                        movie["imdb_code"],
                        "size":
                        torrent["size_bytes"],
                    })

                    width = 1920
                    height = 1080
                    if torrent["quality"] == "720p":
                        width = 1280
                        height = 720
                    item.setdefault("stream_info", {}).update({
                        "video": {
                            "codec": "h264",
                            "width": width,
                            "height": height,
                        },
                        "audio": {
                            "codec": "aac",
                            "language": "en",
                        },
                        "subtitle": {
                            "language": sub[1],
                        },
                    })

                    yield item

        if current_page < (movie_count / limit):
            next_args = args.copy()
            next_args["page"] = int(next_args["page"]) + 1
            yield {
                "label": ">> Next page",
                "path": plugin.url_for(callback, **next_args),
            }