How to use the pysd.Fatal_error function in pysd

To help you get started, we’ve selected a few pysd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github KonishchevDmitry / pysd / pysd.py View on Github external
(.+?)
                    
                """, re.IGNORECASE | re.VERBOSE)

                for match in tv_show_regex.finditer(tv_show_list_html):
                    show_name = self.__tag_re.sub("", match.group(4)).replace(" ", " ").strip().lower()
                    shows[show_name] = { "id": match.group(2), "seasons": {} }

                if not shows:
                    raise Exception("failed to parse a server response")

                self.__cache = shows

            return self.__cache
        except Exception as e:
            raise Fatal_error("Unable to get TV show list from {0}: {1}.", self.__domain_name, e)
github KonishchevDmitry / pysd / pysd.py View on Github external
def make_connection(self, host):
        connection = HTTPConnection(self.proxy if self.proxy else host)

        if hasattr(connection, "real_host"):
            raise Fatal_error("logical error")

        connection.real_host = host

        return connection
github KonishchevDmitry / pysd / pysd.py View on Github external
def get(self, file_path, show_name, season, episode, language):
        """Gets a TV show subtitles and returns the subtitles file contents."""

        subtitles = self.__get_episode_subtitles(show_name, season, episode)

        if language not in subtitles:
            raise Not_found()

        try:
            zipfile_data = get_url_contents( self.__url_prefix + "download-{0}.html".format(subtitles[language]) )
        except Exception as e:
            raise Fatal_error("Unable to download the subtitles: {0}.", e)

        try:
            subtitles_zip = zipfile.ZipFile(BytesIO(zipfile_data))
            if len(subtitles_zip.namelist()) != 1:
                raise Error("zip file contains {0} files instead of 1", len(subtitles_zip.namelist()))

            return subtitles_zip.open(subtitles_zip.namelist()[0]).read()
        except Exception as e:
            raise Error("Unable to unzip the subtitles file: {0}.", e)
github KonishchevDmitry / pysd / pysd.py View on Github external
elif option in ("-r", "--recursive"):
                    recursive = True
                elif option in ("-o", "--opensubtitles"):
                    use_opensubtitles = True
                else:
                    raise Error("invalid option '{0}'", option)

            if not cmd_args:
                raise Error("there is no TV show video file or TV show directory specified")

            if not languages:
                raise Error("there is no subtitles languages specified")

            return (languages, use_opensubtitles, cmd_args, recursive)
        except Exception as e:
            raise Fatal_error("Command line options parsing error: {0}. See `{1} -h` for more information.", e, argv[0])
github KonishchevDmitry / pysd / pysd.py View on Github external
# Getting only one subtitle with the most downloads per
                # language.
                # -->
                subtitles_list.sort(
                    key = lambda subtitle: ( subtitle["language"], subtitle["downloads"] ), reverse = True)

                for subtitles in subtitles_list:
                    if subtitles["language"] not in subtitles_dict:
                        subtitles_dict[subtitles["language"]] = subtitles["id"]
                # <--

                episode["subtitles"] = subtitles_dict

            return episode["subtitles"]
        except Exception as e:
            raise Fatal_error("Unable to get subtitles list from {0}: {1}.", self.__domain_name, e)
github KonishchevDmitry / pysd / pysd.py View on Github external
def __connect(self):
        """Ensures that we are connected to the XML-RPC server."""

        try:
            if self.__connection == None or not self.__token:
                self.__connection = xmlrpclib.ServerProxy(
                    "http://api.opensubtitles.org/xml-rpc", transport = Xml_rpc_proxy(), allow_none = True )
                self.__token = self.__call("LogIn", "", "", "en", "pysd 0.1")["token"]
        except Exception as e:
            raise Fatal_error("Unable to connect to {0} XML-RPC server: {1}.", self.__domain_name, e)
github KonishchevDmitry / pysd / pysd.py View on Github external
def __init__(self, use_datetime = 0):
        xmlrpclib.Transport.__init__(self, use_datetime)

        proxy = urllib.getproxies().get("http", "").strip()

        if proxy:
            if proxy.startswith("http://") and urlparse(proxy).netloc:
                self.proxy = urlparse(proxy).netloc
            else:
                raise Fatal_error("invalid HTTP proxy specified ({0})", proxy)
github KonishchevDmitry / pysd / pysd.py View on Github external
self.__cache[movie_path] = {}

                    for language in languages:
                        self.__cache[movie_path][language] = None

                    errors.append(str(e))
            # Hashing the files <--

            # Getting available subtitles -->
            if movies:
                self.__connect()

                try:
                    subtitles_list = self.__call("SearchSubtitles", self.__token, movies)["data"]
                except Exception as e:
                    raise Fatal_error("Unable to get a list of subtitles from {0}: {1}.", self.__domain_name, e)

                subtitles_dict = {}

                # Filtering the subtitles with the most downloads count -->
                if subtitles_list:
                    subtitles_list.sort(key = lambda subtitle: (
                        subtitle["MovieHash"],
                        subtitle["ISO639"],
                        subtitle["SubDownloadsCnt"],
                    ), reverse = True)

                    for subtitles in subtitles_list:
                        subtitles_dict.setdefault(subtitles["MovieHash"], {}).setdefault(
                            subtitles["ISO639"], subtitles["SubDownloadLink"])
                # Filtering the subtitles with the most downloads count <--
            # Getting available subtitles <--