2014-06-21 23:59:01 +00:00
|
|
|
import re
|
|
|
|
import json
|
|
|
|
|
2015-02-25 03:43:04 +00:00
|
|
|
from . import crawler
|
2013-09-25 10:36:21 +00:00
|
|
|
|
2015-02-25 16:50:23 +00:00
|
|
|
try:
|
|
|
|
basestring
|
|
|
|
except NameError:
|
|
|
|
basestring = str
|
|
|
|
|
2013-11-09 17:48:06 +00:00
|
|
|
|
2015-04-06 15:26:12 +00:00
|
|
|
def pre_worker(url):
|
2017-03-19 09:41:37 +00:00
|
|
|
if url.startswith('http://itunes.apple.com/') or url.startswith('https://itunes.apple.com/'):
|
2014-06-21 16:35:59 +00:00
|
|
|
match = re.search('/id([0-9]+)(\?.*)?$', url)
|
|
|
|
if match:
|
|
|
|
iid = match.groups()[0]
|
2017-03-19 09:41:37 +00:00
|
|
|
redirect = 'https://itunes.apple.com/lookup?id=%s' % iid
|
|
|
|
|
|
|
|
try:
|
|
|
|
con = crawler.custom_handler(basic=True).open(redirect, timeout=4)
|
|
|
|
data = con.read()
|
|
|
|
|
|
|
|
except (IOError, HTTPException):
|
|
|
|
raise
|
|
|
|
|
|
|
|
return json.loads(data.decode('utf-8', 'replace'))['results'][0]['feedUrl']
|
2015-04-06 15:26:12 +00:00
|
|
|
|
|
|
|
return None
|