Example #1
0
    def initialize(self):
        self.fs_encoding = get_viable_encoding()
        self.version = self.get_version()
        self.full_version = u"%s %s" % (PLUGIN_NAME, self.version)

        self.set_plugin_mode()
        self.set_plugin_lock()

        self.lang_list = self.get_lang_list()
        self.subtitle_destination_folder = self.get_subtitle_destination_folder(
        )
        self.providers = self.get_providers()
        self.provider_settings = self.get_provider_settings()
        self.max_recent_items_per_library = int_or_default(
            Prefs["scheduler.max_recent_items_per_library"], 2000)
        self.sections = list(Plex["library"].sections())
        self.missing_permissions = []
        self.ignore_sz_files = cast_bool(Prefs["subtitles.ignore_fs"])
        self.ignore_paths = self.parse_ignore_paths()
        self.enabled_sections = self.check_enabled_sections()
        self.permissions_ok = self.check_permissions()
        self.notify_executable = self.check_notify_executable()
        self.enforce_encoding = cast_bool(Prefs['subtitles.enforce_encoding'])
        self.chmod = self.check_chmod()
        self.forced_only = cast_bool(Prefs["subtitles.only_foreign"])
        self.initialized = True
Example #2
0
    def initialize(self):
        self.libraries_root = os.path.abspath(
            os.path.join(get_root_path(), ".."))
        self.init_libraries()

        self.fs_encoding = get_viable_encoding()
        self.plugin_info = self.get_plugin_info()
        self.is_development = self.get_dev_mode()
        self.version = self.get_version()
        self.full_version = u"%s %s" % (PLUGIN_NAME, self.version)
        self.set_log_paths()
        self.app_support_path = Core.app_support_path
        self.data_path = getattr(Data, "_core").storage.data_path
        self.data_items_path = os.path.join(self.data_path, "DataItems")
        self.universal_plex_token = self.get_universal_plex_token()
        self.plex_token = os.environ.get("PLEXTOKEN",
                                         self.universal_plex_token)

        os.environ["SZ_USER_AGENT"] = self.get_user_agent()

        self.providers = self.get_providers()

        self.set_plugin_mode()
        self.set_plugin_lock()
        self.set_activity_modes()

        self.lang_list = self.get_lang_list()
        self.subtitle_destination_folder = self.get_subtitle_destination_folder(
        )
        self.subtitle_formats = self.get_subtitle_formats()
        self.forced_only = cast_bool(Prefs["subtitles.only_foreign"])
        self.provider_settings = self.get_provider_settings()
        self.max_recent_items_per_library = int_or_default(
            Prefs["scheduler.max_recent_items_per_library"], 2000)
        self.sections = list(Plex["library"].sections())
        self.missing_permissions = []
        self.ignore_sz_files = cast_bool(Prefs["subtitles.ignore_fs"])
        self.ignore_paths = self.parse_ignore_paths()
        self.enabled_sections = self.check_enabled_sections()
        self.permissions_ok = self.check_permissions()
        self.notify_executable = self.check_notify_executable()
        self.remove_hi = cast_bool(Prefs['subtitles.remove_hi'])
        self.fix_ocr = cast_bool(Prefs['subtitles.fix_ocr'])
        self.fix_common = cast_bool(Prefs['subtitles.fix_common'])
        self.colors = Prefs['subtitles.colors'] if Prefs[
            'subtitles.colors'] != "don't change" else None
        self.chmod = self.check_chmod()
        self.exotic_ext = cast_bool(Prefs["subtitles.scan.exotic_ext"])
        self.treat_und_as_first = cast_bool(
            Prefs["subtitles.language.treat_und_as_first"])
        self.ext_match_strictness = self.determine_ext_sub_strictness()
        self.default_mods = self.get_default_mods()
        self.debug_mods = cast_bool(Prefs['log_debug_mods'])
        self.subtitles_save_to = Prefs['subtitles.save.filesystem']
        self.no_refresh = os.environ.get("SZ_NO_REFRESH", False)
        self.initialized = True
Example #3
0
    def initialize(self):
        self.libraries_root = os.path.abspath(
            os.path.join(get_root_path(), ".."))
        self.init_libraries()

        if is_windows_special_path:
            Log.Warn(
                "The Plex metadata folder is residing inside a folder with special characters. "
                "Multithreading and playback activities will be disabled.")

        self.fs_encoding = get_viable_encoding()
        self.plugin_info = self.get_plugin_info()
        self.is_development = self.get_dev_mode()
        self.version = self.get_version()
        self.full_version = u"%s %s" % (PLUGIN_NAME, self.version)
        self.set_log_paths()
        self.app_support_path = Core.app_support_path
        self.data_path = getattr(Data, "_core").storage.data_path
        self.data_items_path = os.path.join(self.data_path, "DataItems")
        self.universal_plex_token = self.get_universal_plex_token()
        self.plex_token = os.environ.get("PLEXTOKEN",
                                         self.universal_plex_token)
        subzero.constants.DEFAULT_TIMEOUT = lib.DEFAULT_TIMEOUT = self.pms_request_timeout = \
            min(cast_int(Prefs['pms_request_timeout'], 15), 45)
        self.low_impact_mode = cast_bool(Prefs['low_impact_mode'])
        self.new_style_cache = cast_bool(Prefs['new_style_cache'])
        self.pack_cache_dir = self.get_pack_cache_dir()
        self.advanced = self.get_advanced_config()

        os.environ["SZ_USER_AGENT"] = self.get_user_agent()

        self.setup_proxies()
        self.set_plugin_mode()
        self.set_plugin_lock()
        self.set_activity_modes()
        self.parse_rename_mode()

        self.subtitle_destination_folder = self.get_subtitle_destination_folder(
        )
        self.subtitle_formats = self.get_subtitle_formats()
        self.forced_only = cast_bool(Prefs["subtitles.only_foreign"])
        self.max_recent_items_per_library = int_or_default(
            Prefs["scheduler.max_recent_items_per_library"], 2000)
        self.sections = list(Plex["library"].sections())
        self.missing_permissions = []
        self.ignore_sz_files = cast_bool(Prefs["subtitles.ignore_fs"])
        self.ignore_paths = self.parse_ignore_paths()
        self.enabled_sections = self.check_enabled_sections()
        self.permissions_ok = self.check_permissions()
        self.notify_executable = self.check_notify_executable()
        self.remove_hi = cast_bool(Prefs['subtitles.remove_hi'])
        self.remove_tags = cast_bool(Prefs['subtitles.remove_tags'])
        self.fix_ocr = cast_bool(Prefs['subtitles.fix_ocr'])
        self.fix_common = cast_bool(Prefs['subtitles.fix_common'])
        self.reverse_rtl = cast_bool(Prefs['subtitles.reverse_rtl'])
        self.colors = Prefs['subtitles.colors'] if Prefs[
            'subtitles.colors'] != "don't change" else None
        self.chmod = self.check_chmod()
        self.exotic_ext = cast_bool(Prefs["subtitles.scan.exotic_ext"])
        self.treat_und_as_first = cast_bool(
            Prefs["subtitles.language.treat_und_as_first"])
        self.subtitle_sub_dir = self.get_subtitle_sub_dir()
        self.ext_match_strictness = self.determine_ext_sub_strictness()
        self.default_mods = self.get_default_mods()
        self.debug_mods = cast_bool(Prefs['log_debug_mods'])
        self.no_refresh = os.environ.get("SZ_NO_REFRESH", False)
        self.plex_transcoder = self.get_plex_transcoder()
        self.only_one = cast_bool(Prefs['subtitles.only_one'])
        self.embedded_auto_extract = cast_bool(
            Prefs["subtitles.embedded.autoextract"])
        self.ietf_as_alpha3 = cast_bool(
            Prefs["subtitles.language.ietf_normalize"])
        self.initialized = True
Example #4
0
# coding=utf-8
from xmlrpclib import SafeTransport, ProtocolError, Fault, Transport

import certifi
import ssl
import os
import socket
from requests import Session, exceptions
from retry.api import retry_call

from subzero.lib.io import get_viable_encoding

pem_file = os.path.normpath(os.path.join(os.path.dirname(os.path.realpath(unicode(__file__, get_viable_encoding()))), "..", certifi.where()))
try:
    default_ssl_context = ssl.create_default_context(cafile=pem_file)
except AttributeError:
    # < Python 2.7.9
    default_ssl_context = None


class RetryingSession(Session):
    proxied_functions = ("get", "post")

    def __init__(self):
        super(RetryingSession, self).__init__()
        self.verify = pem_file

    def retry_method(self, method, *args, **kwargs):
        return retry_call(getattr(super(RetryingSession, self), method), fargs=args, fkwargs=kwargs, tries=3, delay=5,
                          exceptions=(exceptions.ConnectionError,
                                      exceptions.ProxyError,
Example #5
0
# coding=utf-8
from xmlrpclib import SafeTransport

import certifi
import ssl
import os
import socket
from requests import Session, exceptions
from retry.api import retry_call

from subzero.lib.io import get_viable_encoding

pem_file = os.path.normpath(
    os.path.join(
        os.path.dirname(
            os.path.realpath(unicode(__file__, get_viable_encoding()))), "..",
        certifi.where()))
try:
    default_ssl_context = ssl.create_default_context(cafile=pem_file)
except AttributeError:
    # < Python 2.7.9
    default_ssl_context = None


class RetryingSession(Session):
    proxied_functions = ("get", "post")

    def __init__(self):
        super(RetryingSession, self).__init__()
        self.verify = pem_file
Example #6
0
from subliminal_patch.http import RetryingSession
from subliminal_patch.subtitle import Subtitle, guess_matches

from subzero.lib.io import get_viable_encoding


class Provider(_Provider):
    hash_verifiable = False
    hearing_impaired_verifiable = False
    skip_wrong_fps = True


# register providers
# fixme: this is bad
for name in os.listdir(
        os.path.dirname(unicode(__file__, get_viable_encoding()))):
    if name in ("__init__.py", "mixins.py",
                "utils.py") or not name.endswith(".py"):
        continue

    module_name = os.path.splitext(name)[0]
    mod = importlib.import_module("subliminal_patch.providers.%s" %
                                  module_name.lower())
    for item in dir(mod):
        cls = getattr(mod, item)
        if item != "Provider" and item.endswith(
                "Provider") and not item.startswith("_"):
            is_sz_provider = issubclass(cls, Provider)
            is_provider = issubclass(cls, _Provider)

            if not is_provider:
Example #7
0
def get_root_path():
    return os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(unicode(__file__, get_viable_encoding()))), ".."))
Example #8
0
from urllib3.util import connection
from retry.api import retry_call
from exceptions import APIThrottled
from dogpile.cache.api import NO_VALUE
from subliminal.cache import region
from cfscrape import CloudflareScraper

try:
    from urlparse import urlparse
except ImportError:
    from urllib.parse import urlparse

from subzero.lib.io import get_viable_encoding

logger = logging.getLogger(__name__)
pem_file = os.path.normpath(os.path.join(os.path.dirname(os.path.realpath(unicode(__file__, get_viable_encoding()))), "..", certifi.where()))
try:
    default_ssl_context = ssl.create_default_context(cafile=pem_file)
except AttributeError:
    # < Python 2.7.9
    default_ssl_context = None


class TimeoutSession(requests.Session):
    timeout = 10

    def __init__(self, timeout=None):
        super(TimeoutSession, self).__init__()
        self.timeout = timeout or self.timeout

    def request(self, method, url, *args, **kwargs):
Example #9
0
    def initialize(self):
        self.libraries_root = os.path.abspath(os.path.join(get_root_path(), ".."))
        self.init_libraries()

        if is_windows_special_path:
            Log.Warn("The Plex metadata folder is residing inside a folder with special characters. "
                     "Multithreading and playback activities will be disabled.")

        self.fs_encoding = get_viable_encoding()
        self.plugin_info = self.get_plugin_info()
        self.is_development = self.get_dev_mode()
        self.version = self.get_version()
        self.full_version = u"%s %s" % (PLUGIN_NAME, self.version)
        self.set_log_paths()
        self.app_support_path = Core.app_support_path
        self.data_path = getattr(Data, "_core").storage.data_path
        self.data_items_path = os.path.join(self.data_path, "DataItems")
        self.universal_plex_token = self.get_universal_plex_token()
        self.plex_token = os.environ.get("PLEXTOKEN", self.universal_plex_token)
        self.new_style_cache = cast_bool(Prefs['new_style_cache'])
        self.pack_cache_dir = self.get_pack_cache_dir()
        try:
            self.migrate_prefs()
        except:
            Log.Exception("Catastrophic failure when running prefs migration")

        subzero.constants.DEFAULT_TIMEOUT = lib.DEFAULT_TIMEOUT = self.pms_request_timeout = \
            min(cast_int(Prefs['pms_request_timeout'], 15), 45)
        self.low_impact_mode = cast_bool(Prefs['low_impact_mode'])
        self.advanced = self.get_advanced_config()
        self.debug_i18n = self.advanced.debug_i18n

        os.environ["SZ_USER_AGENT"] = self.get_user_agent()
        os.environ["ANTICAPTCHA_ACCOUNT_KEY"] = self.anticaptcha_token = str(Prefs["anticaptcha.api_key"]) or ""
        acs = str(Prefs["anticaptcha.service"])
        if acs and acs != "none":
            os.environ["ANTICAPTCHA_CLASS"] = self.anticaptcha_cls = acs
        self.has_anticaptcha = self.anticaptcha_token and self.anticaptcha_cls

        self.setup_proxies()
        self.set_plugin_mode()
        self.set_plugin_lock()
        self.set_activity_modes()
        self.parse_rename_mode()

        self.normal_subs = Prefs["subtitles.when"] != "Never"
        self.forced_also = self.normal_subs and Prefs["subtitles.when_forced"] != "Never"
        self.forced_only = not self.normal_subs and Prefs["subtitles.when_forced"] != "Never"
        self.include = \
            Prefs["subtitles.include_exclude_mode"] == "disable SZ for all items by default, use include lists"
        self.subtitle_destination_folder = self.get_subtitle_destination_folder()
        self.subtitle_formats = self.get_subtitle_formats()
        self.max_recent_items_per_library = int_or_default(Prefs["scheduler.max_recent_items_per_library"], 2000)
        self.sections = list(Plex["library"].sections())
        self.missing_permissions = []
        self.include_exclude_sz_files = cast_bool(Prefs["subtitles.include_exclude_fs"])
        self.include_exclude_paths = self.parse_include_exclude_paths()
        self.enabled_sections = self.check_enabled_sections()
        self.permissions_ok = self.check_permissions()
        self.notify_executable = self.check_notify_executable()
        self.remove_hi = cast_bool(Prefs['subtitles.remove_hi'])
        self.remove_tags = cast_bool(Prefs['subtitles.remove_tags'])
        self.fix_ocr = cast_bool(Prefs['subtitles.fix_ocr'])
        self.fix_common = cast_bool(Prefs['subtitles.fix_common'])
        self.fix_upper = cast_bool(Prefs['subtitles.fix_only_uppercase'])
        self.reverse_rtl = cast_bool(Prefs['subtitles.reverse_rtl'])
        self.colors = Prefs['subtitles.colors'] if Prefs['subtitles.colors'] != "don't change" else None
        self.chmod = self.check_chmod()
        self.exotic_ext = cast_bool(Prefs["subtitles.scan.exotic_ext"])
        self.treat_und_as_first = cast_bool(Prefs["subtitles.language.treat_und_as_first"])
        self.subtitle_sub_dir = self.get_subtitle_sub_dir()
        self.ext_match_strictness = self.determine_ext_sub_strictness()
        self.default_mods = self.get_default_mods()
        self.debug_mods = cast_bool(Prefs['log_debug_mods'])
        self.no_refresh = os.environ.get("SZ_NO_REFRESH", False)
        self.plex_transcoder = self.get_plex_transcoder()
        self.only_one = cast_bool(Prefs['subtitles.only_one'])
        self.any_language_is_enough = Prefs['subtitles.any_language_is_enough']
        self.embedded_auto_extract = cast_bool(Prefs["subtitles.embedded.autoextract"])
        self.ietf_as_alpha3 = cast_bool(Prefs["subtitles.language.ietf_normalize"])
        self.use_custom_dns = self.parse_custom_dns()
        self.initialized = True
Example #10
0
def get_root_path():
    return os.path.abspath(
        os.path.join(
            os.path.dirname(
                os.path.abspath(six.text_type(__file__,
                                              get_viable_encoding()))), ".."))
Example #11
0
from subliminal_patch.extensions import provider_registry
from subliminal_patch.http import RetryingSession
from subliminal_patch.subtitle import Subtitle, guess_matches

from subzero.lib.io import get_viable_encoding


class Provider(_Provider):
    hash_verifiable = False
    hearing_impaired_verifiable = False
    skip_wrong_fps = True


# register providers
# fixme: this is bad
for name in os.listdir(os.path.dirname(unicode(__file__, get_viable_encoding()))):
    if name in ("__init__.py", "mixins.py", "utils.py") or not name.endswith(".py"):
        continue

    module_name = os.path.splitext(name)[0]
    mod = importlib.import_module("subliminal_patch.providers.%s" % module_name.lower())
    for item in dir(mod):
        cls = getattr(mod, item)
        if item != "Provider" and item.endswith("Provider") and not item.startswith("_"):
            is_sz_provider = issubclass(cls, Provider)
            is_provider = issubclass(cls, _Provider)

            if not is_provider:
                continue

            if not is_sz_provider:
Example #12
0
from subliminal.providers import Provider as _Provider
from subliminal.subtitle import Subtitle as _Subtitle
from subliminal_patch.extensions import provider_registry
from subliminal_patch.http import RetryingSession
from subliminal_patch.subtitle import Subtitle

from subzero.lib.io import get_viable_encoding

class Provider(_Provider):
    hash_verifiable = False
    hearing_impaired_verifiable = False
    skip_wrong_fps = True


# register providers
for name in os.listdir(os.path.dirname(unicode(__file__, get_viable_encoding()))):
    if name in ("__init__.py", "mixins.py", "utils.py") or not name.endswith(".py"):
        continue

    module_name = os.path.splitext(name)[0]
    mod = importlib.import_module("subliminal_patch.providers.%s" % module_name.lower())
    for item in dir(mod):
        if item.endswith("Provider") and not item.startswith("_"):
            provider_class = getattr(mod, item)
            is_sz_provider = issubclass(provider_class, Provider)

            if not is_sz_provider:
                # patch provider bases
                new_bases = []
                for base in provider_class.__bases__:
                    if issubclass(base, _Provider):