Exemplo n.º 1
0
 def test_logic_expressions(self):
     formatted_name = NameFormatter(
         '{{movie.canonical_title()}} - {{file.language if file.language != None}}') \
         .format(movie=movie, media=file)
     formatted_name2 = NameFormatter(
         '{{movie.canonical_title()}}{%if file.quality is not none%} - ({{file.quality}}){%endif%}') \
         .format(movie=movie, media=file)
     self.assertEqual("These Daughters of Mine (2015) - ", formatted_name)
     self.assertEqual("These Daughters of Mine (2015) - (BluRay)",
                      formatted_name2)
Exemplo n.º 2
0
 def test_movies_target_path(self):
     formatted_name = NameFormatter('{{media_movies_target_path}}/{{movie.canonical_title()}} - {{file.quality}} '
                                    '- {{file.resolution}}') \
         .format(movie=movie, media=file)
     self.assertEqual(
         "{}/These Daughters of Mine (2015) - BluRay - 1080p".format(
             Config.media_movies_target_path()), formatted_name)
Exemplo n.º 3
0
    def test_movie_sanitization(self):
        suspected_title = replace(movie, title="<>:?")
        formatted_name = NameFormatter("{{movie.title}}").format(
            movie=suspected_title, media=file)

        self.assertEqual('', formatted_name)
        self.assertEqual('<>:?', suspected_title.title)
Exemplo n.º 4
0
    def test_skip_already_existing_media_resolver_for_already_existing_target(
            self):
        class MockMediaTarget(MediaTarget):
            def can_link(self):
                return True

            def do_link(self):
                pass

            def already_exist(self):
                pass

            def do_relink(self, from_path: str):
                pass

        media_target = MockMediaTarget()
        media_target.already_exist = MagicMock(return_value=True)

        class MockMediaTargetBuilder(MediaTargetBuilder):
            def build(self, media: ParsedMediaItem, movie: Movie,
                      formatter: NameFormatter):
                return media_target

        media = ParsedMediaItem()
        movie = Movie(title='Monty Python', release_year=2015)
        target = SkipExistingMediaTargetResolver(
            media_target_builder=MockMediaTargetBuilder(),
            formatter=NameFormatter())

        _, media_target = target.resolve(media, movie)

        self.assertEqual(False, media_target.can_link())
        self.assertRaises(NotImplementedError, media_target.do_link)
Exemplo n.º 5
0
    def test_extended_plex_pattern(self):
        formatted_name = NameFormatter(
            "{{movie.canonical_title()}}"
            "{%if file.quality is not none%} - {{file.quality}}{%endif%}"
            "{%if file.resolution is not none%} - {{file.resolution}}{%endif%}.{{file.container}}")\
            .format(movie=movie, media=file)

        self.assertEqual("These Daughters of Mine (2015) - BluRay - 1080p.mp4",
                         formatted_name)
Exemplo n.º 6
0
    def test_grouping_path(self):
        """
        Lets assume we want to group movies into directories by resolution
        movies/1080p/These Daughters of Mine (2015)/These Daughters of Mine (2015) - BluRay - 1080p.mp4
        """
        formatted_name = NameFormatter('movies/{{file.resolution}}/'
                                       '{{movie.canonical_title()}}/'
                                       '{{movie.canonical_title()}}'
                                       ' - {{file.quality}} - {{file.resolution}}.{{file.container}}')\
            .format(movie=movie, media=file)

        self.assertEqual(
            'movies/1080p/These Daughters of Mine (2015)/These Daughters of Mine (2015) - BluRay - 1080p.mp4',
            formatted_name)

        path = pathlib.PurePath(formatted_name).parts
        self.assertEqual(
            ('movies', '1080p', 'These Daughters of Mine (2015)',
             'These Daughters of Mine (2015) - BluRay - 1080p.mp4'), path)
Exemplo n.º 7
0
 def test_missing_properties(self):
     formatted_name = NameFormatter('{{movie.canonical_title()}} - {{file.language}}') \
         .format(movie=movie, media=file)
     self.assertEqual("These Daughters of Mine (2015) - ", formatted_name)
Exemplo n.º 8
0
 def test_quality_and_resolution(self):
     formatted_name = NameFormatter('{{movie.canonical_title()}} - {{file.quality}} - {{file.resolution}}') \
         .format(movie=movie, media=file)
     self.assertEqual("These Daughters of Mine (2015) - BluRay - 1080p",
                      formatted_name)
Exemplo n.º 9
0
 def test_canonical_original_title(self):
     formatted_name = NameFormatter('{{canonical_movie_title(movie.original_title, movie.release_year)}}') \
         .format(movie=movie, media=file)
     self.assertEqual("Moje Corki Krowy (2015)", formatted_name)
Exemplo n.º 10
0
 def test_canonical_title(self):
     formatted_name = NameFormatter('{{movie.canonical_title()}}').format(
         movie=movie, media=file)
     self.assertEqual("These Daughters of Mine (2015)", formatted_name)
Exemplo n.º 11
0
 def __init__(self,
              media_target_builder: MediaTargetBuilder,
              formatter: NameFormatter = NameFormatter()):
     self._media_target_builder = media_target_builder
     self._formatter = formatter
     self.logger = getLogger(__class__.__name__)