예제 #1
0
    def test_renaming_subs(self):
        source_files = [
            'a_movie_with_subs/Another.Another.S02E03.bigfile.mp4',
            'a_movie_with_subs/intetest/Other.Other.Other.Other.S09E01.something.something-something[something].swe.srt',
            'a_movie_with_subs/Other.Other.Other.Other.S09E01.something.something-something[something].smi',
            'a_movie_with_subs/[ www.flobbing.com ] - /Other.Other.Other.Other.S09E01.something.something-something[something].ssa',
            'a_movie_with_subs/[ www.flobbing.com ] - Longer.S01E02.HaHV.Maam-A/Information Downloaded From www.akkero.com.ass',
            'a_movie_with_subs/a/b/www.Lobertar.com - Long.S01E02.720p.KOOK.asdf-Risig/Stuff from www.Lobertar.com.vtt',
            'a_movie_with_subs/www.Lobertar.com - Long.S01E02.720p.KOOK.asdf-Risig/Stuff from www.Lobertar.com.txt',
            'a_movie_with_subs/intetest/Other.Other.Other.Other.S09E01.something.something-something[something].eng.srt'
        ]

        subtitles_file = [
            'a_movie_with_subs/Another.Another.S02E03.bigfile.en3.smi',
            'a_movie_with_subs/Another.Another.S02E03.bigfile.en.ass',
            'a_movie_with_subs/Another.Another.S02E03.bigfile.en5.vtt',
            'a_movie_with_subs/Another.Another.S02E03.bigfile.en4.ssa',
            'a_movie_with_subs/Another.Another.S02E03.bigfile.en2.srt',
            'a_movie_with_subs/Another.Another.S02E03.bigfile.sv.srt',
        ]

        # Create source files
        for source_file in source_files:
            self._createSourceFile(source_file)

        # make the first file the biggest
        self._set_size_in_mb(source_files[0], 60)

        subtitles.rename_and_move(self._SOURCE_DIRECTORY)

        for path in subtitles_file:
            self.assertTrue(file_handler.file_exist(self._SOURCE_DIRECTORY + path))

        #  assert that none sub files have not changed
        self.assertTrue(file_handler.file_exist(self._SOURCE_DIRECTORY + source_files[0]))

        self.assertFalse(
            file_handler.directory_exist(file_handler.get_parent(self._SOURCE_DIRECTORY + source_files[1]))
        )

        self.assertFalse(
            file_handler.file_exist(self._SOURCE_DIRECTORY + source_files[2])
        )

        self.assertFalse(
            file_handler.directory_exist(file_handler.get_parent(self._SOURCE_DIRECTORY + source_files[3]))
        )

        self.assertFalse(
            file_handler.file_exist(file_handler.get_parent(self._SOURCE_DIRECTORY + source_files[4]))
        )

        self.assertFalse(
            file_handler.directory_exist('testing/1')
        )

        self.assertTrue(file_handler.file_exist(self._SOURCE_DIRECTORY + source_files[6]))
예제 #2
0
def __move_subtitle(subtitle_path, source_directory):
    for biggest_file in file_handler.get_biggest_files(
            file_handler.get_parent(subtitle_path), source_directory):
        if media_file_extractor.is_media_file(biggest_file.path):
            destination_path = file_handler.get_parent(
                biggest_file.path) + '/' + file_handler.get_last_path_part(
                    subtitle_path)

            file_handler.move(subtitle_path, destination_path)
            __delete_empty_parents(subtitle_path, source_directory)
            return destination_path
예제 #3
0
 def test_get_biggest_file(self):
     file_path = self._createSourceFile('a/b/c/d/e/f/g.aa')
     directory_path = file_handler.get_parent(file_path)
     biggest_files = list(
         file_handler.get_biggest_files(directory_path,
                                        self._SOURCE_DIRECTORY))
     self.assertEqual(1, len(biggest_files))
     self.assertEqual(file_path, biggest_files[0].path)
예제 #4
0
def __calculate_index(language_code, file_path):
    dir = file_handler.get_parent(file_path)
    files_in_dir = file_handler.get_directory_content(dir)
    files = [
        file for file in files_in_dir
        if re.search(r'\.' + language_code + r'\d*\.', file) is not None
    ]
    index = len(files)
    return '' if index == 0 else str(index + 1)
예제 #5
0
def __should_be_moved(subtitle_path):
    if not subtitle_path.endswith(__subtitle_types):
        return False

    subtitle_dir = file_handler.get_parent(subtitle_path)
    biggest_file = file_handler.get_biggest_file(subtitle_dir)
    if media_file_extractor.is_media_file(biggest_file.path):
        return False

    return True
예제 #6
0
def __should_be_renamed(subtitle_path):
    if not subtitle_path.endswith(__subtitle_types):
        return False

    subtitle_dir = file_handler.get_parent(subtitle_path)
    biggest_file = file_handler.get_biggest_file(subtitle_dir)
    if not media_file_extractor.is_media_file(biggest_file.path):
        return False  # No media file. Nothing to rename to

    biggest_file_name = file_handler.get_last_path_part(biggest_file.path)
    subtitle_file_name = file_handler.get_last_path_part(subtitle_path)

    # should be moved if subtitle is not already named after media file in directory
    return subtitle_file_name.find(biggest_file_name) == -1
예제 #7
0
def __rename(file_path):
    subtitle_type = file_handler.get_file_type(file_path)

    biggest_file = file_handler.get_biggest_file(
        file_handler.get_parent(file_path))
    if not media_file_extractor.is_media_file(biggest_file.path):
        return

    language_code = __identify_language(file_path)
    index = __calculate_index(language_code, file_path)

    destination_path = file_handler.get_path_without_extension(
        biggest_file.path) + '.' + language_code + index + subtitle_type

    file_handler.move(file_path, destination_path)
예제 #8
0
def __delete_empty_parents(path, source_directory):
    current_parent = file_handler.get_parent(path)
    while current_parent != source_directory and file_handler.directory_is_empty(
            current_parent):
        file_handler.delete_directory(current_parent)
        current_parent = file_handler.get_parent(current_parent)