コード例 #1
0
    def _getMeta(self, item, args, id):
            metadata = Cache("%s.mediainfo.metadata" %self._mediaSettings.mediaType, ttl=_ttl, readOnly=True, last_changed=self._mediaSettings.metadata_lastchanged).get(id)
            if not metadata:
                try:
                    log("(Media) Getting metadata")
                    _res = self._handle_param(**self._mediaSettings.metadata_provider.item(*args+[_settings.language]))
                    if not self.stop.is_set():
                        metadata = cleanDictList(self._mediaSettings.metadata_provider.build_item(_res, *args+[_settings.language])) # 1. Get request parameter. 2. Perform request(s). 3. Build info.
                except:
                    log_error()
                    sys.exc_clear()
                finally:
                    if self._callbackfn:
                        log("(Media) Callback with '%s'" %item['label'])
                        self._callbackfn(self._progressValue, item, metadata or {})

                if not self._mediaSettings.metadata_provider.FALLBACKLANG == _settings.language:
                    fallbackMeta = None
                    try:
                        log("(Media) Getting fallback metadata")
                        _res = self._handle_param(**self._mediaSettings.metadata_provider.item(*args+[_settings.language]))
                        if not self.stop.is_set():
                            fallbackMeta = self._mediaSettings.metadata_provider.build_item(_res, *args+[_settings.language]) # 1. Get request parameter. 2. Perform request(s). 3. Build info.
                    except:
                        log_error()
                        sys.exc_clear()
                    else:
                        if metadata and fallbackMeta:
                            fallbackMeta.update(metadata)
                        if fallbackMeta:
                            metadata = cleanDictList(fallbackMeta)
                    finally:
                        if self._callbackfn:
                            log("(Media) Callback with '%s'" %item['label'])
                            self._callbackfn(self._progressValue, item, metadata or {})

                if metadata:
                    Cache("%s.mediainfo.metadata" %self._mediaSettings.mediaType, ttl=_ttl, last_changed=self._mediaSettings.metadata_lastchanged)[id] = metadata
            else:
                if self._callbackfn:
                    log("(Media) Callback with '%s'" %item['label'])
                    self._callbackfn(self._progressValue*(1+(not self._mediaSettings.metadata_provider.FALLBACKLANG == _settings.language)), item, metadata)

            if metadata:
                item.setdefault('info',        {}).update(dict((key, value) for key, value in metadata.pop('info',        {}).items() if value))
                item.setdefault('properties',  {}).update(dict((key, value) for key, value in metadata.pop('properties',  {}).items() if value))
                item.setdefault('stream_info', {}).setdefault('video', {}).update(dict((key, value) for key, value in metadata.pop('stream_info', {}).pop('video', {}).items() if value))
                item.update(dict((key, value) for key, value in metadata.items() if value))
コード例 #2
0
ファイル: media.py プロジェクト: chakhdin/KODI-Popcorn-Time
    def _getSubtitle(self, item, args, id):
        log("(Media) Subtitle")
        subtitle = Cache(
            "%s.mediainfo.subtitles" % self._mediaSettings.mediaType,
            ttl=_ttl,
            readOnly=True,
            last_changed=self._mediaSettings.subtitle_lastchanged,
        ).get(id)
        if not subtitle:
            try:
                log("(Media) Getting subtitle")
                _res = self._handle_param(**self._mediaSettings.subtitles_provider.item(*args))
                if not self.stop.is_set():
                    subtitle = cleanDictList(
                        self._mediaSettings.subtitles_provider.build_item(_res, *args)
                    )  # 1. Get request parameter. 2. Perform request(s). 3. Build info.
            except:
                log_error()
                sys.exc_clear()
            else:
                if subtitle:
                    Cache(
                        "%s.mediainfo.subtitles" % self._mediaSettings.mediaType,
                        ttl=_ttl,
                        last_changed=self._mediaSettings.subtitle_lastchanged,
                    )[id] = subtitle

        if self._callbackfn:
            log("(Media) Callback with '%s'" % item["label"])
            self._callbackfn(self._progressValue, item, subtitle or {})

        if subtitle:
            item.setdefault("stream_info", {})["subtitle"] = subtitle.setdefault("stream_info", {}).get("subtitle", {})
            item.setdefault("params", {}).update(subtitle.get("params", {}))
コード例 #3
0
ファイル: addon.py プロジェクト: Tuxik/KODI-Popcorn-Time
def _shelf_mediainfo(type, item, provider, refresh):
    with shelf("mediainfo.{type}.{md5}".format(type=type, md5=hashlib.md5(simplejson.dumps(item)).hexdigest()), 24 * 3600) as mediainfo:
        if refresh:
            mediainfo.clear()
        if not mediainfo:
            mediainfo.update(cleanDictList(provider.get(item["info"]["code"], item["label"], item["info"]["year"])))
        return mediainfo
コード例 #4
0
def _shelf_mediainfo(type, item, provider, refresh):
    with shelf(
            "mediainfo.{type}.{md5}".format(
                type=type,
                md5=hashlib.md5(simplejson.dumps(item)).hexdigest()),
            24 * 3600) as mediainfo:
        if refresh:
            mediainfo.clear()
        if not mediainfo:
            mediainfo.update(
                cleanDictList(
                    provider.get(item["info"]["code"], item["label"],
                                 item["info"]["year"])))
        return mediainfo
コード例 #5
0
def get(id, label, year):
    # English
    params={
        "api_key": _api_key,
        "append_to_response": "credits",
        "language": "en",
        "include_image_language": "en,null"
    }
    meta = url_get(_base_url, "/3/movie/{id}".format(id=id), params=params)
    if not meta or meta.get('status_code'):
        return {}

    # System language
    sys_lang = xbmc.getLanguage(xbmc.ISO_639_1)
    if not sys_lang == 'en':
        params.update({"language": sys_lang, "include_image_language": sys_lang})
        sys_meta = url_get(_base_url, "/3/movie/{id}".format(id=id), params=params)
        if sys_meta and not sys_meta.get('status_code'):
            meta.update(cleanDictList(sys_meta))

    return _create_item(meta)
コード例 #6
0
ファイル: meta_tmdb.py プロジェクト: revho6/KODI-Popcorn-Time
def get(id, label, year):
    # English
    params={
        "api_key": _api_key,
        "append_to_response": "credits",
        "language": "en",
        "include_image_language": "en,null"
    }
    meta = url_get(_base_url, "/3/movie/{id}".format(id=id), params=params)
    if not meta or meta.get('status_code'):
        return {}

    # System language
    sys_lang = xbmc.getLanguage(xbmc.ISO_639_1)
    if not sys_lang == 'en':
        params.update({"language": sys_lang, "include_image_language": sys_lang})
        sys_meta = url_get(_base_url, "/3/movie/{id}".format(id=id), params=params)
        if sys_meta and not sys_meta.get('status_code'):
            meta.update(cleanDictList(sys_meta))

    return _create_item(meta)
コード例 #7
0
    def _getSubtitle(self, item, args, id):
        log("(Media) Subtitle")
        subtitle = Cache("%s.mediainfo.subtitles" %self._mediaSettings.mediaType, ttl=_ttl, readOnly=True, last_changed=self._mediaSettings.subtitle_lastchanged).get(id)
        if not subtitle:
            try:
                log("(Media) Getting subtitle")
                _res = self._handle_param(**self._mediaSettings.subtitles_provider.item(*args))
                if not self.stop.is_set():
                    subtitle = cleanDictList(self._mediaSettings.subtitles_provider.build_item(_res, *args)) # 1. Get request parameter. 2. Perform request(s). 3. Build info.
            except:
                log_error()
                sys.exc_clear()
            else:
                if subtitle:
                    Cache("%s.mediainfo.subtitles" %self._mediaSettings.mediaType, ttl=_ttl, last_changed=self._mediaSettings.subtitle_lastchanged)[id] = subtitle

        if self._callbackfn:
            log("(Media) Callback with '%s'" %item['label'])
            self._callbackfn(self._progressValue, item, subtitle or {})

        if subtitle:
            item.setdefault('stream_info', {})['subtitle'] = subtitle.setdefault('stream_info', {}).get("subtitle", {})
            item.setdefault('params', {}).update(subtitle.get('params',  {}))