summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
fc17418)
Tested with Python 3.2 (and Python 2.7).
#!/usr/bin/env python
import sys
#!/usr/bin/env python
import sys
+if sys.version_info[0] < 3:
+ from HTMLParser import HTMLParser
+ from urllib import urlopen, urlretrieve, urlencode
+ def get_encoding(info):
+ return info.getparam('charset')
+
+else:
+ from html.parser import HTMLParser
+ from urllib.request import urlopen, urlretrieve
+ from urllib.parse import urlencode
+ def get_encoding(info):
+ return info.get_content_charset('ascii')
import zipfile
import subprocess
import zipfile
import subprocess
class SubDivXQuery:
def __init__(self, to_search, page_number):
class SubDivXQuery:
def __init__(self, to_search, page_number):
@property
def url(self):
return 'http://%s%s?%s' % (self.host, self.page,
@property
def url(self):
return 'http://%s%s?%s' % (self.host, self.page,
- urllib.urlencode(self.query))
@property
def page_uri(self):
@property
def page_uri(self):
- return self.page + '?' + urllib.urlencode(self.query)
+ return self.page + '?' + urlencode(self.query)
@property
def down_uri(self):
return 'http://' + self.host + self.down_page
@property
def down_uri(self):
return 'http://' + self.host + self.down_page
-class SubDivXHTMLParser(HTMLParser.HTMLParser):
+class SubDivXHTMLParser(HTMLParser):
IDLE = 1
HEADER = 2
def __init__(self, down_uri):
IDLE = 1
HEADER = 2
def __init__(self, down_uri):
- HTMLParser.HTMLParser.__init__(self)
+ HTMLParser.__init__(self)
self.down_uri = down_uri
self.depth = 0
self.parsing = False
self.down_uri = down_uri
self.depth = 0
self.parsing = False
subs = []
while True:
query = SubDivXQuery(query_str, page_number)
subs = []
while True:
query = SubDivXQuery(query_str, page_number)
- url = urllib.urlopen(query.url)
+ url = urlopen(query.url)
parser = SubDivXHTMLParser(query.down_uri)
parser = SubDivXHTMLParser(query.down_uri)
+ try:
+ encoding = get_encoding(url.info())
+ except:
+ encoding = 'ascii'
+
+ parser.feed(line.decode(encoding))
subs = filter_subtitles(subs, filters)
for sub in subs:
subs = filter_subtitles(subs, filters)
for sub in subs:
- %(titulo)s (%(autor)s - %(fecha)s - %(downloads)s - %(comentarios)s)
%(desc)s
DOWNLOADING ...
- %(titulo)s (%(autor)s - %(fecha)s - %(downloads)s - %(comentarios)s)
%(desc)s
DOWNLOADING ...
-''' % sub
- fname, headers = urllib.urlretrieve(sub['url'])
+''' % sub)
+ continue
+ fname, headers = urlretrieve(sub['url'])
if 'Content-Type' in headers:
if headers['Content-Type'] in zip_exts:
z = zipfile.ZipFile(fname, 'r')
if 'Content-Type' in headers:
if headers['Content-Type'] in zip_exts:
z = zipfile.ZipFile(fname, 'r')
for fn in z.namelist():
if fn.endswith('.srt') or fn.endswith('.sub'):
if '..' in fn or fn.startswith('/'):
for fn in z.namelist():
if fn.endswith('.srt') or fn.endswith('.sub'):
if '..' in fn or fn.startswith('/'):
- print 'Dangerous file name:', fn
+ print('Dangerous file name:', fn)
- print 'Extracting', fn, '...'
+ print('Extracting', fn, '...')
z.extract(fn)
elif headers['Content-Type'] in rar_exts:
if subprocess.call(['rar', 'x', fname]) != 0:
z.extract(fn)
elif headers['Content-Type'] in rar_exts:
if subprocess.call(['rar', 'x', fname]) != 0:
- print 'Error unraring file %s' % fname
+ print('Error unraring file %s' % fname)
- print 'Unrecognized file type:', headers['Content-Type']
+ print('Unrecognized file type:', headers['Content-Type'])
- print 'No Content-Type!'
+ print('No Content-Type!')
get_subs(sys.argv[1], sys.argv[2:])
get_subs(sys.argv[1], sys.argv[2:])