Skip to content

Instantly share code, notes, and snippets.

@dvdbng
Created October 18, 2018 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvdbng/588a415515b19810a1d89c576f7f86cc to your computer and use it in GitHub Desktop.
Save dvdbng/588a415515b19810a1d89c576f7f86cc to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""
Usage: subscene-dl <subscene url> > file.srt
Example:
subscene-dl https://subscene.com/subtitles/mr-mercedes-second-season/english/1864622 > Mr.Mercedes.S02E09.WEBRip.x264-ION10.srt
"""
from lxml import html
import requests
import sys
import zipfile
from io import BytesIO
page = requests.get(sys.argv[1])
dl = html.fromstring(page.content).xpath('//*[@id="downloadButton"]')
dl_url = 'http://www.subscene.com' + dl[0].get('href')
with zipfile.ZipFile(BytesIO(requests.get(dl_url).content), 'r') as zf:
sys.stdout.buffer.write(zf.read(zf.namelist()[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment