Example #1
0
    def test_init(self):
        extra = Extra("path", "showname", 1)

        self.assertIsInstance(extra, Container)
        self.assertIsInstance(extra, MediaLibrary)
        self.assertIsInstance(extra, Show)
        self.assertIsInstance(extra, Season)
        self.assertIsInstance(extra, Extra)

        extra = Extra("path", "showname", 1)
        self.assertIsNone(extra.parent())

        parent = Container()
        extra = Extra("path", "showname", 1, parent=parent)
        self.assertTrue(testutils.compare_containers(extra.parent(), parent))

        PATH = "path"
        extra = Extra(PATH, "showname", 1)
        season = Season(PATH, "showname", 1)
        self.assertEqual(PATH, season.path())

        SHOW_NAME = "showname"
        extra = Extra("path", SHOW_NAME, 1)
        self.assertEqual(extra.show_name(), SHOW_NAME)

        SEASON_NUMBER = 22
        extra = Extra("path", "showname", SEASON_NUMBER)
        self.assertEqual(extra.season_number(), SEASON_NUMBER)
Example #2
0
    def test_filter_season(self):
        from models.containers import Season

        base_path, file_paths = test_file_paths()
        create_test_files(self, file_paths)

        season = Season(base_path, "Show 1", 2)

        filtered_paths = Scanner.filter_season(season)

        self.assertEqual(1, len(filtered_paths))

        for filtered_path in filtered_paths:
            self.assertTrue(season.show_name() in filtered_path)

        remove_test_files(self, base_path, file_paths)
Example #3
0
    def test_scan_season(self):
        from models.containers import Season

        base_path, file_paths = test_file_paths()
        create_test_files(self, file_paths)

        container = Scanner.scan_season(Season(base_path, "Show 1", 1))
        self.assertEqual(len(container.containers), 0)
        self.assertEqual(len(container.media), 1)

        remove_test_files(self, base_path, file_paths)
Example #4
0
    def test_init(self):
        container = Container()

        self.assertIsInstance(container, Container)
        self.assertNotIsInstance(container, MediaLibrary)
        self.assertNotIsInstance(container, Show)
        self.assertNotIsInstance(container, Season)
        self.assertNotIsInstance(container, Extra)

        container = Container()
        self.assertIsNone(container.parent())

        parent = Container()
        container = Container(parent=parent)
        self.assertTrue(
            testutils.compare_containers(container.parent(), parent))

        container = Show("path", "showname")

        self.assertIsInstance(container, Container)
        self.assertIsInstance(container, MediaLibrary)
        self.assertIsInstance(container, Show)
        self.assertNotIsInstance(container, Season)
        self.assertNotIsInstance(container, Extra)

        container = Season("path", "showname", 1)

        self.assertIsInstance(container, Container)
        self.assertIsInstance(container, MediaLibrary)
        self.assertIsInstance(container, Show)
        self.assertIsInstance(container, Season)
        self.assertNotIsInstance(container, Extra)

        container = Extra("path", "showname", 1)

        self.assertIsInstance(container, Container)
        self.assertIsInstance(container, MediaLibrary)
        self.assertIsInstance(container, Show)
        self.assertIsInstance(container, Season)
        self.assertIsInstance(container, Extra)
Example #5
0
    def scan(file_paths, root_container):
        subtitle_cache = {}
        for file_path in file_paths:
            current_container = root_container

            show_name = File_name_parser.guess_show_name(file_path)
            year = File_name_parser.guess_year(file_path)
            season_number = File_name_parser.guess_season(file_path)
            episode_number = File_name_parser.guess_episode(file_path)
            is_media = File_name_parser.is_media(file_path)
            is_subtitle = File_name_parser.is_subtitle(file_path)
            is_extra = File_name_parser.is_extra(file_path)
            is_oad = File_name_parser.is_oad(file_path)
            is_ncop = File_name_parser.is_ncop(file_path)
            is_nced = File_name_parser.is_nced(file_path)
            is_ova = File_name_parser.is_ova(file_path)

            is_show = (season_number or episode_number or is_extra)
            is_movie = not is_show

            if not year:
                year = None

            if is_show:
                show = Show(root_container.path(),
                            show_name,
                            parent=current_container)
                show.set_year(year)

                existing = current_container.get_container(show.id())
                if existing:
                    show = existing
                else:
                    current_container.containers.append(show)

                current_container = show

                if season_number:
                    season = Season(root_container.path(),
                                    show_name,
                                    season_number,
                                    parent=current_container)
                    existing = current_container.get_container(season.id())
                    if existing:
                        season = existing
                    else:
                        current_container.containers.append(season)

                    current_container = season

                if is_extra:
                    extra = Extra(root_container.path(),
                                  show_name,
                                  season_number,
                                  parent=current_container)
                    existing = current_container.get_container(extra.id())
                    if existing:
                        extra = existing
                    else:
                        current_container.containers.append(extra)

                    current_container = extra

                if episode_number or is_extra:
                    media = Episode(file_path,
                                    episode_number,
                                    False,
                                    parent=current_container,
                                    is_oad=is_oad,
                                    is_ncop=is_ncop,
                                    is_nced=is_nced,
                                    is_ova=is_ova)
                    existing = current_container.get_media(media.id())
                    if existing:
                        media = existing
                    else:
                        current_container.media.append(media)

            elif is_movie:
                _show_name = show_name if not year else f'{show_name} ({year})'
                if is_subtitle:
                    added = False
                    for m in current_container.media:
                        if (isinstance(m, Movie) and m.title() == _show_name):
                            m.subtitles.append(file_path)
                            added = True
                            break

                    if not added:
                        subtitle_cache[_show_name] = file_path

                    continue

                media = Movie(file_path,
                              _show_name,
                              False,
                              parent=current_container)
                media.set_year(year)

                existing = current_container.get_media(media.id())
                if existing:
                    media = existing
                else:
                    current_container.media.append(media)

                if _show_name in subtitle_cache.keys():
                    media.subtitles.append(subtitle_cache.pop(_show_name))

            if media:
                if is_media:
                    media.file = file_path

                elif is_subtitle:
                    media.subtitles.append(file_path)

        return root_container
Example #6
0
 def test_season_number(self):
     SEASON_NUMBER = 22
     season = Season("path", "showname", SEASON_NUMBER)
     self.assertEqual(season.season_number(), SEASON_NUMBER)
Example #7
0
 def test_title(self):
     season = Season("path", "showname", 1)
     self.assertEqual(season.title(),
                      "Season {:02d}".format(season.season_number()))
Example #8
0
 def test_id(self):
     season = Season("path", "showname", 1)
     id_str = "{}{}{}".format(season.show_name(), "season",
                              season.season_number())
     self.assertEqual(season.id(), season.hash_id(id_str))
Example #9
0
    def test_init(self):
        season = Season("path", "showname", 1)

        self.assertIsInstance(season, Container)
        self.assertIsInstance(season, MediaLibrary)
        self.assertIsInstance(season, Show)
        self.assertIsInstance(season, Season)
        self.assertNotIsInstance(season, Extra)

        season = Season("path", "showname", 1)
        self.assertIsNone(season.parent())

        parent = Container()
        season = Season("path", "showname", 1, parent=parent)
        self.assertTrue(testutils.compare_containers(season.parent(), parent))

        PATH = "path"
        season = Season(PATH, "showname", 1)
        self.assertEqual(PATH, season.path())

        SHOW_NAME = "showname"
        season = Season("path", SHOW_NAME, 1)
        self.assertEqual(season.show_name(), SHOW_NAME)
Example #10
0
def create_test_library():
    meta = create_test_meta()

    media_lib = MediaLibrary("apath", parent=None)

    show1 = Show(media_lib.path(), "Show 1", parent=media_lib)
    show1.ext_ids()['TestID'] = '1'
    show1.set_meta(meta[0])
    media_lib.containers.append(show1)

    show2 = Show(media_lib.path(), "Show 2", parent=media_lib)
    show2.ext_ids()['TestID'] = '2'
    show2.set_meta(meta[1])
    media_lib.containers.append(show2)

    movie = Movie("moviepath", "atitle", False, parent=media_lib)
    movie.ext_ids()['TestID'] = '3'
    movie.set_meta(meta[2])
    media_lib.media.append(movie)

    season1 = Season(show1.path(), show1.show_name(), 1, parent=show1)
    show1.containers.append(season1)

    season2 = Season(show1.path(), show1.show_name(), 2, parent=show1)
    show1.containers.append(season2)

    extra1 = Extra(season1.path(),
                   season1.show_name(),
                   season1.season_number(),
                   parent=season1)
    season1.containers.append(extra1)

    extra2 = Extra(show2.path(), show2.show_name(), 0, parent=show2)
    show2.containers.append(extra2)

    episode1 = Episode("episode1path",
                       1,
                       False,
                       parent=season1,
                       is_oad=False,
                       is_ncop=False,
                       is_nced=False,
                       is_ova=False)
    season1.media.append(episode1)

    episode2 = Episode("episode2path",
                       2,
                       False,
                       parent=season1,
                       is_oad=False,
                       is_ncop=False,
                       is_nced=False,
                       is_ova=False)
    season1.media.append(episode2)

    episode3 = Episode("episode3path",
                       3,
                       False,
                       parent=extra1,
                       is_oad=False,
                       is_ncop=False,
                       is_nced=False,
                       is_ova=False)
    extra1.media.append(episode3)

    episode4 = Episode("episode4path",
                       4,
                       False,
                       parent=extra2,
                       is_oad=False,
                       is_ncop=False,
                       is_nced=False,
                       is_ova=False)
    extra2.media.append(episode4)

    episode5 = Episode("episode5path",
                       5,
                       False,
                       parent=show2,
                       is_oad=False,
                       is_ncop=False,
                       is_nced=False,
                       is_ova=False)
    show2.media.append(episode5)

    root = media_lib
    containers = [media_lib, show1, show2, season1, season2, extra1, extra2]
    media = [movie, episode1, episode2, episode3, episode4, episode5]

    return root, containers, media