コード例 #1
0
    def _common_menu_builder(self,
                             trakt_list,
                             content_type,
                             action="getSources",
                             **params):
        if len(trakt_list) == 0:
            g.log("We received no titles to build a list", "warning")
            g.cancel_directory()
            return

        list_items = []
        smart_play = params.pop("smart_play", False)
        no_paging = params.pop("no_paging", False)
        sort = params.pop("sort", False)
        prepend_date = params.pop("prepend_date", False)
        mixed_list = params.pop("mixed_list", False)
        next_args = params.pop("next_args", None)

        params.pop("hide_unaired", None)
        params.pop("hide_watched", None)
        try:
            params["bulk_add"] = True
            list_items = [
                g.add_directory_item(item.get("name"),
                                     action=action,
                                     menu_item=item,
                                     action_args=item.get("args"),
                                     **params) for item in
                self._post_process_list(trakt_list, prepend_date, mixed_list)
                if item is not None
            ]

            if smart_play:
                return list_items
            else:
                xbmcplugin.addDirectoryItems(g.PLUGIN_HANDLE, list_items,
                                             len(list_items))
        except Exception as e:
            g.log_stacktrace()
            if not smart_play:
                g.cancel_directory()
            raise e

        finally:
            if not smart_play:
                if (not (g.FROM_WIDGET
                         and g.get_bool_setting("general.widget.hide_next"))
                        and not no_paging
                        and len(list_items) >= self.page_limit):
                    g.REQUEST_PARAMS["page"] = g.PAGE + 1
                    if next_args:
                        g.REQUEST_PARAMS["action_args"] = next_args
                    elif g.REQUEST_PARAMS.get("action_args") is not None:
                        g.REQUEST_PARAMS["action_args"] = g.REQUEST_PARAMS.get(
                            "action_args")
                    params = g.REQUEST_PARAMS
                    params.update({"special_sort": "bottom"})
                    g.add_directory_item(g.get_language_string(30016),
                                         **params)
                g.close_directory(content_type, sort=sort)
コード例 #2
0
    def get_json(self, **params):
        from resources.lib.third_party import xml_to_dict
        from xml.parsers.expat import ExpatError  # pylint: disable=no-name-in-module

        response = self.get(**params)
        if response is None:
            return None
        try:
            if not response.content:
                return None
            elif xml_to_dict.parse(response.text).get("root",
                                                      {}).get("@response",
                                                              {}) == "False":
                return None
            elif xml_to_dict.parse(response.text).get("root",
                                                      {}).get("error", {}):
                return None

            return self._handle_response(
                xml_to_dict.parse(response.text).get("root", {}).get("movie"))
        except (ValueError, AttributeError, ExpatError):
            g.log_stacktrace()
            g.log(
                "Failed to receive JSON from OMDb response - response: {}".
                format(response),
                "error",
            )
            return None
コード例 #3
0
    def _trakt_stop_watching(self):
        if (not self.trakt_enabled or not self.scrobbling_enabled
                or self.scrobbled
                or g.get_global_setting("marked_watched_dialog_open")
                or self.current_time < self.ignoreSecondsAtStart):
            return

        post_data = self._build_trakt_object()

        if (post_data["progress"] >= self.playCountMinimumPercent
                or self._force_marked_watched):
            post_data["progress"] = (80 if post_data["progress"] < 80 else
                                     post_data["progress"])
            try:
                scrobble_response = self._trakt_api.post(
                    "scrobble/stop", post_data)
            except:
                g.log_stacktrace()
                return
            if scrobble_response.status_code in (201, 409):
                self._trakt_mark_playing_item_watched()
                self.scrobbled = True
        elif self.current_time > self.ignoreSecondsAtStart:
            try:
                scrobble_response = self._trakt_api.post(
                    "scrobble/pause", post_data)
            except:
                g.log_stacktrace()
                return
        else:
            return

        if not scrobble_response.status_code == 201:
            g.log("Error scrobbling item to Trakt")
コード例 #4
0
    def background_tasks(self):
        """
        Runs background watcher tasks
        :return: None
        :rtype: none
        """
        try:
            try:
                progress_bar = self.getControlProgress(3014)
            except:
                progress_bar = None

            while (int(self.getTotalTime()) - int(self.getTime()) > 2
                   and not self.closed
                   and self.playing_file == self.getPlayingFile()
                   and not g.abort_requested()):
                xbmc.sleep(500)
                if progress_bar is not None:
                    progress_bar.setPercent(self.calculate_percent())

                if self.skip_intro_activated_time + self.skip_intro_open_time == int(
                        self.getTime()):
                    self.close()

        except:
            import traceback

            g.log_stacktrace()

        self.close()
コード例 #5
0
    def run(self):
        """
        Executes the workload
        :return:
        :rtype:
        """
        while not self.tasks.empty() and not self.stop_flag.is_set():

            try:
                func, result_callback, args, kwargs = self.tasks.get(
                    timeout=0.1)
                self.name = g.UNICODE(func)
                result_callback(func(*args, **kwargs))
            except Empty:
                break
            except BaseException as ex:
                g.log_stacktrace()
                self.exception_handler(ex)
                break
            finally:
                try:
                    self.tasks.task_done()
                except Exception as e:
                    print("task done error: {}".format(repr(e)))
                    pass
コード例 #6
0
    def get_hoster_list():
        """
        Fetche
        :return:
        """
        thread_pool = ThreadPool()

        hosters = {"premium": {}, "free": []}

        try:
            if g.get_bool_setting("premiumize.enabled") and g.get_bool_setting(
                    "premiumize.hosters"):
                thread_pool.put(Premiumize().get_hosters, hosters)

            if g.get_bool_setting("realdebrid.enabled") and g.get_bool_setting(
                    "rd.hosters"):
                thread_pool.put(RealDebrid().get_hosters, hosters)

            if g.get_bool_setting("alldebrid.enabled") and g.get_bool_setting(
                    "alldebrid.hosters"):
                thread_pool.put(AllDebrid().get_hosters, hosters)
            thread_pool.wait_completion()
        except ValueError:
            g.log_stacktrace()
            xbmcgui.Dialog().notification(g.ADDON_NAME,
                                          g.get_language_string(30513))
            return hosters
        return hosters
コード例 #7
0
    def wrapper(*args, **kwarg):
        try:
            response = func(*args, **kwarg)
            if response.status_code in [200, 201]:
                return response

            if response.status_code == 404:
                g.log('FanartTv failed to find {}'.format(response.url),
                      'debug')
                return None
            else:
                g.log(
                    'FanartTv returned a {} ({}): while requesting {}'.format(
                        response.status_code,
                        FanartTv.http_codes[response.status_code],
                        response.url), 'error')
            return response
        except requests.exceptions.ConnectionError:
            return None
        except Exception:
            xbmcgui.Dialog().notification(
                g.ADDON_NAME,
                g.get_language_string(30025).format('Fanart'))
            if g.get_runtime_setting("run.mode") == "test":
                raise
            else:
                g.log_stacktrace()
            return None
コード例 #8
0
ファイル: omdb.py プロジェクト: vonsagar/plugin.video.seren
    def wrapper(*args, **kwarg):
        try:
            response = func(*args, **kwarg)

            if response.status_code in [200, 201, 204]:
                return response

            g.log(
                "OMDb returned a {} ({}): while requesting {}".format(
                    response.status_code,
                    OMDB_STATUS_CODES[response.status_code],
                    "&".join(x for x in response.url.split('&')
                             if not x.lower().startswith("apikey")),
                ),
                "error",
            )

            return None
        except requests.exceptions.ConnectionError as e:
            g.log("Connection Error to OMDb: {} - {}".format(args, kwarg),
                  "error")
            g.log(e, "error")
            return None
        except Exception:
            xbmcgui.Dialog().notification(
                g.ADDON_NAME,
                g.get_language_string(30025).format("OMDb"))
            if g.get_runtime_setting("run.mode") == "test":
                raise
            else:
                g.log_stacktrace()
            return None
コード例 #9
0
ファイル: player.py プロジェクト: nixgates/plugin.video.seren
    def _handle_bookmark(self):
        if g.get_runtime_setting("marked_watched_dialog_open"):
            return

        try:
            g.clear_kodi_bookmarks()
        except Exception:
            g.log_stacktrace()
            pass

        if self.current_time == 0 or self.total_time == 0:
            self.bookmark_sync.remove_bookmark(self.trakt_id)
            return

        if (
                self.watched_percentage < self.playCountMinimumPercent
                and self.current_time >= self.ignoreSecondsAtStart
                and not self._force_marked_watched
         ):
            self.bookmark_sync.set_bookmark(
                self.trakt_id,
                int(self.current_time),
                self.mediatype,
                self.watched_percentage,
                )
        else:
            self.bookmark_sync.remove_bookmark(self.trakt_id)
コード例 #10
0
    def background_tasks(self):
        """
        Runs background watcher tasks
        :return: None
        :rtype: none
        """
        try:
            try:
                progress_bar = self.getControlProgress(3014)
            except Exception:
                progress_bar = None

            while (
                (int(self.player.getTotalTime()) - int(self.player.getTime())) > 1
                and not self.closed
                and self.playing_file == self.player.getPlayingFile()
                and not g.abort_requested()
            ):
                xbmc.sleep(500)
                if progress_bar is not None:
                    progress_bar.setPercent(self.calculate_percent())

            if not self.closed:
                self.player.pause()
        except Exception:
            g.log_stacktrace()

        self.close()
コード例 #11
0
    def build_playlist(self, season_id=None, minimum_episode=None):
        """
        Uses available information to add relevant episodes to the current playlist
        :param season_id: Trakt ID of season to build
        :type season_id: int
        :param minimum_episode: Minimum episodes to add from
        :type minimum_episode: int
        :return:
        :rtype:
        """
        if season_id is None:
            season_id = self.item_information["info"]["trakt_season_id"]

        if minimum_episode is None:
            minimum_episode = int(self.item_information["info"]["episode"]) + 1

        try:
            [
                g.PLAYLIST.add(url=i[0], listitem=i[1])
                for i in self.list_builder.episode_list_builder(
                    self.show_trakt_id,
                    season_id,
                    minimum_episode=minimum_episode,
                    smart_play=True,
                    hide_unaired=True,
                )
            ]
        except TypeError:
            g.log_stacktrace()
            g.log(
                "Unable to add more episodes to the playlist, they may not be available for the requested season",
                "error",
            )
            return
コード例 #12
0
    def wrapper(*args, **kwarg):
        import requests
        try:
            response = func(*args, **kwarg)
            if response.status_code in [200, 201]:
                return response

            g.log(
                "TMDb returned a {} ({}): while requesting {}".format(
                    response.status_code,
                    TMDBAPI.http_codes[response.status_code],
                    "&".join(x for x in response.url.split('&')
                             if not x.lower().startswith("api_key")),
                ), "warning" if not response.status_code == 404 else "debug")
            return None
        except requests.exceptions.ConnectionError:
            return None
        except Exception:
            xbmcgui.Dialog().notification(
                g.ADDON_NAME,
                g.get_language_string(30024).format("TMDb"))
            if g.get_runtime_setting("run.mode") == "test":
                raise
            else:
                g.log_stacktrace()
            return None
コード例 #13
0
 def get_hosters(self, hosters):
     host_list = self.update_relevant_hosters()
     if host_list is not None:
         hosters["premium"]["all_debrid"] = [
             (d, d.split(".")[0]) for l in host_list["hosts"].values()
             if "status" in l and l["status"] for d in l["domains"]
         ]
     else:
         g.log_stacktrace()
         hosters["premium"]["all_debrid"] = []
コード例 #14
0
 def doModal(self):
     """
     Call to display window in an interactive fashion
     :return: None
     :rtype: none
     """
     try:
         super(StillWatching, self).doModal()
     except Exception:
         g.log_stacktrace()
コード例 #15
0
 def doModal(self):
     """
     Call to display window in an interactive fashion
     :return: None
     :rtype: none
     """
     try:
         super(PlayingNext, self).doModal()
     except:
         g.log_stacktrace()
コード例 #16
0
 def __init__(self, xml_file, xml_location, item_information=None):
     try:
         self.player = xbmc.Player()
         self.playing_file = self.player.getPlayingFile()
         self.closed = False
         self.duration = self.player.getTotalTime() - self.player.getTime()
         super(StillWatching, self).__init__(
             xml_file, xml_location, item_information=item_information
         )
     except Exception:
         g.log_stacktrace()
コード例 #17
0
ファイル: __init__.py プロジェクト: peno64/plugin.video.seren
        def _decorated(*args, **kwargs):
            method_class = args[0]

            for a in args[1:]:
                if isinstance(a, types.GeneratorType):
                    raise UnsupportedCacheParamException("generator")

            for k, v in kwargs.items():
                if isinstance(v, types.GeneratorType):
                    raise UnsupportedCacheParamException("generator")

            if func.__name__ == "get_sources":
                overwrite_cache = kwargs.get("overwrite_cache", False)
                kwargs_cache_value = {
                    k: v
                    for k, v in kwargs.items() if not k == "overwrite_cache"
                }
            else:
                overwrite_cache = kwargs.pop("overwrite_cache", False)
                kwargs_cache_value = kwargs

            hours = kwargs.pop("cache_hours", cache_hours)
            global_cache_ignore = g.get_bool_runtime_setting(
                "ignore.cache", False)
            ignore_cache = kwargs.pop("ignore_cache", False)
            if ignore_cache or global_cache_ignore:
                return func(*args, **kwargs)

            checksum = _get_checksum(method_class.__class__.__name__,
                                     func.__name__)
            cache_str = "{}.{}.{}.{}".format(
                method_class.__class__.__name__, func.__name__,
                tools.md5_hash(args[1:]), tools.md5_hash(kwargs_cache_value))
            cached_data = g.CACHE.get(
                cache_str, checksum=checksum
            ) if not overwrite_cache else CacheBase.NOT_CACHED
            if cached_data == CacheBase.NOT_CACHED:
                fresh_result = func(*args, **kwargs)
                if func.__name__ == "get_sources" and (not fresh_result or len(
                        fresh_result[1]) == 0):
                    return fresh_result
                try:
                    g.CACHE.set(
                        cache_str,
                        fresh_result,
                        expiration=datetime.timedelta(hours=hours),
                        checksum=checksum,
                    )
                except TypeError:
                    g.log_stacktrace()
                    pass
                return fresh_result
            else:
                return cached_data
コード例 #18
0
    def __init__(self, xml_file, xml_location, item_information=None):

        try:
            super(PlayingNext, self).__init__(
                xml_file, xml_location, item_information=item_information
            )
            self.playing_file = self.getPlayingFile()
            self.duration = self.getTotalTime() - self.getTime()
            self.closed = False
            self.default_action = g.get_int_setting("playingnext.defaultaction")
        except Exception:
            g.log_stacktrace()
コード例 #19
0
    def __init__(self, xml_file, xml_location, item_information=None):

        try:
            super(PlayingNext,
                  self).__init__(xml_file,
                                 xml_location,
                                 item_information=item_information)
            self.playing_file = self.getPlayingFile()
            self.duration = self.getTotalTime() - self.getTime()
            self.closed = False
        except:
            g.log_stacktrace()
コード例 #20
0
 def __init__(self, xml_file, xml_location, item_information=None):
     try:
         self.player = xbmc.Player()
         self.playing_file = self.player.getPlayingFile()
         self.closed = False
         self.duration = 30
         self.dialog_opened_time = int(self.player.getTime())
         self.is_paused = False
         super(StillWatching,
               self).__init__(xml_file,
                              xml_location,
                              item_information=item_information)
     except:
         g.log_stacktrace()
コード例 #21
0
 def _premiumize_worker(self, torrent_list):
     try:
         hash_list = [i['hash'] for i in torrent_list]
         if len(hash_list) == 0:
             return
         premiumize_cache = premiumize.Premiumize().hash_check(hash_list)
         premiumize_cache = premiumize_cache['response']
         count = 0
         for i in torrent_list:
             if premiumize_cache[count] is True:
                 i['debrid_provider'] = 'premiumize'
                 self.store_torrent(i)
             count += 1
     except Exception:
         g.log_stacktrace()
コード例 #22
0
    def __init__(self, xml_file, xml_location, item_information=None):

        try:
            super(SkipIntro, self).__init__(xml_file,
                                            xml_location,
                                            item_information=item_information)
            self.playing_file = self.getPlayingFile()
            self.duration = g.get_int_setting("skip.intro.open.time")
            self.closed = False
            self.skip_intro = g.get_bool_setting("skip.intro.dialog")
            self.skip_intro_open_time = g.get_int_setting(
                "skip.intro.open.time")
            self.skip_intro_time = g.get_int_setting("skip.intro.time")
            self.skip_intro_activated_time = 0
        except:
            g.log_stacktrace()
コード例 #23
0
ファイル: omdb.py プロジェクト: vonsagar/plugin.video.seren
 def get_json(self, **params):
     response = self.get(**params)
     if response is None:
         return None
     try:
         if not response.content:
             return None
         return self._handle_response(
             xml_to_dict.parse(response.text).get("root", {}).get("movie"))
     except (ValueError, AttributeError):
         g.log_stacktrace()
         g.log(
             "Failed to receive JSON from OMDb response - response: {}".
             format(response),
             "error",
         )
         return None
コード例 #24
0
    def _trakt_start_watching(self, offset=None, re_scrobble=False):
        if (not self.trakt_enabled or not self.scrobbling_enabled
                or (self.scrobbled and not re_scrobble)
                or (self.scrobble_started and not re_scrobble)):
            return

        if (self.watched_percentage >= self.playCountMinimumPercent
                or self.current_time < self.ignoreSecondsAtStart):
            return

        try:
            post_data = self._build_trakt_object(offset=offset)

            self._trakt_api.post("scrobble/start", post_data)
        except:
            g.log_stacktrace()
        self.scrobble_started = True
コード例 #25
0
ファイル: subtitles.py プロジェクト: CYBERxNUKE/xbmc-addon
 def download(self, request, **extra):
     """
     Downloads requested subtitle
     :param request: Selected subtitle from search results
     :type request: dict
     :param extra: Kwargs, set settings to settings to request to use
     :type extra: dict
     :return: Path to subtitle
     :rtype: str
     """
     try:
         settings = extra.pop("settings", None)
         return self.service.download(request, settings)
     except (OSError, IOError):
         g.log("Unable to download subtitle, file already exists", "error")
     except Exception as e:
         g.log("Unknown error acquiring subtitle: {}".format(e), "error")
         g.log_stacktrace()
コード例 #26
0
    def _realdebrid_worker(self, torrent_list, info):

        try:
            hash_list = [i['hash'] for i in torrent_list]
            api = real_debrid.RealDebrid()
            real_debrid_cache = api.check_hash(hash_list)

            for i in torrent_list:
                try:
                    if 'rd' not in real_debrid_cache.get(i['hash'], {}):
                        continue
                    if len(real_debrid_cache[i['hash']]['rd']) >= 1:
                        if self.scraper_class.media_type == 'episode':
                            self._handle_episode_rd_worker(i, real_debrid_cache, info)
                        else:
                            self._handle_movie_rd_worker(i, real_debrid_cache)
                except KeyError:
                    pass
        except Exception:
            g.log_stacktrace()
コード例 #27
0
    def wrapper(*args, **kwarg):
        method_class = args[0]
        try:
            response = func(*args, **kwarg)
            if response.status_code in [200, 201]:
                return response

            if response.status_code == 401:
                try:
                    with GlobalLock("tvdb.oauth",
                                    run_once=True,
                                    check_sum=method_class.jwToken) as lock:
                        if method_class.jwToken is not None:
                            method_class.try_refresh_token(True)
                except RanOnceAlready:
                    pass
                if method_class.refresh_token is not None:
                    return func(*args, **kwarg)

            g.log(
                "TVDB returned a {} ({}): while requesting {}".format(
                    response.status_code,
                    TVDBAPI.http_codes[response.status_code]
                    if not response.status_code == 404 else
                    response.json()["Error"],
                    response.url,
                ),
                "warning" if not response.status_code == 404 else "debug",
            )
            return None
        except requests.exceptions.ConnectionError:
            return None
        except Exception:
            xbmcgui.Dialog().notification(
                g.ADDON_NAME,
                g.get_language_string(30025).format("TVDB"))
            if g.get_runtime_setting("run.mode") == "test":
                raise
            else:
                g.log_stacktrace()
            return None
コード例 #28
0
    def wrapper(*args, **kwarg):
        try:
            response = func(*args, **kwarg)
            if response.status_code in [200, 201]:
                return response

            if "Retry-After" in response.headers:
                # API REQUESTS Are not being throttled anymore but we leave it here for if the re-enable it again
                throttle_time = response.headers["Retry-After"]
                g.log(
                    "TMDb Throttling Applied, Sleeping for {} seconds".format(
                        throttle_time),
                    "",
                )
                xbmc.sleep((int(throttle_time) * 1000) + 1)
                return wrapper(*args, **kwarg)

            g.log(
                "TMDb returned a {} ({}): while requesting {}".format(
                    response.status_code,
                    TMDBAPI.http_codes[response.status_code],
                    response.url,
                ),
                "warning",
            )
            return None
        except requests.exceptions.ConnectionError:
            return None
        except Exception:
            xbmcgui.Dialog().notification(
                g.ADDON_NAME,
                g.get_language_string(30025).format("TMDb"))
            if g.get_global_setting("run.mode") == "test":
                raise
            else:
                g.log_stacktrace()
            return None
コード例 #29
0
    def _all_debrid_worker(self, torrent_list):

        try:
            api = all_debrid.AllDebrid()

            if len(torrent_list) == 0:
                return

            cache_check = api.check_hash([i['hash'] for i in torrent_list])

            if not cache_check:
                return

            for idx, i in enumerate(torrent_list):
                try:
                    if cache_check['magnets'][idx]['instant'] is True:
                        i['debrid_provider'] = 'all_debrid'
                        self.store_torrent(i)
                except KeyError:
                    g.log('KeyError in AllDebrid Cache check worker. '
                          'Failed to walk AllDebrid cache check response, check your auth and account status', 'error')
                    return
        except Exception:
            g.log_stacktrace()
コード例 #30
0
    def background_tasks(self):
        """
        Runs background watcher tasks
        :return:
        """
        try:
            try:
                progress_bar = self.getControlProgress(3014)
            except RuntimeError:
                progress_bar = None

            while (int(self.getTotalTime()) - int(self.getTime()) > 2
                   and not self.closed
                   and self.playing_file == self.getPlayingFile()
                   and not g.abort_requested()):
                xbmc.sleep(500)
                if progress_bar is not None:
                    progress_bar.setPercent(self.calculate_percent())

            self.smart_play_action()
        except Exception:
            g.log_stacktrace()

        self.close()