cd d:\workspace\autosub
d:\workspace\autosub
spynner
is the module that emulates a browser:
import spynner
br=spynner.Browser()
br.load("http://www.subscenter.org/he/subtitle/series/californication/5/12/")
True
br.html[:100]
u'<!--?xml version="1.0" encoding="utf-8"?--><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '
pyquery
parses HTML and allows querying it like jQuery:
import pyquery
p = pyquery.PyQuery(br.html)
h=p('.pageName:first')[0]
print h.text_content()
קליפורניקיישן
use p
instead of $
, the rest is like jQuery!
onclick = p(".minibutton")[0].attrib['onclick']
onclick
"return download_adv_boxy('/subtitle/download/he/254501/?v=Californication.S05E12.Hell.Aint.a.Bad.Place.to.Be.HDTV.XviD-FQM&key=848421679ad833eae66166c13159d80c');"
start = onclick.index("('") + 2
stop = onclick[start:].index("')")
link = onclick[start:stop]
link
'/subtitle/download/he/254501/?v=Californication.S05E12.Hell.Aint.a.Bad.Place.to.Be.HDTV.XviD-FQM&key=848421'
requests
is the module that will download the zip file containing the subtitles
import requests
r = requests.get('http://www.subscenter.org' + link)
r.content[:100]
'PK\x03\x04\x14\x00\x00\x00\x00\x00Ov\x85@t\xe2\xaa\xbb\xa6\x88\x00\x00\xa6\x88\x00\x00D\x00\x00\x00Californication.S05E12.Hell.Aint.a.Bad.Place.to.Be.HDTV.XviD-FQM.srt1\r'
Use StringIO
to convert the above hexa-string to bytes and zipfile
to extract the subtitle from the zip:
from StringIO import StringIO
import zipfile
z = zipfile.ZipFile(StringIO(r.content))
z.extractall()
z.close()
That's it!
import feedparser # http://code.google.com/p/feedparser/
feed_url = "http://www.subscenter.org/he/feeds/all/latest/"
feed = feedparser.parse( feed_url )
for i in feed['items']:
print i['title']
קוגר טאון עונה 4 פרק 1 30 רוק עונה 7 פרק 8 שקרניות קטנות ויפות עונה 3 פרק 14 איש משפחה עונה 11 פרק 8 אחת שיודעת עונה 6 פרק 3 צדק צעיר עונה 1 פרק 2 קאסל עונה 5 פרק 4 היה היה פעם עונה 2 פרק 10 מחלקת גנים ונוף עונה 4 פרק 1 המנטליסט עונה 5 פרק 9 נקודת שבירה עונה 5 פרק 1 גברים בעבודה עונה 1 פרק 6 מבוקש לחקירה עונה 2 פרק 11 מפלט עונה 3 פרק 11 לגדל את הופ עונה 3 פרק 9 לגדל את הופ עונה 3 פרק 8 אחת שיודעת עונה 6 פרק 2 מילדרד פירס עונה 1 פרק 2 המפץ הגדול עונה 6 פרק 12 מסע בין כוכבים: וויאג'ר עונה 6 פרק 4 צדק צעיר עונה 1 פרק 1 פיוצ'רמה עונה 7 פרק 12 סיפור אימה אמריקני עונה 2 פרק 10 רחובות המרטש עונה 1 פרק 1 עולם ללא קץ עונה 1 פרק 2 עולם ללא קץ עונה 1 פרק 1 בחורה חדשה עונה 2 פרק 8 המנטליסט עונה 5 פרק 8 מחסן 13 עונה 4 פרק 10 כבאי שיקגו עונה 1 פרק 2 זואי הארט עונה 2 פרק 9 קאסל עונה 5 פרק 3 העוקץ עונה 5 פרק 15 פיוצ'רמה עונה 7 פרק 11 סדנה לעצבים עונה 1 פרק 7 איש משפחה עונה 11 פרק 7 פרברי הגיהנום עונה 2 פרק 2 גברים בעבודה עונה 1 פרק 5 בראשית: עולם חדש עונה 1 פרק 1 ריזולי ואיילס עונה 3 פרק 15 כבאי שיקגו עונה 1 פרק 1 המפץ הגדול עונה 6 פרק 11 מסע בין כוכבים: וויאג'ר עונה 6 פרק 3 שוטרים בדם עונה 3 פרק 9 פיוצ'רמה עונה 7 פרק 10 גברים בעבודה עונה 1 פרק 4 משפחה מודרנית עונה 4 פרק 10 מחסן 13 עונה 4 פרק 9 המנטליסט עונה 5 פרק 7 אלפאס עונה 2 פרק 8
favs = [i for i in feed['items'] if i['title'].startswith(u'משפחה מודרנית')]
favs[0].keys()
['summary_detail', 'links', 'title', 'summary', 'guidislink', 'title_detail', 'link', 'id']
print favs[0]['title_detail']['value']
משפחה מודרנית עונה 4 פרק 10
stop = favs[0]['link'].index('?')
link = favs[0]['link'][:stop]
link
u'http://www.subscenter.org/he/subtitle/series/modern-family/4/10/'
And this is what I need to feed the browser.
%run subcenter.py
episodes = latest_episodes(LATEST_FEED_URL)
episodes
{u'30 \u05e8\u05d5\u05e7 \u05e2\u05d5\u05e0\u05d4 7 \u05e4\u05e8\u05e7 8': u'http://www.subscenter.org/he/subtitle/series/30-rock/7/8/', u'\u05d0\u05d7\u05ea \u05e9\u05d9\u05d5\u05d3\u05e2\u05ea \u05e2\u05d5\u05e0\u05d4 6 \u05e4\u05e8\u05e7 2': u'http://www.subscenter.org/he/subtitle/series/gossip-girl/6/2/', u'\u05d0\u05d7\u05ea \u05e9\u05d9\u05d5\u05d3\u05e2\u05ea \u05e2\u05d5\u05e0\u05d4 6 \u05e4\u05e8\u05e7 3': u'http://www.subscenter.org/he/subtitle/series/gossip-girl/6/3/', u'\u05d0\u05d9\u05e9 \u05de\u05e9\u05e4\u05d7\u05d4 \u05e2\u05d5\u05e0\u05d4 11 \u05e4\u05e8\u05e7 7': u'http://www.subscenter.org/he/subtitle/series/family-guy/11/7/', u'\u05d0\u05d9\u05e9 \u05de\u05e9\u05e4\u05d7\u05d4 \u05e2\u05d5\u05e0\u05d4 11 \u05e4\u05e8\u05e7 8': u'http://www.subscenter.org/he/subtitle/series/family-guy/11/8/', u'\u05d0\u05dc\u05e4\u05d0\u05e1 \u05e2\u05d5\u05e0\u05d4 2 \u05e4\u05e8\u05e7 8': u'http://www.subscenter.org/he/subtitle/series/alphas/2/8/', u'\u05d1\u05d7\u05d5\u05e8\u05d4 \u05d7\u05d3\u05e9\u05d4 \u05e2\u05d5\u05e0\u05d4 2 \u05e4\u05e8\u05e7 8': u'http://www.subscenter.org/he/subtitle/series/the-new-girl/2/8/', u'\u05d1\u05e8\u05d0\u05e9\u05d9\u05ea: \u05e2\u05d5\u05dc\u05dd \u05d7\u05d3\u05e9 \u05e2\u05d5\u05e0\u05d4 1 \u05e4\u05e8\u05e7 1': u'http://www.subscenter.org/he/subtitle/series/primeval-new-world/1/1/', u'\u05d2\u05d1\u05e8\u05d9\u05dd \u05d1\u05e2\u05d1\u05d5\u05d3\u05d4 \u05e2\u05d5\u05e0\u05d4 1 \u05e4\u05e8\u05e7 4': u'http://www.subscenter.org/he/subtitle/series/men-at-work-2012/1/4/', u'\u05d2\u05d1\u05e8\u05d9\u05dd \u05d1\u05e2\u05d1\u05d5\u05d3\u05d4 \u05e2\u05d5\u05e0\u05d4 1 \u05e4\u05e8\u05e7 5': u'http://www.subscenter.org/he/subtitle/series/men-at-work-2012/1/5/', u'\u05d2\u05d1\u05e8\u05d9\u05dd \u05d1\u05e2\u05d1\u05d5\u05d3\u05d4 \u05e2\u05d5\u05e0\u05d4 1 \u05e4\u05e8\u05e7 6': u'http://www.subscenter.org/he/subtitle/series/men-at-work-2012/1/6/', u'\u05d4\u05d9\u05d4 \u05d4\u05d9\u05d4 \u05e4\u05e2\u05dd \u05e2\u05d5\u05e0\u05d4 2 \u05e4\u05e8\u05e7 10': u'http://www.subscenter.org/he/subtitle/series/once-upon-a-time/2/10/', u'\u05d4\u05de\u05e0\u05d8\u05dc\u05d9\u05e1\u05d8 \u05e2\u05d5\u05e0\u05d4 5 \u05e4\u05e8\u05e7 7': u'http://www.subscenter.org/he/subtitle/series/the-mentalist/5/7/', u'\u05d4\u05de\u05e0\u05d8\u05dc\u05d9\u05e1\u05d8 \u05e2\u05d5\u05e0\u05d4 5 \u05e4\u05e8\u05e7 8': u'http://www.subscenter.org/he/subtitle/series/the-mentalist/5/8/', u'\u05d4\u05de\u05e0\u05d8\u05dc\u05d9\u05e1\u05d8 \u05e2\u05d5\u05e0\u05d4 5 \u05e4\u05e8\u05e7 9': u'http://www.subscenter.org/he/subtitle/series/the-mentalist/5/9/', u'\u05d4\u05de\u05e4\u05e5 \u05d4\u05d2\u05d3\u05d5\u05dc \u05e2\u05d5\u05e0\u05d4 6 \u05e4\u05e8\u05e7 11': u'http://www.subscenter.org/he/subtitle/series/the-big-bang-theory/6/11/', u'\u05d4\u05de\u05e4\u05e5 \u05d4\u05d2\u05d3\u05d5\u05dc \u05e2\u05d5\u05e0\u05d4 6 \u05e4\u05e8\u05e7 12': u'http://www.subscenter.org/he/subtitle/series/the-big-bang-theory/6/12/', u'\u05d4\u05e2\u05d5\u05e7\u05e5 \u05e2\u05d5\u05e0\u05d4 5 \u05e4\u05e8\u05e7 15': u'http://www.subscenter.org/he/subtitle/series/leverage/5/15/', u'\u05d6\u05d5\u05d0\u05d9 \u05d4\u05d0\u05e8\u05d8 \u05e2\u05d5\u05e0\u05d4 2 \u05e4\u05e8\u05e7 9': u'http://www.subscenter.org/he/subtitle/series/hart-of-dixie/2/9/', u'\u05db\u05d1\u05d0\u05d9 \u05e9\u05d9\u05e7\u05d2\u05d5 \u05e2\u05d5\u05e0\u05d4 1 \u05e4\u05e8\u05e7 1': u'http://www.subscenter.org/he/subtitle/series/chicago-fire/1/1/', u'\u05db\u05d1\u05d0\u05d9 \u05e9\u05d9\u05e7\u05d2\u05d5 \u05e2\u05d5\u05e0\u05d4 1 \u05e4\u05e8\u05e7 2': u'http://www.subscenter.org/he/subtitle/series/chicago-fire/1/2/', u'\u05dc\u05d2\u05d3\u05dc \u05d0\u05ea \u05d4\u05d5\u05e4 \u05e2\u05d5\u05e0\u05d4 3 \u05e4\u05e8\u05e7 8': u'http://www.subscenter.org/he/subtitle/series/raising-hope/3/8/', u'\u05dc\u05d2\u05d3\u05dc \u05d0\u05ea \u05d4\u05d5\u05e4 \u05e2\u05d5\u05e0\u05d4 3 \u05e4\u05e8\u05e7 9': u'http://www.subscenter.org/he/subtitle/series/raising-hope/3/9/', u'\u05de\u05d1\u05d5\u05e7\u05e9 \u05dc\u05d7\u05e7\u05d9\u05e8\u05d4 \u05e2\u05d5\u05e0\u05d4 2 \u05e4\u05e8\u05e7 11': u'http://www.subscenter.org/he/subtitle/series/person-of-interest/2/11/', u'\u05de\u05d7\u05dc\u05e7\u05ea \u05d2\u05e0\u05d9\u05dd \u05d5\u05e0\u05d5\u05e3 \u05e2\u05d5\u05e0\u05d4 4 \u05e4\u05e8\u05e7 1': u'http://www.subscenter.org/he/subtitle/series/parks-and-recreation-2009/4/1/', u'\u05de\u05d7\u05e1\u05df 13 \u05e2\u05d5\u05e0\u05d4 4 \u05e4\u05e8\u05e7 10': u'http://www.subscenter.org/he/subtitle/series/warehouse-13/4/10/', u'\u05de\u05d7\u05e1\u05df 13 \u05e2\u05d5\u05e0\u05d4 4 \u05e4\u05e8\u05e7 9': u'http://www.subscenter.org/he/subtitle/series/warehouse-13/4/9/', u'\u05de\u05d9\u05dc\u05d3\u05e8\u05d3 \u05e4\u05d9\u05e8\u05e1 \u05e2\u05d5\u05e0\u05d4 1 \u05e4\u05e8\u05e7 2': u'http://www.subscenter.org/he/subtitle/series/mildred-pierce/1/2/', u"\u05de\u05e1\u05e2 \u05d1\u05d9\u05df \u05db\u05d5\u05db\u05d1\u05d9\u05dd: \u05d5\u05d5\u05d9\u05d0\u05d2'\u05e8 \u05e2\u05d5\u05e0\u05d4 6 \u05e4\u05e8\u05e7 3": u'http://www.subscenter.org/he/subtitle/series/star-trek-voyager/6/3/', u"\u05de\u05e1\u05e2 \u05d1\u05d9\u05df \u05db\u05d5\u05db\u05d1\u05d9\u05dd: \u05d5\u05d5\u05d9\u05d0\u05d2'\u05e8 \u05e2\u05d5\u05e0\u05d4 6 \u05e4\u05e8\u05e7 4": u'http://www.subscenter.org/he/subtitle/series/star-trek-voyager/6/4/', u'\u05de\u05e4\u05dc\u05d8 \u05e2\u05d5\u05e0\u05d4 3 \u05e4\u05e8\u05e7 11': u'http://www.subscenter.org/he/subtitle/series/haven-2010/3/11/', u'\u05de\u05e9\u05e4\u05d7\u05d4 \u05de\u05d5\u05d3\u05e8\u05e0\u05d9\u05ea \u05e2\u05d5\u05e0\u05d4 4 \u05e4\u05e8\u05e7 10': u'http://www.subscenter.org/he/subtitle/series/modern-family/4/10/', u'\u05e0\u05e7\u05d5\u05d3\u05ea \u05e9\u05d1\u05d9\u05e8\u05d4 \u05e2\u05d5\u05e0\u05d4 5 \u05e4\u05e8\u05e7 1': u'http://www.subscenter.org/he/subtitle/series/flashpoint/5/1/', u'\u05e1\u05d3\u05e0\u05d4 \u05dc\u05e2\u05e6\u05d1\u05d9\u05dd \u05e2\u05d5\u05e0\u05d4 1 \u05e4\u05e8\u05e7 7': u'http://www.subscenter.org/he/subtitle/series/anger-management-2012/1/7/', u'\u05e1\u05d9\u05e4\u05d5\u05e8 \u05d0\u05d9\u05de\u05d4 \u05d0\u05de\u05e8\u05d9\u05e7\u05e0\u05d9 \u05e2\u05d5\u05e0\u05d4 2 \u05e4\u05e8\u05e7 10': u'http://www.subscenter.org/he/subtitle/series/american-horror-story/2/10/', u'\u05e2\u05d5\u05dc\u05dd \u05dc\u05dc\u05d0 \u05e7\u05e5 \u05e2\u05d5\u05e0\u05d4 1 \u05e4\u05e8\u05e7 1': u'http://www.subscenter.org/he/subtitle/series/world-without-end/1/1/', u'\u05e2\u05d5\u05dc\u05dd \u05dc\u05dc\u05d0 \u05e7\u05e5 \u05e2\u05d5\u05e0\u05d4 1 \u05e4\u05e8\u05e7 2': u'http://www.subscenter.org/he/subtitle/series/world-without-end/1/2/', u"\u05e4\u05d9\u05d5\u05e6'\u05e8\u05de\u05d4 \u05e2\u05d5\u05e0\u05d4 7 \u05e4\u05e8\u05e7 10": u'http://www.subscenter.org/he/subtitle/series/futurama/7/10/', u"\u05e4\u05d9\u05d5\u05e6'\u05e8\u05de\u05d4 \u05e2\u05d5\u05e0\u05d4 7 \u05e4\u05e8\u05e7 11": u'http://www.subscenter.org/he/subtitle/series/futurama/7/11/', u"\u05e4\u05d9\u05d5\u05e6'\u05e8\u05de\u05d4 \u05e2\u05d5\u05e0\u05d4 7 \u05e4\u05e8\u05e7 12": u'http://www.subscenter.org/he/subtitle/series/futurama/7/12/', u'\u05e4\u05e8\u05d1\u05e8\u05d9 \u05d4\u05d2\u05d9\u05d4\u05e0\u05d5\u05dd \u05e2\u05d5\u05e0\u05d4 2 \u05e4\u05e8\u05e7 2': u'http://www.subscenter.org/he/subtitle/series/suburgatory/2/2/', u'\u05e6\u05d3\u05e7 \u05e6\u05e2\u05d9\u05e8 \u05e2\u05d5\u05e0\u05d4 1 \u05e4\u05e8\u05e7 1': u'http://www.subscenter.org/he/subtitle/series/young-justice/1/1/', u'\u05e6\u05d3\u05e7 \u05e6\u05e2\u05d9\u05e8 \u05e2\u05d5\u05e0\u05d4 1 \u05e4\u05e8\u05e7 2': u'http://www.subscenter.org/he/subtitle/series/young-justice/1/2/', u'\u05e7\u05d0\u05e1\u05dc \u05e2\u05d5\u05e0\u05d4 5 \u05e4\u05e8\u05e7 3': u'http://www.subscenter.org/he/subtitle/series/castle/5/3/', u'\u05e7\u05d0\u05e1\u05dc \u05e2\u05d5\u05e0\u05d4 5 \u05e4\u05e8\u05e7 4': u'http://www.subscenter.org/he/subtitle/series/castle/5/4/', u'\u05e7\u05d5\u05d2\u05e8 \u05d8\u05d0\u05d5\u05df \u05e2\u05d5\u05e0\u05d4 4 \u05e4\u05e8\u05e7 1': u'http://www.subscenter.org/he/subtitle/series/cougar-town/4/1/', u'\u05e8\u05d7\u05d5\u05d1\u05d5\u05ea \u05d4\u05de\u05e8\u05d8\u05e9 \u05e2\u05d5\u05e0\u05d4 1 \u05e4\u05e8\u05e7 1': u'http://www.subscenter.org/he/subtitle/series/ripper-street/1/1/', u'\u05e8\u05d9\u05d6\u05d5\u05dc\u05d9 \u05d5\u05d0\u05d9\u05d9\u05dc\u05e1 \u05e2\u05d5\u05e0\u05d4 3 \u05e4\u05e8\u05e7 15': u'http://www.subscenter.org/he/subtitle/series/rizzoli-isles/3/15/', u'\u05e9\u05d5\u05d8\u05e8\u05d9\u05dd \u05d1\u05d3\u05dd \u05e2\u05d5\u05e0\u05d4 3 \u05e4\u05e8\u05e7 9': u'http://www.subscenter.org/he/subtitle/series/blue-bloods/3/9/', u'\u05e9\u05e7\u05e8\u05e0\u05d9\u05d5\u05ea \u05e7\u05d8\u05e0\u05d5\u05ea \u05d5\u05d9\u05e4\u05d5\u05ea \u05e2\u05d5\u05e0\u05d4 3 \u05e4\u05e8\u05e7 14': u'http://www.subscenter.org/he/subtitle/series/pretty-little-liars/3/14/'}
links=parse_subtitles_links('http://www.subscenter.org/he/subtitle/series/blue-bloods/3/9/')
links
return download_adv_boxy('/subtitle/download/he/260769/?v=Blue.Bloods.S03E09.720p.HDTV.X264-DIMENSION&key=633aa739739b8768502352ff8de6e59d'); return download_adv_boxy('/subtitle/download/he/260769/?v=Blue.Bloods.S03E09.HDTV.x264-LOL&key=934505a45f58a99af99f0a32b886a6e9');
['/subtitle/download/he/260769/?v=Blue.Bloods.S03E09.720p.HDTV.X264-DIMENSION&key=633aa739739b8768502352ff8de6e59d', '/subtitle/download/he/260769/?v=Blue.Bloods.S03E09.HDTV.x264-LOL&key=934505a45f58a99af99f0a32b886a6e9']
download_links(links)
2
%run subcenter.py modern-family 4 10
filter(lambda x: 'LOL' in x, links)
['/subtitle/download/he/260769/?v=Blue.Bloods.S03E09.HDTV.x264-LOL&key=934505a45f58a99af99f0a32b886a6e9']
links
['/subtitle/download/he/260769/?v=Blue.Bloods.S03E09.720p.HDTV.X264-DIMENSION&key=633aa739739b8768502352ff8de6e59d', '/subtitle/download/he/260769/?v=Blue.Bloods.S03E09.HDTV.x264-LOL&key=934505a45f58a99af99f0a32b886a6e9']
%run subcenter.py modern-family 4 11
Did not find subtitles for משפחה מודרנית
%run subcenter.py greys-anatomy 9 9
Found subtitles for האנטומיה של גריי
%run subcenter the-big-bang-theory 6 12 LOL
Found subtitles for המפץ הגדול
%run subcenter.py
Found subtitles for משפחה מודרנית עונה 4 פרק 10 Found subtitles for משפחה מודרנית