-
Notifications
You must be signed in to change notification settings - Fork 0
/
eztvparser-fetch-magnets.py
35 lines (28 loc) · 1.01 KB
/
eztvparser-fetch-magnets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
import eztvit
if __name__ == "__main__":
import pprint
import sys
import os
import re
import urllib2
if len(sys.argv) != 4:
print "Usage: %s <outdir> http://eztv.ch/shows/36/breaking-bad/ <filename filter: S02>" % sys.argv[0]
sys.exit(1)
out_dir = sys.argv[1]
url = sys.argv[2] # http://eztv.ch/shows/36/breaking-bad/
filter_pat = sys.argv[3]
url_pat = re.compile(ur"shows\/(\d+)\/(.+)\/")
m = url_pat.search(url)
if m:
show_id, show_name = m.groups()
else:
print "Could not extract show from", url
sys.exit(1)
for v in eztvit.torrents(show_id):
for __t in v['torrents']:
if v['filename'].find(filter_pat) > -1:
if __t.find("magnet:") > -1:
f = open(os.path.join(out_dir, v['filename']+ ".magnet"), 'wb')
f.write(__t)
print "%s;%s;%s" % (__t, v['filename'], eztvit.episodeinfo_from_filename(v['filename']) )