Exemple #1
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", {}))
Exemple #2
0
def cleanDebris():
    try:
        for _mediaType in settings.MEDIATYPES:
            _m = getattr(settings, _mediaType)
            if _m and _m.delete_files and os.path.isdir(_m.media_cache_path):
                clear_media_cache(_m.media_cache_path)
    except:
        log_error()
        sys.exc_clear()
def cleanDebris():
    try:
        for _mediaType in settings.MEDIATYPES:
            _m = getattr(settings, _mediaType)
            if _m and _m.delete_files and os.path.isdir(_m.media_cache_path):
                clear_media_cache(_m.media_cache_path)
    except:
        log_error()
        sys.exc_clear()
 def __init__(self, *args):
     super(_Base3, self).__init__(*args)
     try:
         update_id = "%s.%s" % (_settings.version, BUILD)
         if not update_id == _settings.last_update_id:
             # Clear cache after update
             clear_cache()
             __addon__.setSetting("last_update_id", update_id)
     except:
         log_error()
         sys.exc_clear()
Exemple #5
0
 def __init__(self, *args):
     super(_Base3, self).__init__(*args)
     try:
         update_id = "%s.%s" %(_settings.version, BUILD)
         if not update_id == _settings.last_update_id:
             # Clear cache after update
             clear_cache()
             __addon__.setSetting("last_update_id", update_id)
     except:
         log_error()
         sys.exc_clear()
Exemple #6
0
def cleanDebris():
    try:
        for _mediaType in settings.MEDIATYPES:
            _m = getattr(settings, _mediaType)
            if _m and _m.delete_files:
                _p = os.path.join(settings.addon.cache_path, _mediaType)
                if os.path.isdir(_p):
                    clear_media_cache(_p)
    except:
        log_error()
        sys.exc_clear()
Exemple #7
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))
Exemple #8
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',  {}))
Exemple #9
0
def run():
    try:
        log("(Main) Starting - Platform: %s %s" %(Platform.system, Platform.arch), LOGLEVEL.INFO)

        log("(Main) Platform: %s" %sys.platform)
        if hasattr(os, 'uname'):
            log("(Main) Uname: %s" %str(os.uname()))
        log("(Main) Environ: %s" %str(os.environ))

        if not Platform.system:
            raise Error("Unsupported OS", 30302)

        def _empty_dir(path):
            if os.path.isdir(path):
                for x in os.listdir(path):
                    if x in ['.', '..', 'movies', 'tvshows']:
                        continue
                    _path = os.path.join(path, x)
                    if os.path.isfile(_path):
                        os.remove(_path)
                    elif os.path.isdir(_path):
                        _empty_dir(_path)
                        os.rmdir(_path)

        params = dict(urlparse.parse_qsl(settings.addon.cur_uri))
        if not params.pop('cmd', None):
            if not settings.addon.version+"~1" == settings.addon.last_update_id:
                # Clear cache after update
                _empty_dir(settings.addon.cache_path)
                __addon__.setSetting("last_update_id", settings.addon.version+"~1")
            else:
                # Clean debris from the cache dir
                try:
                    for mediaType in ['movies', 'tvshows']:
                        if getattr(settings, mediaType).delete_files:
                            _empty_dir(os.path.join(settings.addon.cache_path, mediaType))
                except:
                    log_error()
                    sys.exc_clear()
            PopcornTime(**params)
        else:
            Cmd(**params)

    except (Error, HTTPError, ProxyError, TorrentError) as e:
        notify(e.messageID, level=NOTIFYLEVEL.ERROR)
        log_error()
    except Notify as e:
        notify(e.messageID, e.message, level=e.level)
        log("(Main) Notify: %s" %str(e), LOGLEVEL.NOTICE)
        sys.exc_clear()
    except Abort:
        log("(Main) Abort", LOGLEVEL.INFO)
        sys.exc_clear()
    except:
        notify(30308, level=NOTIFYLEVEL.ERROR)
        log_error()
Exemple #10
0
        log("(Main) Platform: %s" % sys.platform)
        if hasattr(os, 'uname'):
            log("(Main) Uname: %s" % str(os.uname()))
        log("(Main) Environ: %s" % str(os.environ))

        if not Platform.system:
            raise Error("Unsupported OS", 30302)

        params = dict(urlparse.parse_qsl(settings.addon.cur_uri))
        if not params.get('cmd'):
            params = _fix(params)
            getattr(gui, params.pop('endpoint',
                                    'index'))(params.pop('mediaType',
                                                         '')).show(**params)
        else:
            getattr(gui.cmd, params.get('cmd'))()

    except (Error, HTTPError, ProxyError, TorrentError) as e:
        notify(e.messageID, level=NOTIFYLEVEL.ERROR)
        log_error()
    except Notify as e:
        notify(e.messageID, e.message, level=e.level)
        log("(Main) Notify: %s" % str(e), LOGLEVEL.NOTICE)
        sys.exc_clear()
    except Abort:
        log("(Main) Abort", LOGLEVEL.INFO)
        sys.exc_clear()
    except:
        notify(30308, level=NOTIFYLEVEL.ERROR)
        log_error()
Exemple #11
0
        log("(Main) Starting %s version %s build %s - Platform: %s %s" %(settings.addon.name, settings.addon.version, settings.BUILD, Platform.system, Platform.arch), LOGLEVEL.INFO)

        log("(Main) Platform: %s" %sys.platform)
        if hasattr(os, 'uname'):
            log("(Main) Uname: %s" %str(os.uname()))
        log("(Main) Environ: %s" %str(os.environ))

        if not Platform.system:
            raise Error("Unsupported OS", 30302)

        params = dict(urlparse.parse_qsl(settings.addon.cur_uri))
        if not params.get('cmd'):
            params = _fix(params)
            getattr(gui, params.pop('endpoint', 'index'))(params.pop('mediaType', '')).show(**params)
        else:
            getattr(gui.cmd, params.get('cmd'))()

    except (Error, HTTPError, ProxyError, TorrentError) as e:
        notify(e.messageID, level=NOTIFYLEVEL.ERROR)
        log_error()
    except Notify as e:
        notify(e.messageID, e.message, level=e.level)
        log("(Main) Notify: %s" %str(e), LOGLEVEL.NOTICE)
        sys.exc_clear()
    except Abort:
        log("(Main) Abort", LOGLEVEL.INFO)
        sys.exc_clear()
    except:
        notify(30308, level=NOTIFYLEVEL.ERROR)
        log_error()