Example #1
0
    def subtitle(self, episodes):

        # Parse babelfish languages
        bb_lang = {Language.fromietf(l) for l in self.languages}

        # Create subliminal episode set
        sub_episodes = set()
        for episode in episodes:

            ep_path = os.path.join(episode['dir'], episode['filename'])
            sub_episode = Episode.fromguess(ep_path, episode)

            # Look for external subtitles (not done automatically, apparently)
            sub_episode.subtitle_languages |= set(search_external_subtitles(sub_episode.name).values())

            sub_episodes.add(sub_episode)

        # download subtitles in the specified language
        subl_subtitles = download_best_subtitles(sub_episodes, bb_lang, providers=self.providers)

        for video, subtitles in subl_subtitles.items():

            save_subtitles(video, subtitles)

            # save subtitle languages in episode dict
Example #2
0
def test_refine_episode_with_country_hoc_us(episodes):
    episode = Episode.fromname(episodes['house_of_cards_us_s06e01'].name)
    video_series = episode.series
    refine(episode, apikey=APIKEY)
    # omdb has no country info. No match
    assert episode.series == video_series
    assert episode.series_imdb_id is None
Example #3
0
def test_refine_episode_with_country(episodes):
    episode = Episode.fromname(episodes['shameless_us_s08e01'].name)
    video_series = episode.series
    refine(episode, apikey=APIKEY)
    # omdb has no country info. No match
    assert episode.series == video_series
    assert episode.series_imdb_id is None
Example #4
0
    def execute(self):
        generic_queue.QueueItem.execute(self)

        ep_obj = self.ep_obj
        force = self.force

        random.shuffle(SUBTITLE_SERVICES)
        logger.log("Searching subtitles for " + ep_obj.prettyName())

        if not ek.ek(os.path.isfile, ep_obj.location):
            logger.log(
                "Can't download subtitles for " + ep_obj.prettyName() +
                ". Episode file doesn't exist.", logger.DEBUG)
            return

        epName = ep_obj.location.rpartition(".")[0]
        subLanguages = []
        if sickbeard.SUBTITLE_LANGUAGES <> '':
            subLanguages = sickbeard.SUBTITLE_LANGUAGES.split(",")
        if len(subLanguages) < 1 and ep_obj.show.lang:
            subLanguages.append(ep_obj.show.lang)

        if len(subLanguages) < 1:
            logger.log(
                "Can't download subtitles for " + ep_obj.prettyName() +
                ". Configure the language to search at post processing options.",
                logger.DEBUG)
            return
        #for lang in subLanguages:
        #langS = lang.split("-")
        #if len(langS) > 1:
        #subLanguages.append(langS[0])
        try:
            sublimLangs = set()
            for sub in subLanguages:
                bLang = Language.fromietf(sub)
                sublimLangs.add(bLang)
            sublimEpisode = set()
            sublimEpisode.add(Episode.fromname(ep_obj.location))
            downloadedSubs = subliminal.download_best_subtitles(
                videos=sublimEpisode,
                languages=sublimLangs,
                providers=SUBTITLE_SERVICES)

            subliminal.save_subtitles(downloadedSubs,
                                      directory=os.path.dirname(
                                          ep_obj.location))
            subCount = 0
            for video, video_subtitles in downloadedSubs.items():
                for sub in video_subtitles:
                    subPath = subliminal.subtitle.get_subtitle_path(
                        ep_obj.location, sub.language)
                    helpers.chmodAsParent(subPath)
                    subCount += 1
        except Exception, e:
            logger.log(
                "Error while downloading subtitles for %s: %s" %
                (ep_obj.prettyName(), str(e)), logger.ERROR)
            traceback.print_exc()
            return False
def test_refine_episode():
    episode = Episode(name=os.path.join(resources_dir, 'Refine.Episode.mkv'),
                      series='Refine',
                      season=0,
                      episode=0)
    refine(episode)
    assert episode.alternative_series == ['series']
    assert episode.series_tvdb_id == 123456
Example #6
0
def test_refine_episode(episodes):
    episode = Episode(episodes['bbt_s07e05'].name,
                      episodes['bbt_s07e05'].series.lower(),
                      episodes['bbt_s07e05'].season,
                      episodes['bbt_s07e05'].episode)
    refine(episode)
    assert episode.series == episodes['bbt_s07e05'].series
    assert episode.year == episodes['bbt_s07e05'].year
    assert episode.series_imdb_id == episodes['bbt_s07e05'].series_imdb_id
Example #7
0
def test_refine_episode_original_series(episodes):
    episode = Episode(episodes['dallas_s01e03'].name,
                      episodes['dallas_s01e03'].series.lower(),
                      episodes['dallas_s01e03'].season,
                      episodes['dallas_s01e03'].episode)
    refine(episode)
    assert episode.series == episodes['dallas_s01e03'].series
    assert episode.year == 1978
    assert episode.series_imdb_id == 'tt0077000'
Example #8
0
def test_refine_episode_year(episodes):
    episode = Episode(episodes['dallas_2012_s01e03'].name,
                      episodes['dallas_2012_s01e03'].series.lower(),
                      episodes['dallas_2012_s01e03'].season,
                      episodes['dallas_2012_s01e03'].episode,
                      year=episodes['dallas_2012_s01e03'].year,
                      original_series=False)
    refine(episode)
    assert episode.series == episodes['dallas_2012_s01e03'].series
    assert episode.year == episodes['dallas_2012_s01e03'].year
    assert episode.series_imdb_id == 'tt1723760'
Example #9
0
def test_refine_episode_with_comma(episodes):
    video = episodes['alex_inc_s01e04']
    episode = Episode.fromname(video.name)
    refine(episode)
    assert episode.series == video.series
    assert episode.year == video.year
    assert episode.original_series == video.original_series
    assert episode.title == video.title
    assert episode.imdb_id == video.imdb_id
    assert episode.series_imdb_id == video.series_imdb_id
    assert episode.tvdb_id == video.tvdb_id
    assert episode.series_tvdb_id == video.series_tvdb_id
    assert episode.alternative_series == video.alternative_series
Example #10
0
def test_refine_episode_no_year(episodes):
    video = episodes['dallas_s01e03']
    episode = Episode(video.name.lower(), video.series.lower(), video.season,
                      video.episode)
    refine(episode)
    assert episode.series == video.series
    assert episode.year == video.year
    assert episode.original_series == video.original_series
    assert episode.title == video.title
    assert episode.imdb_id == video.imdb_id
    assert episode.series_imdb_id == video.series_imdb_id
    assert episode.tvdb_id == video.tvdb_id
    assert episode.series_tvdb_id == video.series_tvdb_id
Example #11
0
def test_refine_ambiguous_2(episodes):
    video = episodes['the_100_s03e09']
    episode = Episode(video.name.lower(), video.series.lower(), video.season,
                      video.episode)
    refine(episode)
    assert episode.series == video.series
    assert episode.year == video.year
    assert episode.original_series == video.original_series
    assert episode.title == video.title
    assert episode.imdb_id == video.imdb_id
    assert episode.series_imdb_id == video.series_imdb_id
    assert episode.tvdb_id == video.tvdb_id
    assert episode.series_tvdb_id == video.series_tvdb_id
Example #12
0
def test_refine(episodes):
    video = episodes['bbt_s07e05']
    episode = Episode(video.name.lower(), video.series.lower(), video.season,
                      video.episode)
    refine(episode)
    assert episode.series == video.series
    assert episode.year == video.year
    assert episode.original_series == video.original_series
    assert episode.title == video.title
    assert episode.imdb_id == video.imdb_id
    assert episode.series_imdb_id == video.series_imdb_id
    assert episode.tvdb_id == video.tvdb_id
    assert episode.series_tvdb_id == video.series_tvdb_id
Example #13
0
def test_refine_episode_with_country_hoc_us(episodes):
    video = episodes['house_of_cards_us_s06e01']
    episode = Episode.fromname(video.name)
    refine(episode)
    assert episode.series == video.series
    assert episode.year == video.year
    assert episode.original_series == video.original_series
    assert episode.title == video.title
    assert episode.imdb_id == video.imdb_id
    assert episode.series_imdb_id == video.series_imdb_id
    assert episode.tvdb_id == video.tvdb_id
    assert episode.series_tvdb_id == video.series_tvdb_id
    assert episode.alternative_series == video.alternative_series
Example #14
0
def test_refine_episode():
    episode = Episode(name=os.path.join(resources_dir, 'Refine.Episode.mkv'), series='Refine', season=0, episode=0)
    wanted_item = WantedItem(type='episode', title='Series', year=2018, season=1, episode=[1, 2], source='Source',
                             quality='Resolution', codec='Codec', releasegrp='Group')
    refine(episode, wanted_item)
    assert episode.series == 'Series'
    assert episode.year == 2018
    assert episode.season == 1
    assert episode.episode == 1  # Only first episode is kept when refining
    assert episode.source == 'Source'
    assert episode.resolution == 'Resolution'
    assert episode.video_codec == 'Codec'
    assert episode.release_group == 'Group'
Example #15
0
    def execute(self):
        generic_queue.QueueItem.execute(self)
        
        ep_obj = self.ep_obj
        force = self.force
        
        random.shuffle(SUBTITLE_SERVICES)
        logger.log("Searching subtitles for " + ep_obj.prettyName())

        if not ek.ek(os.path.isfile, ep_obj.location):
            logger.log("Can't download subtitles for " + ep_obj.prettyName() + ". Episode file doesn't exist.", logger.DEBUG)
            return
        
        epName = ep_obj.location.rpartition(".")[0]
        subLanguages = []
        if sickbeard.SUBTITLE_LANGUAGES <> '':
            subLanguages = sickbeard.SUBTITLE_LANGUAGES.split(",")
        if len(subLanguages) < 1 and ep_obj.show.lang:
            subLanguages.append(ep_obj.show.lang)
        
        if len(subLanguages) < 1:
            logger.log("Can't download subtitles for " + ep_obj.prettyName() + ". Configure the language to search at post processing options.", logger.DEBUG)
            return
        #for lang in subLanguages:
            #langS = lang.split("-")
            #if len(langS) > 1:
                #subLanguages.append(langS[0])
        try:
            sublimLangs = set()
            for sub in subLanguages:
                bLang = Language.fromietf(sub)
                sublimLangs.add(bLang)
            sublimEpisode = set()
            sublimEpisode.add(Episode.fromname(ep_obj.location))
            downloadedSubs = subliminal.download_best_subtitles(
                videos=sublimEpisode,
                languages=sublimLangs,
                providers=SUBTITLE_SERVICES)

            subliminal.save_subtitles(downloadedSubs, directory = os.path.dirname(ep_obj.location))
            subCount = 0
            for video, video_subtitles in downloadedSubs.items():
                for sub in video_subtitles:
                    subPath = subliminal.subtitle.get_subtitle_path(ep_obj.location, sub.language)
                    helpers.chmodAsParent(subPath)
                    subCount += 1
        except Exception, e:
            logger.log("Error while downloading subtitles for %s: %s" % (ep_obj.prettyName(), str(e)), logger.ERROR)
            traceback.print_exc()
            return False
Example #16
0
def test_refine_episode_alternative_series(episodes):
    video = episodes['turn_s04e03']
    episode = Episode(video.name.lower(), video.series.lower(), video.season,
                      video.episode)
    refine(episode)
    assert episode.series == video.series
    assert episode.year == video.year
    assert episode.original_series == video.original_series
    assert episode.title == video.title
    assert episode.imdb_id == video.imdb_id
    assert episode.series_imdb_id == video.series_imdb_id
    assert episode.tvdb_id == video.tvdb_id
    assert episode.series_tvdb_id == video.series_tvdb_id
    assert episode.alternative_series == video.alternative_series
Example #17
0
def test_refine_episode_partial(episodes):
    video = episodes['csi_s15e18']
    episode = Episode(video.name.lower(),
                      video.series.lower().split(':')[0], video.season,
                      video.episode)
    refine(episode)
    assert episode.series == video.series
    assert episode.year == video.year
    assert episode.original_series == video.original_series
    assert episode.title == video.title
    assert episode.imdb_id == video.imdb_id
    assert episode.series_imdb_id == video.series_imdb_id
    assert episode.tvdb_id == video.tvdb_id
    assert episode.series_tvdb_id == video.series_tvdb_id
Example #18
0
def test_episode_fromname(episodes):
    video = Episode.fromname(episodes['bbt_s07e05'].name)
    assert video.name == episodes['bbt_s07e05'].name
    assert video.format == episodes['bbt_s07e05'].format
    assert video.release_group == episodes['bbt_s07e05'].release_group
    assert video.resolution == episodes['bbt_s07e05'].resolution
    assert video.video_codec == episodes['bbt_s07e05'].video_codec
    assert video.audio_codec is None
    assert video.imdb_id is None
    assert video.hashes == {}
    assert video.size is None
    assert video.subtitle_languages == set()
    assert video.series == episodes['bbt_s07e05'].series
    assert video.season == episodes['bbt_s07e05'].season
    assert video.episode == episodes['bbt_s07e05'].episode
    assert video.title is None
    assert video.year is None
    assert video.tvdb_id is None
Example #19
0
def test_episode_fromname(episodes):
    video = Episode.fromname(episodes['bbt_s07e05'].name)
    assert video.name == episodes['bbt_s07e05'].name
    assert video.format == episodes['bbt_s07e05'].format
    assert video.release_group == episodes['bbt_s07e05'].release_group
    assert video.resolution == episodes['bbt_s07e05'].resolution
    assert video.video_codec == episodes['bbt_s07e05'].video_codec
    assert video.audio_codec is None
    assert video.imdb_id is None
    assert video.hashes == {}
    assert video.size is None
    assert video.subtitle_languages == set()
    assert video.series == episodes['bbt_s07e05'].series
    assert video.season == episodes['bbt_s07e05'].season
    assert video.episode == episodes['bbt_s07e05'].episode
    assert video.title is None
    assert video.year is None
    assert video.tvdb_id is None
Example #20
0
def test_episode_fromguess_insufficient_data(episodes):
    guess = {'type': 'episode'}
    with pytest.raises(ValueError) as excinfo:
        Episode.fromguess(episodes['bbt_s07e05'].name, guess)
    assert str(excinfo.value) == 'Insufficient data to process the guess'
Example #21
0
def test_episode_fromguess_wrong_type(episodes):
    guess = {'type': 'subtitle'}
    with pytest.raises(ValueError) as excinfo:
        Episode.fromguess(episodes['bbt_s07e05'].name, guess)
    assert str(excinfo.value) == 'The guess must be an episode guess'
Example #22
0
def test_episode_fromguess_insufficient_data(episodes):
    guess = {'type': 'episode'}
    with pytest.raises(ValueError) as excinfo:
        Episode.fromguess(episodes['bbt_s07e05'].name, guess)
    assert str(excinfo.value) == 'Insufficient data to process the guess'
Example #23
0
def test_episode_fromguess_wrong_type(episodes):
    guess = {'type': 'subtitle'}
    with pytest.raises(ValueError) as excinfo:
        Episode.fromguess(episodes['bbt_s07e05'].name, guess)
    assert str(excinfo.value) == 'The guess must be an episode guess'
Example #24
0
def test_episode_fromguess_insufficient_data(episodes):
    guess = {"type": "episode"}
    with pytest.raises(ValueError) as excinfo:
        Episode.fromguess(episodes["bbt_s07e05"].name, guess)
    assert str(excinfo.value) == "Insufficient data to process the guess"
Example #25
0
def usage():
    print "Usage: " + sys.argv[0] + " lang series season episode"
    sys.exit(1)


numargs = len(sys.argv)
if numargs != 5:
    usage()

lang = sys.argv[1]
series = sys.argv[2]
season = int(sys.argv[3])
episode = int(sys.argv[4])

e = Episode(series + '.mp4', series, season, episode)
l = Language(lang)

pathname = None
subtitles = download_best_subtitles(set((e, )), set((l, )))
for video, video_subtitles in subtitles.items():
    for video_subtitle in video_subtitles:
        filename = get_subtitle_path(video.name, video_subtitle.language)
        pathname = os.path.join(OUT_DIR, filename)
        break
save_subtitles(subtitles, directory=OUT_DIR, encoding='utf-8')
if pathname is not None:
    print('{"filename":"' + pathname + '"}')
else:
    print("{}")
Example #26
0
def test_episode_fromguess_wrong_type(episodes):
    guess = {"type": "subtitle"}
    with pytest.raises(ValueError) as excinfo:
        Episode.fromguess(episodes["bbt_s07e05"].name, guess)
    assert str(excinfo.value) == "The guess must be an episode guess"