Example #1
0
def get(imdb_id):
    from kodipopcorntime.caching import shelf
    with shelf("com.imdb.%s" % imdb_id) as movie:
        if not movie:
            try:
                import urllib2
                from kodipopcorntime.utils import url_get_json
                import xbmc
                sys_lang = xbmc.getLanguage(xbmc.ISO_639_1)
                data = url_get_json("%s/movie/%s" % (BASE_URL, imdb_id),
                                    params={
                                        "api_key": API_KEY,
                                        "append_to_response": "credits",
                                        "language": "en",
                                        "include_image_language": "en,null"
                                    },
                                    headers=HEADERS,
                                    with_immunicity=False) or {}
                if not sys_lang == 'en':
                    data.update(
                        url_get_json("%s/movie/%s" % (BASE_URL, imdb_id),
                                     params={
                                         "api_key": API_KEY,
                                         "append_to_response": "credits",
                                         "language": sys_lang,
                                         "include_image_language":
                                         "%s" % sys_lang
                                     },
                                     headers=HEADERS,
                                     with_immunicity=False) or {})
                movie.update(data)
            except urllib2.HTTPError:
                pass
        return dict(movie)
Example #2
0
def get(imdb_id):
    from kodipopcorntime.caching import shelf
    with shelf("com.imdb.%s" % imdb_id) as movie:
        if not movie:
            try:
                import urllib2
                from kodipopcorntime.utils import url_get_json
                import xbmc
                sys_lang = xbmc.getLanguage(xbmc.ISO_639_1)
                data = url_get_json("%s/movie/%s" % (BASE_URL, imdb_id), params={"api_key": API_KEY, "append_to_response": "credits", "language": "en", "include_image_language": "en,null"}, headers=HEADERS, with_immunicity=False) or {}
                if not sys_lang == 'en':
                    data.update(url_get_json("%s/movie/%s" % (BASE_URL, imdb_id), params={"api_key": API_KEY, "append_to_response": "credits", "language": sys_lang, "include_image_language": "%s" % sys_lang}, headers=HEADERS, with_immunicity=False) or {})
                movie.update(data)
            except urllib2.HTTPError:
                pass
        return dict(movie)
Example #3
0
def get_sub_items(imdb_id):
    if SUBLANG_EN_1 == 'none':
        return None

    import urllib2
    from kodipopcorntime.utils import url_get_json
    try:
        data = url_get_json("%s/%s" % (API_BASE_URL, imdb_id), headers={"Referer":API_BASE_URL,}, with_immunicity=False) or {}
    except urllib2.HTTPError:
        return None

    if data["subtitles"] == 0:
        return None

    data = data["subs"][imdb_id]
    if data.has_key(SUBLANG_EN_1):
        sub = "%s%s" % (BASE_URL, data[SUBLANG_EN_1][0]["url"])
        sublang = SUBLANG_ISO_1
    elif data.has_key(SUBLANG_EN_2):
        sub = "%s%s" % (BASE_URL, data[SUBLANG_EN_2][0]["url"])
        sublang = SUBLANG_ISO_2
    elif data.has_key(SUBLANG_EN_3):
        sub = "%s%s" % (BASE_URL, data[SUBLANG_EN_3][0]["url"])
        sublang = SUBLANG_ISO_3
    else:
        return None

    return [
        sub,
        sublang,
    ]
Example #4
0
def get_sub_items(imdb_id):
    if SUBLANG_EN_1 == 'none':
        return None

    import urllib2
    from kodipopcorntime.utils import url_get_json
    try:
        data = url_get_json("%s/%s" %
                            (API_BASE_URL, imdb_id), headers=HEADERS) or {}
    except urllib2.HTTPError:
        return None

    if data["subtitles"] == 0:
        return None

    data = data["subs"][imdb_id]
    if data.has_key(SUBLANG_EN_1):
        sub = "%s%s" % (BASE_URL, data[SUBLANG_EN_1][0]["url"])
        sublang = SUBLANG_ISO_1
    elif data.has_key(SUBLANG_EN_2):
        sub = "%s%s" % (BASE_URL, data[SUBLANG_EN_2][0]["url"])
        sublang = SUBLANG_ISO_2
    elif data.has_key(SUBLANG_EN_3):
        sub = "%s%s" % (BASE_URL, data[SUBLANG_EN_3][0]["url"])
        sublang = SUBLANG_ISO_3
    else:
        return None

    return [
        sub,
        sublang,
    ]
Example #5
0
def get(imdb_id):
    from kodipopcorntime.caching import shelf
    try:
        with shelf("com.imdb.%s" % imdb_id, DEFAULT_TTL) as movie:
            if not movie:
                import xbmc
                from kodipopcorntime.utils import url_get_json
                sys_lang = xbmc.getLanguage(xbmc.ISO_639_1)
                movie.update(url_get_json("%s/movie/%s" % (BASE_URL, imdb_id), params={"api_key": API_KEY, "append_to_response": "credits", "language": "en", "include_image_language": "en,null"}, headers=HEADERS))
                if not sys_lang == 'en':
                    movie.update(url_get_json("%s/movie/%s" % (BASE_URL, imdb_id), params={"api_key": API_KEY, "append_to_response": "credits", "language": sys_lang, "include_image_language": "%s" % sys_lang}, headers=HEADERS) or {})
                if not movie:
                    raise
        return dict(movie)
    except:
        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))
Example #6
0
def search(query, **kwargs):
    from kodipopcorntime.utils import url_get_json

    kwargs["query"] = query
    return url_get_json("%s/search/movie" % BASE_URL,
                        params=kwargs,
                        headers=HEADERS,
                        with_immunicity=False)
Example #7
0
def tmdb_config():
    from kodipopcorntime.caching import shelf
    try:
        with shelf("com.imdb.conf", DEFAULT_TTL) as conf:
            if not conf:
                from kodipopcorntime.utils import url_get_json
                conf.update(url_get_json("%s/configuration" % BASE_URL, params={"api_key": API_KEY}, headers=HEADERS))
                if not conf:
                    raise
            return dict(conf)
    except:
        plugin.notify(plugin.addon.getLocalizedString(30304))
        plugin.log.error('Could not connect to %s/configuration?api_key=%s' %(BASE_URL, API_KEY))
Example #8
0
def search(query):
    from kodipopcorntime.utils import url_get_json
    return url_get_json("%s/search/movie" % BASE_URL, params={"api_key": API_KEY, "query": query, "language": "en"}, headers=HEADERS)
Example #9
0
    def loop(self):
        from kodipopcorntime.utils import SafeDialogProgress

        has_resolved = False

        plugin.log.info("Starting torrent2http...")
        with closing(torrent2http.start(**self.torrent2http_options)) as t2h_instance:
            t2h = lambda cmd: url_get_json("http://%s/%s" % (t2h_instance.bind_address, cmd))

            if not self._wait_t2h_startup(t2h):
                return

            plugin.log.info("Opening download dialog...")
            with closing(SafeDialogProgress(delay_create=0)) as dialog:
                dialog.create(plugin.name)

                plugin.log.info("Waiting for file resolution...")
                progress = 0
                while not has_resolved:
                    if xbmc.abortRequested or dialog.iscanceled():
                        return

                    status = t2h("status")

                    if status["state"] >= 0:
                        new_progress = status["progress"] * 9091
                        if new_progress > progress:
                            progress = new_progress
                        if progress > int(progress):
                            progress = progress + 1
                        if progress > 100:
                            progress = 100
                        dialog.update(int(progress), *self._get_status_lines(status))

                    if status["state"] >= 3 and progress == 100:
                        files = t2h("ls")["files"]
                        biggest_file = sorted(files, key=lambda x: x["size"])[-1]
                        biggest_file["name"] = biggest_file["name"].encode("utf-8")
                        plugin.log.info("Resolving to http://%s/files/%s" % (t2h_instance.bind_address, biggest_file["name"]))
                        item = {"path": "http://%s/files/%s" % (t2h_instance.bind_address, urllib.quote(biggest_file["name"])),}
                        if not xbmc.getInfoLabel("ListItem.Title"):
                            item["label"] = status["name"]

                        self.subtitles = get_subtitle(self.subtitles)
                        plugin.set_resolved_url(item, self.subtitles)
                        break

                    xbmc.sleep(TORRENT2HTTP_POLL)

            # We are now playing
            plugin.log.info("Now playing torrent...")
            last_playing_event = 0
            with closing(OverlayText(w=OVERLAY_WIDTH, h=OVERLAY_HEIGHT, alignment=XBFONT_CENTER_X | XBFONT_CENTER_Y)) as overlay:
                with nested(self.attach(overlay.show, self.on_playback_paused),
                            self.attach(overlay.hide, self.on_playback_resumed, self.on_playback_stopped)):
                    while not xbmc.abortRequested and self.isPlaying():
                        overlay.text = "\n".join(self._get_status_lines(t2h("status")))
                        now = time.time()
                        if (now - last_playing_event) > PLAYING_EVENT_INTERVAL:
                            last_playing_event = now
                        xbmc.sleep(TORRENT2HTTP_POLL)

        clear_subtitle(self.subtitles)
        plugin.log.info("Closing Torrent player.")
Example #10
0
def tmdb_config():
    from kodipopcorntime.utils import url_get_json
    return url_get_json("%s/configuration" % BASE_URL,
                        params={"api_key": API_KEY},
                        headers=HEADERS,
                        with_immunicity=False)
Example #11
0
    def loop(self):
        from kodipopcorntime.utils import SafeDialogProgress

        has_resolved = False

        plugin.log.info("Starting torrent2http...")
        with closing(torrent2http.start(
                **self.torrent2http_options)) as t2h_instance:
            t2h = lambda cmd: url_get_json("http://%s/%s" %
                                           (t2h_instance.bind_address, cmd))

            if not self._wait_t2h_startup(t2h):
                return

            plugin.log.info("Opening download dialog...")
            with closing(SafeDialogProgress(delay_create=0)) as dialog:
                dialog.create(plugin.name)

                plugin.log.info("Waiting for file resolution...")
                progress = 0
                while not has_resolved:
                    if xbmc.abortRequested or dialog.iscanceled():
                        return

                    status = t2h("status")

                    if status["state"] >= 0:
                        new_progress = status["progress"] * 9091
                        if new_progress > progress:
                            progress = new_progress
                        if progress > int(progress):
                            progress = progress + 1
                        if progress > 100:
                            progress = 100
                        dialog.update(int(progress),
                                      *self._get_status_lines(status))

                    if status["state"] >= 3 and progress == 100:
                        files = t2h("ls")["files"]
                        biggest_file = sorted(files,
                                              key=lambda x: x["size"])[-1]
                        biggest_file["name"] = biggest_file["name"].encode(
                            "utf-8")
                        plugin.log.info(
                            "Resolving to http://%s/files/%s" %
                            (t2h_instance.bind_address, biggest_file["name"]))
                        item = {
                            "path":
                            "http://%s/files/%s" %
                            (t2h_instance.bind_address,
                             urllib.quote(biggest_file["name"])),
                        }
                        if not xbmc.getInfoLabel("ListItem.Title"):
                            item["label"] = status["name"]

                        self.subtitles = get_subtitle(self.subtitles)
                        plugin.set_resolved_url(item, self.subtitles)
                        break

                    xbmc.sleep(TORRENT2HTTP_POLL)

            # We are now playing
            plugin.log.info("Now playing torrent...")
            last_playing_event = 0
            with closing(
                    OverlayText(w=OVERLAY_WIDTH,
                                h=OVERLAY_HEIGHT,
                                alignment=XBFONT_CENTER_X
                                | XBFONT_CENTER_Y)) as overlay:
                with nested(
                        self.attach(overlay.show, self.on_playback_paused),
                        self.attach(overlay.hide, self.on_playback_resumed,
                                    self.on_playback_stopped)):
                    while not xbmc.abortRequested and self.isPlaying():
                        overlay.text = "\n".join(
                            self._get_status_lines(t2h("status")))
                        now = time.time()
                        if (now - last_playing_event) > PLAYING_EVENT_INTERVAL:
                            last_playing_event = now
                        xbmc.sleep(TORRENT2HTTP_POLL)

        clear_subtitle(self.subtitles)
        plugin.log.info("Closing Torrent player.")
Example #12
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 #13
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 #14
0
def search(query, **kwargs):
    from kodipopcorntime.utils import url_get_json

    kwargs["query"] = query
    return url_get_json("%s/search/movie" % BASE_URL, params=kwargs, headers=HEADERS, with_immunicity=False)
Example #15
0
def tmdb_config():
    from kodipopcorntime.utils import url_get_json
    return url_get_json("%s/configuration" % BASE_URL, params={"api_key": API_KEY}, headers=HEADERS, with_immunicity=False)
Example #16
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),
            }