Exemple #1
0
    def get_subtitles(self):
        """Returns a dict of index -> (language, filename) for available
        tracks.
        """
        if not self.playbin or not self.supports_subtitles:
            return {}

        tracks = {}

        if self.playbin.get_property("suburi") is None:
            # Don't list subtitle tracks that we're getting from an SRT file
            for track_index in range(self.playbin.get_property("n-text")):
                track_name = self._get_subtitle_track_name(track_index)
                if track_name is None:
                    track_name = _("Track %(tracknumber)d",
                                   {"tracknumber": track_index})
                tracks[track_index] = (track_name, None)

        files = gather_subtitle_files(self.iteminfo.video_path)

        external_track_id = 100
        for i, mem in enumerate(files):
            track_name = self._get_subtitle_file_name(mem)
            if track_name is None:
                track_name = _("Subtitle file %(tracknumber)d",
                               {"tracknumber": i})
            tracks[external_track_id + i] = (track_name, mem)

        return tracks
Exemple #2
0
 def test_subtitles_dir(self):
     movie_file, sub_files = self.create_files("foo.mov", [
         os.path.join("subtitles", "foo.en.srt"),
         os.path.join("subtitles", "foo.fr.srt")
     ])
     self.assertEquals(sub_files,
                       util.gather_subtitle_files(FilenameType(movie_file)))
Exemple #3
0
    def get_subtitles(self):
        """Returns a dict of index -> (language, filename) for available
        tracks.
        """
        if not self.playbin or not self.supports_subtitles:
            return {}

        tracks = {}

        if self.playbin.get_property("suburi") is None:
            # Don't list subtitle tracks that we're getting from an SRT file
            for track_index in range(self.playbin.get_property("n-text")):
                track_name = self._get_subtitle_track_name(track_index)
                if track_name is None:
                    track_name = _("Track %(tracknumber)d",
                                   {"tracknumber": track_index})
                tracks[track_index] = (track_name, None)

        files = gather_subtitle_files(self.iteminfo.video_path)

        external_track_id = 100
        for i, mem in enumerate(files):
            track_name = self._get_subtitle_file_name(mem)
            if track_name is None:
                track_name = _("Subtitle file %(tracknumber)d",
                               {"tracknumber": i})
            tracks[external_track_id + i] = (track_name, mem)

        return tracks
Exemple #4
0
    def test_lots_of_files(self):
        movie_file, sub_files = self.create_files(
            "foo.mov", ["foo.en.srt", "blah.ogv", "foo.ogv"])

        # weed out the non-srt files so we can test correctly
        sub_files = [mem for mem in sub_files if mem.endswith(".srt")]
        self.assertEquals(sub_files,
                          util.gather_subtitle_files(FilenameType(movie_file)))
Exemple #5
0
    def test_lots_of_files(self):
        movie_file, sub_files = self.create_files(
            "foo.mov", ["foo.en.srt", "blah.ogv", "foo.ogv"])

        # weed out the non-srt files so we can test correctly
        sub_files = [mem for mem in sub_files if mem.endswith(".srt")]
        self.assertEquals(
            sub_files, util.gather_subtitle_files(FilenameType(movie_file)))
Exemple #6
0
    def test_filename_possibilities(self):
        movie_file, sub_files = self.create_files(
            "foo.mov", ["foo.en.srt", "foo.en.sub", "foo.srt", "foo.sub"])

        self.assertEquals(sub_files,
                          util.gather_subtitle_files(FilenameType(movie_file)))
Exemple #7
0
 def test_multiple_files(self):
     movie_file, sub_files = self.create_files(
         "foo.mov", ["foo.en.srt", "foo.fr.srt", "foo.es.srt"])
     self.assertEquals(sub_files,
                       util.gather_subtitle_files(FilenameType(movie_file)))
Exemple #8
0
 def test_no_subtitle_files(self):
     movie_file, sub_files = self.create_files("foo.mov")
     self.assertEquals(sub_files,
                       util.gather_subtitle_files(FilenameType(movie_file)))
Exemple #9
0
 def test_no_directory(self):
     # tests the case where the foofeed directory doesn't exist
     movie_file = os.path.join(self.tempdir, "foofeed", "foo.mov")
     self.assertEquals([],
                       util.gather_subtitle_files(FilenameType(movie_file)))
Exemple #10
0
    def test_filename_possibilities(self):
        movie_file, sub_files = self.create_files(
            "foo.mov", ["foo.en.srt", "foo.en.sub", "foo.srt", "foo.sub"])

        self.assertEquals(
            sub_files, util.gather_subtitle_files(FilenameType(movie_file)))
Exemple #11
0
 def test_subtitles_dir(self):
     movie_file, sub_files = self.create_files(
         "foo.mov", [os.path.join("subtitles", "foo.en.srt"),
                     os.path.join("subtitles", "foo.fr.srt")])
     self.assertEquals(
         sub_files, util.gather_subtitle_files(FilenameType(movie_file)))
Exemple #12
0
 def test_multiple_files(self):
     movie_file, sub_files = self.create_files(
         "foo.mov", ["foo.en.srt", "foo.fr.srt", "foo.es.srt"])
     self.assertEquals(
         sub_files, util.gather_subtitle_files(FilenameType(movie_file)))
Exemple #13
0
 def test_no_subtitle_files(self):
     movie_file, sub_files = self.create_files("foo.mov")
     self.assertEquals(
         sub_files, util.gather_subtitle_files(FilenameType(movie_file)))
Exemple #14
0
 def test_no_directory(self):
     # tests the case where the foofeed directory doesn't exist
     movie_file = os.path.join(self.tempdir, "foofeed", "foo.mov")
     self.assertEquals(
         [], util.gather_subtitle_files(FilenameType(movie_file)))