Example #1
0
    def __init__(self, file_name, dest, testing):

        match = FILE_WELL_FORMATTED_PATTERN.search(file_name)
        try:
            if match:
                self.season = match.group("season")
                self.episode = match.group("episode")
                self.episode_title = match.group("episode_title")
                self.extension = match.group("extension")
                self.show_name = file_name.split(self.season)[0].strip()

                name_tmp = "{0}x{1}".format(self.season, self.episode)

                if self.episode_title and (self.episode_title != ""):
                    name_tmp = "{0} - {1}".format(name_tmp, self.episode_title)

                file_final_name = "{0}.{1}".format(name_tmp, self.extension)

                if self.__path_exists(dest):
                    self.season_path = "{0} {1}".format(SEASON_PATH_NAME, self.season)
                    if not self.__season_exists(dest):
                        self.__create_season_dir(dest, testing)

                    self.final_destination = os.path.join(dest, self.show_name, self.season_path, file_final_name)
        except Exception as e:
            print_exception(e)
Example #2
0
    def __init__(self, file_name, dest, testing):

        match = FILE_WELL_FORMATTED_PATTERN.search(file_name)
        try:
            if match:
                self.season = match.group("season")
                self.episode = match.group("episode")
                self.episode_title = match.group("episode_title")
                self.extension = match.group("extension")
                self.show_name = file_name.split(self.season)[0].strip()

                name_tmp = "{0}x{1}".format(self.season, self.episode)

                if self.episode_title and (self.episode_title != ""):
                    name_tmp = "{0} - {1}".format(name_tmp, self.episode_title)

                file_final_name = "{0}.{1}".format(name_tmp, self.extension)

                if self.__path_exists(dest):
                    self.season_path = "{0} {1}".format(
                        SEASON_PATH_NAME, self.season)
                    if not self.__season_exists(dest):
                        self.__create_season_dir(dest, testing)

                    self.final_destination = os.path.join(
                        dest, self.show_name, self.season_path,
                        file_final_name)
        except Exception as e:
            print_exception(e)
def __get_best_quality(path, repeated_episodes, testing):
    """
    __get_best_quality(dest_path, episodes)
        Looking videos with best quality among the repeated videos.
    Arguments:
        - dest_path: Current dest_path for video files_in_path.
        - repeated_episodes: List of repeated episodes in the dest_path.
    """

    files_in_path = []

    for f in os.listdir(path):
        file_absolute_path = os.path.join(path, f)
        if os.path.isfile(file_absolute_path):
            files_in_path.append(file_absolute_path)

    if files_in_path:
        for episode in repeated_episodes:

            relative_path = path.replace(path, "")
            print_repeated_file(os.path.join(relative_path, episode))

            best_file, discarted_files = __get_best_file(
                episode, files_in_path)

            print_best_file(best_file)

            for f in discarted_files:
                print_rm(f)

                if not testing:
                    try:
                        os.remove(f)
                    except Exception as e:
                        print_exception(e)
def get_plugin_instance(plugin_name):
    try:
        class_name = inspect.getmembers(plugin_name, inspect.isclass)[1][0]
        plugin_class = getattr(plugin_name, class_name)
        plugin_instance = plugin_class()

        return plugin_instance
    except Exception as e:
        print_exception(e)
def get_plugin_instance(plugin_name):
    try:
        class_name = inspect.getmembers(plugin_name, inspect.isclass)[1][0]
        plugin_class = getattr(plugin_name, class_name)
        plugin_instance = plugin_class()

        return plugin_instance
    except Exception as e:
        print_exception(e)
def execute_plugin(plugin, f):
    try:
        video = _get_file_info(f)

        plugin = get_plugin_instance(plugin)
        file_found = getattr(plugin, "download")(f)

        return file_found
    except Exception as e:
        print_exception(e)
def execute_plugin(plugin, f):
    try:
        video = _get_file_info(f)

        plugin = get_plugin_instance(plugin)
        file_found = getattr(plugin, "download")(f)

        return file_found
    except Exception as e:
        print_exception(e)
Example #8
0
    def _rename_file(self, testing):
        """
        _rename_file(self)
            Renames a file with a new name.
        """

        try:
            if self.new_file_name and self.new_file_name != self.file_name:
                self.new_path = os.path.join(self.path, self.new_file_name)

                mv(self.original_path, self.new_path, testing)

        except Exception as ex:
            print_exception(ex)
Example #9
0
    def __write_header(self):
        """
        __write_header(self)
            Writes CSV file header.
        """

        try:
            f_log = open(self.file_name, 'w')
            f_log.write('#File name, Path, Title, Author, Creator, Subject,'
                        ' Producer, Creation date, Modification date,'
                        ' Encrypted, Pages, Size, Keywords\n')
            f_log.close()
        except Exception as ex:
            print_exception(ex)
Example #10
0
    def _rename_file(self, testing):
        """
        _rename_file(self)
            Renames a file with a new name.
        """

        try:
            if self.new_file_name and self.new_file_name != self.file_name:
                self.new_path = os.path.join(self.path, self.new_file_name)

                mv(self.original_path, self.new_path, testing)

        except Exception as ex:
            print_exception(ex)
Example #11
0
    def __write_header(self):
        """
        __write_header(self)
            Writes CSV file header.
        """

        try:
            f_log = open(self.file_name, 'w')
            f_log.write('#File name, Title, Author, Creator, Subject,'
                        ' Producer, Creation date, Modification date,'
                        ' Encrypted, Pages, Size\n')
            f_log.close()
        except Exception as ex:
            print_exception(ex)
Example #12
0
def _load_modules(plugins):
    try:
        loaded_modules = []

        for plugin in plugins:
            plugin_name = os.path.splitext(plugin)[0]
            plugins_module = ".get_subs_plugins"
            plugin_relative_path = "{0}.{1}".format(plugins_module, plugin_name)
            plugin_loaded = importlib.import_module(plugin_relative_path, __package__)
            loaded_modules.append(plugin_loaded)
            print_info("\t+ {0} loaded".format(plugin_name))

        return loaded_modules
    except Exception as e:
        print_exception(e)
Example #13
0
    def write(self, metadata):
        try:
            f_log = open(self.file_name, 'a+')
            if metadata.name:
                f_log.write('File: {0}\n'.format(metadata.name))

            if metadata.absolute_path:
                f_log.write('Path: {0}\n'.format(metadata.absolute_path))

            if metadata.title:
                f_log.write('Title: {0}\n'.format(metadata.title))

            if metadata.author:
                f_log.write('Author: {0}\n'.format(metadata.author))

            if metadata.creator:
                f_log.write('Creator: {0}\n'.format(metadata.creator))

            if metadata.subject:
                f_log.write('Subject: {0}\n'.format(metadata.subject))

            if metadata.producer:
                f_log.write('Producer: {0}\n'.format(metadata.producer))

            if metadata.creation_date:
                f_log.write('Creation date: {0}\n'.format(
                    metadata.creation_date))

            if metadata.modification_date:
                f_log.write('Modification date: {0}\n'.format(
                    metadata.modification_date))

            f_log.write('Encrypted: {0}\n'.format(metadata.encrypted))

            if metadata.num_pages:
                f_log.write('Pages: {0}\n'.format(metadata.num_pages))

            if metadata.size:
                f_log.write('Size: {0}\n'.format(metadata.size))

            if metadata.keywords:
                f_log.write('Keywords: {0}\n'.format(metadata.keywords))

            f_log.write('\n')
            f_log.close()
        except Exception as ex:
            print_exception(ex)
Example #14
0
def _load_modules(plugins):
    try:
        loaded_modules = []

        for plugin in plugins:
            plugin_name = os.path.splitext(plugin)[0]
            plugins_module = ".get_subs_plugins"
            plugin_relative_path = "{0}.{1}".format(plugins_module,
                                                    plugin_name)
            plugin_loaded = importlib.import_module(plugin_relative_path,
                                                    __package__)
            loaded_modules.append(plugin_loaded)
            print_info("\t+ {0} loaded".format(plugin_name))

        return loaded_modules
    except Exception as e:
        print_exception(e)
Example #15
0
    def write(self, metadata):
        try:
            f_log = open(self.file_name, 'a+')
            if metadata.name:
                f_log.write('File: {0}\n'.format(metadata.name))

            if metadata.absolute_path:
                f_log.write('Path: {0}\n'.format(metadata.absolute_path))

            if metadata.title:
                f_log.write('Title: {0}\n'.format(metadata.title))

            if metadata.author:
                f_log.write('Author: {0}\n'.format(metadata.author))

            if metadata.creator:
                f_log.write('Creator: {0}\n'.format(metadata.creator))

            if metadata.subject:
                f_log.write('Subject: {0}\n'.format(metadata.subject))

            if metadata.producer:
                f_log.write('Producer: {0}\n'.format(metadata.producer))

            if metadata.creation_date:
                f_log.write('Creation date: {0}\n'.format(metadata.creation_date))

            if metadata.modification_date:
                f_log.write('Modification date: {0}\n'.format(metadata.modification_date))

            f_log.write('Encrypted: {0}\n'.format(metadata.encrypted))

            if metadata.num_pages:
                f_log.write('Pages: {0}\n'.format(metadata.num_pages))

            if metadata.size:
                f_log.write('Size: {0}\n'.format(metadata.size))

            f_log.write('\n')
            f_log.close()
        except Exception as ex:
            print_exception(ex)
Example #16
0
def _get_plugins(path):

    plugins = []

    try:
        plugins_path_files = os.listdir(path)

        for f in plugins_path_files:
            f_abs_path = os.path.join(path, f)
            if os.path.isfile(f_abs_path):
                if is_python(f_abs_path):
                    plugins.append(f)

        plugins.remove("__init__.py")
        plugins.remove("get_sub_plugin.py")

        return plugins
    except ValueError:
        pass
    except Exception as e:
        print_exception(e)
Example #17
0
def get_metadata(file_path):
    """
    get_metadata(file_path)
        Defined to use the script as a module.

    Arguments:
        file_path: (string) Absolute file path.
    """

    metadata = None

    if file_path.lower().endswith('.pdf'):
        try:
            metadata = Metadata(file_path)
            metadata.print_info()
        except Exception as ex:
            print_exception(ex)
    else:
        print_error('{0} is not a PDF file.'.format(file_path))

    return metadata
Example #18
0
def _get_plugins(path):

    plugins = []

    try:
        plugins_path_files = os.listdir(path)

        for f in plugins_path_files:
            f_abs_path = os.path.join(path, f)
            if os.path.isfile(f_abs_path):
                if is_python(f_abs_path):
                    plugins.append(f)

        plugins.remove("__init__.py")
        plugins.remove("get_sub_plugin.py")

        return plugins
    except ValueError:
        pass
    except Exception as e:
        print_exception(e)
Example #19
0
def get_metadata(file_path):
    """
    get_metadata(file_path)
        Defined to use the script as a module.

    Arguments:
        file_path: (string) Absolute file path.
    """

    metadata = None

    if file_path.lower().endswith('.pdf'):
        try:
            metadata = Metadata(file_path)
            metadata.print_info()
        except Exception as ex:
            print_exception(ex)
    else:
        print_error('{0} is not a PDF file.'.format(file_path))

    return metadata
def handle_exception(function, e):
    print_exception("{0}: {1}".format(function, e))
    exit(2)
Example #21
0
def handle_exception(e):
    print_exception(e)
    exit(2)
Example #22
0
    def write(self, metadata):
        try:
            f_log = open(self.file_name, 'a+')
            if metadata.name:
                f_log.write(metadata.name)

            f_log.write(self.field_separator)

            if metadata.absolute_path:
                f_log.write(metadata.absolute_path)

            f_log.write(self.field_separator)

            if metadata.title:
                f_log.write(metadata.title)

            f_log.write(self.field_separator)

            if metadata.author:
                f_log.write(metadata.author)

            f_log.write(self.field_separator)

            if metadata.creator:
                f_log.write(metadata.creator)

            f_log.write(self.field_separator)

            if metadata.subject:
                f_log.write(metadata.subject)

            f_log.write(self.field_separator)

            if metadata.producer:
                f_log.write(metadata.producer)

            f_log.write(self.field_separator)

            if metadata.creation_date:
                f_log.write(metadata.creation_date)

            f_log.write(self.field_separator)

            if metadata.modification_date:
                f_log.write(metadata.modification_date)

            f_log.write(self.field_separator)

            f_log.write(metadata.encrypted)
            f_log.write(self.field_separator)

            if metadata.num_pages:
                f_log.write(metadata.num_pages)

            f_log.write(self.field_separator)

            if metadata.size:
                f_log.write(metadata.size)

            f_log.write(self.field_separator)

            if metadata.keywords:
                f_log.write(metadata.keywords)

            f_log.write('\n')
            f_log.close()

        except Exception as ex:
            print_exception(ex)
Example #23
0
    def write(self, metadata):
        try:
            f_log = open(self.file_name, 'a+')
            if metadata.name:
                f_log.write(metadata.name)

            f_log.write(self.field_separator)

            if metadata.absolute_path:
                f_log.write(metadata.absolute_path)

            f_log.write(self.field_separator)

            if metadata.title:
                f_log.write(metadata.title)

            f_log.write(self.field_separator)

            if metadata.author:
                f_log.write(metadata.author)

            f_log.write(self.field_separator)

            if metadata.creator:
                f_log.write(metadata.creator)

            f_log.write(self.field_separator)

            if metadata.subject:
                f_log.write(metadata.subject)

            f_log.write(self.field_separator)

            if metadata.producer:
                f_log.write(metadata.producer)

            f_log.write(self.field_separator)

            if metadata.creation_date:
                f_log.write(metadata.creation_date)

            f_log.write(self.field_separator)

            if metadata.modification_date:
                f_log.write(metadata.modification_date)

            f_log.write(self.field_separator)

            f_log.write(metadata.encrypted)
            f_log.write(self.field_separator)

            if metadata.num_pages:
                f_log.write(metadata.num_pages)

            f_log.write(self.field_separator)

            if metadata.size:
                f_log.write(metadata.size)

            f_log.write('\n')
            f_log.close()

        except Exception as ex:
            print_exception(ex)
def handle_exception(e):
    print_exception(e)
    exit(1)