Last active
September 1, 2016 19:52
-
-
Save binho/780b62713fc41be7b6bd7ab7aeb72b16 to your computer and use it in GitHub Desktop.
Download subtitles using subliminal lib (https://github.com/Diaoul/subliminal)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from datetime import timedelta | |
from babelfish import Language | |
from subliminal import download_best_subtitles, region, save_subtitles, scan_videos | |
import sys | |
import os | |
""" | |
1) Install subliminal (https://github.com/Diaoul/subliminal) running `pip install subliminal` (Add sudo if needed) | |
2) Run `python download-subtitles.py ~/Movies/Series/Game_of_Thrones/S01` (Adding the folder to scan as param) | |
3) 🎉 | |
""" | |
# Configuration | |
default_language = 'por' | |
default_country = 'BR' | |
try: | |
folder = sys.argv[1] | |
if not os.path.isdir(folder): | |
print 'Directory not found. Please check and try again.' | |
exit(0) | |
except IndexError: | |
print 'Ops! You need to define a folder to scan.' | |
exit(0) | |
print 'Searching/downloading subtitles. Please wait. ⏳' | |
# configure the cache | |
region.configure('dogpile.cache.dbm', arguments={'filename': '/tmp/download-subtitles.dbm'}) | |
# scan for videos newer than 2 weeks and their existing subtitles in a folder | |
# videos = scan_videos(folder, age=timedelta(weeks=2)) | |
videos = scan_videos(folder) | |
# download best subtitles - http://babelfish.readthedocs.io/en/latest/ | |
subtitles = download_best_subtitles(videos, {Language(default_language, default_country)}) | |
# save them to disk, next to the video | |
for v in videos: | |
if v.title: | |
print '✅ %s (%s) - S%s/E%s' % (v.series, v.title, v.season, v.episode) | |
else: | |
print '✅ %s - S%s/E%s' % (v.series, v.season, v.episode) | |
# https://subliminal.readthedocs.io/en/latest/api/core.html?highlight=download_best_subtitles#subliminal.core.save_subtitles | |
save_subtitles(v, subtitles[v], True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment