Ejemplo n.º 1
0
class OpenSubtitlesDownloader():

	def __init__(self):
		self.provider = OpenSubtitlesProvider()
		self.provider.initialize()

	def download(self, imdb_id):
		subtitles = self.provider.query(set([babelfish.Language('eng')]), imdb_id=imdb_id)
		# import pdb; pdb.set_trace()
		for subtitle in subtitles:
			try:
				return self.provider.download_subtitle(subtitle)
			except Exception as e:
				print e
				continue
Ejemplo n.º 2
0
def test_query_tag_movie(movies):
    video = movies['enders_game']
    languages = {Language('fra')}
    expected_subtitles = {'1954121830'}
    with OpenSubtitlesProvider() as provider:
        subtitles = provider.query(languages, tag=video.name)
    assert {subtitle.id for subtitle in subtitles} == expected_subtitles
    assert {subtitle.language for subtitle in subtitles} == languages
Ejemplo n.º 3
0
def test_query_imdb_id(movies):
    video = movies['man_of_steel']
    languages = {Language('deu')}
    expected_subtitles = {'1953771409', '1953768982'}
    with OpenSubtitlesProvider() as provider:
        subtitles = provider.query(languages, imdb_id=video.imdb_id)
    assert {subtitle.id for subtitle in subtitles} == expected_subtitles
    assert {subtitle.language for subtitle in subtitles} == languages
Ejemplo n.º 4
0
def test_query_query_movie(movies):
    video = movies['man_of_steel']
    languages = {Language('fra')}
    expected_subtitles = {'1953767244', '1953770526', '1953150292', '1953647841', '1953767650'}
    with OpenSubtitlesProvider() as provider:
        subtitles = provider.query(languages, query=video.title)
    assert {subtitle.id for subtitle in subtitles} == expected_subtitles
    assert {subtitle.language for subtitle in subtitles} == languages
Ejemplo n.º 5
0
def test_query_query_episode(episodes):
    video = episodes['dallas_2012_s01e03']
    languages = {Language('fra')}
    expected_subtitles = {'1953147577'}
    with OpenSubtitlesProvider() as provider:
        subtitles = provider.query(languages, query=video.series, season=video.season, episode=video.episode)
    assert {subtitle.id for subtitle in subtitles} == expected_subtitles
    assert {subtitle.language for subtitle in subtitles} == languages
Ejemplo n.º 6
0
def test_download_subtitle(movies):
    video = movies['man_of_steel']
    languages = {Language('deu'), Language('fra')}
    with OpenSubtitlesProvider() as provider:
        subtitles = provider.list_subtitles(video, languages)
        provider.download_subtitle(subtitles[0])
    assert subtitles[0].content is not None
    assert subtitles[0].is_valid() is True
Ejemplo n.º 7
0
def test_list_subtitles_episode(episodes):
    video = episodes['marvels_agents_of_shield_s02e06']
    languages = {Language('hun')}
    expected_subtitles = {'1954464403', '1954454544'}
    with OpenSubtitlesProvider() as provider:
        subtitles = provider.list_subtitles(video, languages)
    assert {subtitle.id for subtitle in subtitles} == expected_subtitles
    assert {subtitle.language for subtitle in subtitles} == languages
Ejemplo n.º 8
0
def test_list_subtitles_movie_no_hash(movies):
    video = movies['enders_game']
    languages = {Language('deu')}
    expected_subtitles = {'1954157398', '1954156756', '1954443141'}
    with OpenSubtitlesProvider() as provider:
        subtitles = provider.list_subtitles(video, languages)
    assert {subtitle.id for subtitle in subtitles} == expected_subtitles
    assert {subtitle.language for subtitle in subtitles} == languages
Ejemplo n.º 9
0
def test_list_subtitles_movie(movies):
    video = movies['man_of_steel']
    languages = {Language('deu'), Language('fra')}
    expected_subtitles = {'1953767244', '1953647841', '1953767650', '1953771409', '1953768982', '1953770526'}
    with OpenSubtitlesProvider() as provider:
        subtitles = provider.list_subtitles(video, languages)
    assert {subtitle.id for subtitle in subtitles} == expected_subtitles
    assert {subtitle.language for subtitle in subtitles} == languages
Ejemplo n.º 10
0
def test_query_query_season_episode(episodes):
    video = episodes['bbt_s07e05']
    languages = {Language('deu')}
    expected_subtitles = {'1953771908'}
    with OpenSubtitlesProvider() as provider:
        subtitles = provider.query(languages, query=video.series, season=video.season, episode=video.episode)
    assert {subtitle.id for subtitle in subtitles} == expected_subtitles
    assert {subtitle.language for subtitle in subtitles} == languages
Ejemplo n.º 11
0
def test_query_hash_size(movies):
    video = movies['man_of_steel']
    languages = {Language('eng')}
    expected_subtitles = {'1953767678', '1953800590', '1953766751', '1953621994', '1953766883', '1953767330',
                          '1953766488', '1953766413', '1953766280', '1953767141', '1953766279', '1953785668',
                          '1953767218'}
    with OpenSubtitlesProvider() as provider:
        subtitles = provider.query(languages, hash=video.hashes['opensubtitles'], size=video.size)
    assert {subtitle.id for subtitle in subtitles} == expected_subtitles
    assert {subtitle.language for subtitle in subtitles} == languages
Ejemplo n.º 12
0
def test_query_query_movie(movies):
    video = movies['man_of_steel']
    languages = {Language('fra')}
    expected_subtitles = {
        '1953150292', '1953647841', '1953767244', '1953767650', '1953770526',
        '1955250359', '1955252613', '1955260179', '1955260793', '1956104848'
    }
    with OpenSubtitlesProvider(USERNAME, PASSWORD) as provider:
        subtitles = provider.query(languages, query=video.title)
    assert {subtitle.id for subtitle in subtitles} == expected_subtitles
    assert {subtitle.language for subtitle in subtitles} == languages
Ejemplo n.º 13
0
def test_query_imdb_id(movies):
    video = movies['man_of_steel']
    languages = {Language('deu')}
    expected_subtitles = {
        '1953768982', '1953771409', '1955278518', '1955279635', '1955742626',
        '1956717408'
    }
    with OpenSubtitlesProvider(USERNAME, PASSWORD) as provider:
        subtitles = provider.query(languages, imdb_id=video.imdb_id)
    assert {subtitle.id for subtitle in subtitles} == expected_subtitles
    assert {subtitle.language for subtitle in subtitles} == languages
Ejemplo n.º 14
0
def test_tag_match(episodes):
    video = episodes['the fall']
    languages = {Language('por', 'BR')}
    unwanted_subtitle_id = '1954369181'  # 'Doc.Martin.S03E01.(24 September 2007).[TVRip (Xvid)]-spa.srt'
    with OpenSubtitlesProvider() as provider:
        subtitles = provider.list_subtitles(video, languages)
        found_subtitle = [s for s in subtitles if s.id == unwanted_subtitle_id and s.matched_by == 'tag'][0]
        matches = found_subtitle.get_matches(video)
    assert len(subtitles) > 0
    assert unwanted_subtitle_id in {subtitle.id for subtitle in subtitles}
    # Assert is not a tag match: {'series', 'year', 'season', 'episode'}
    assert matches == {'episode', 'year', 'country', 'season'}
Ejemplo n.º 15
0
def test_list_subtitles_movie(movies):
    video = movies['man_of_steel']
    languages = {Language('deu'), Language('fra')}
    expected_subtitles = {
        '1953150292', '1953600788', '1953608995', '1953608996', '1953647841',
        '1953767244', '1953767650', '1953768982', '1953770526', '1953771409',
        '1954879110', '1955250359', '1955252613', '1955260179', '1955260793',
        '1955268745', '1955278518', '1955279635', '1955280869', '1955280874',
        '1955742626', '1955752850', '1955752852', '1955933986', '1956104848',
        '1956113223', '1956683278', '1956683279', '1956717408', '1956717410'
    }
    with OpenSubtitlesProvider(USERNAME, PASSWORD) as provider:
        subtitles = provider.list_subtitles(video, languages)
    assert {subtitle.id for subtitle in subtitles} == expected_subtitles
    assert {subtitle.language for subtitle in subtitles} == languages
Ejemplo n.º 16
0
	def __init__(self):
		self.provider = OpenSubtitlesProvider()
		self.provider.initialize()
Ejemplo n.º 17
0
def test_query_not_enough_information():
    languages = {Language('eng')}
    with OpenSubtitlesProvider() as provider:
        with pytest.raises(ValueError) as excinfo:
            provider.query(languages)
    assert str(excinfo.value) == 'Not enough information'
Ejemplo n.º 18
0
def test_no_operation():
    with OpenSubtitlesProvider() as provider:
        provider.no_operation()
Ejemplo n.º 19
0
def test_logout():
    provider = OpenSubtitlesProvider('python-subliminal', 'subliminal')
    provider.initialize()
    provider.terminate()
    assert provider.token is None
Ejemplo n.º 20
0
def test_login_bad_password():
    provider = OpenSubtitlesProvider('python-subliminal', 'lanimilbus')
    with pytest.raises(Unauthorized):
        provider.initialize()
Ejemplo n.º 21
0
logger.setLevel(logging.INFO)
myhandler = logging.StreamHandler()  # writes to stderr
myformatter = logging.Formatter(fmt='%(levelname)s: %(message)s')
myhandler.setFormatter(myformatter)
logger.addHandler(myhandler)

# check the config file
if not config['OPENSUBTITLE']['username']:
    logger.info('Problem in configuration')

if not config['OPENSUBTITLE']['password']:
    logger.info('Problem in configuration')

# configure providers with config
providerOpenSubtitles = OpenSubtitlesProvider(
    username=config['OPENSUBTITLE']['username'],
    password=config['OPENSUBTITLE']['password'])

# configure the cache
region.configure('dogpile.cache.dbm', arguments={'filename': 'cachefile.dbm'})

# configure the path to scan
pathToScan = config['DEFAULT']['pathToScan']

# scan for videos newer than 2 weeks and their existing subtitles in a folder
videos = scan_videos(pathToScan, age=timedelta(days=30))
logger.info('Analyse video  % s ' % (videos))

# Download all shooters
shooter_providers = ['shooter']
shooter_subtitles = list_subtitles(videos, {Language('zho')},
Ejemplo n.º 22
0
def test_configuration_error_no_password():
    with pytest.raises(ConfigurationError):
        OpenSubtitlesProvider(username='******')
Ejemplo n.º 23
0
def test_login():
    provider = OpenSubtitlesProvider('python-subliminal', 'subliminal')
    assert provider.token is None
    provider.initialize()
    assert provider.token is not None
Ejemplo n.º 24
0
def test_logout():
    provider = OpenSubtitlesProvider('python-subliminal', 'subliminal')
    provider.initialize()
    provider.terminate()
    assert provider.token is None
Ejemplo n.º 25
0
 def __init__(self):
     self.provider = OpenSubtitlesProvider()
     self.provider.initialize()
Ejemplo n.º 26
0
def test_configuration_error_no_username():
    with pytest.raises(ConfigurationError):
        OpenSubtitlesProvider(password=PASSWORD)
Ejemplo n.º 27
0
def test_login():
    provider = OpenSubtitlesProvider(USERNAME, PASSWORD)
    assert provider.token is None
    provider.initialize()
    assert provider.token is not None
Ejemplo n.º 28
0
def test_query_wrong_hash_wrong_size():
    languages = {Language('eng')}
    with OpenSubtitlesProvider() as provider:
        subtitles = provider.query(languages, hash='123456787654321', size=99999)
    assert len(subtitles) == 0
Ejemplo n.º 29
0
def test_login_bad_password():
    provider = OpenSubtitlesProvider('python-subliminal', 'lanimilbus')
    with pytest.raises(Unauthorized):
        provider.initialize()
Ejemplo n.º 30
0
def test_logout():
    provider = OpenSubtitlesProvider(USERNAME, PASSWORD)
    provider.initialize()
    provider.terminate()
    assert provider.token is None
Ejemplo n.º 31
0
def test_login_bad_password():
    provider = OpenSubtitlesProvider(USERNAME, 'lanimilbus')
    with pytest.raises(Unauthorized):
        provider.initialize()
Ejemplo n.º 32
0
def test_login():
    provider = OpenSubtitlesProvider('python-subliminal', 'subliminal')
    assert provider.token is None
    provider.initialize()
    assert provider.token is not None
Ejemplo n.º 33
0
def test_no_operation():
    with OpenSubtitlesProvider(USERNAME, PASSWORD) as provider:
        provider.no_operation()