Remove broken iTunes podcast code (bug 1218)
This commit is contained in:
parent
73d34b1446
commit
b875481241
|
@ -116,9 +116,7 @@ def normalize_feed_url(url):
|
|||
used with "wget". If the URL cannot be converted (invalid
|
||||
or unknown scheme), "None" is returned.
|
||||
|
||||
This will also normalize feed:// and itpc:// to http://
|
||||
Also supported are phobos.apple.com links (iTunes podcast)
|
||||
and itms:// links (iTunes podcast direct link).
|
||||
This will also normalize feed:// and itpc:// to http://.
|
||||
|
||||
>>> normalize_feed_url('itpc://example.org/podcast.rss')
|
||||
'http://example.org/podcast.rss'
|
||||
|
@ -161,9 +159,6 @@ def normalize_feed_url(url):
|
|||
(scheme, rest) = url.split('://', 1)
|
||||
scheme = scheme.lower()
|
||||
|
||||
# Remember to parse iTunes XML for itms:// URLs
|
||||
do_parse_itunes_xml = (scheme == 'itms')
|
||||
|
||||
# feed://, itpc:// and itms:// are really http://
|
||||
if scheme in ('feed', 'itpc', 'itms'):
|
||||
scheme = 'http'
|
||||
|
@ -171,13 +166,6 @@ def normalize_feed_url(url):
|
|||
# Re-assemble our URL
|
||||
url = scheme + '://' + rest
|
||||
|
||||
# If we had an itms:// URL, parse XML
|
||||
if do_parse_itunes_xml:
|
||||
url = parse_itunes_xml(url)
|
||||
|
||||
# Links to "phobos.apple.com"
|
||||
url = itunes_discover_rss(url)
|
||||
|
||||
if scheme in ('http', 'https', 'ftp'):
|
||||
return url
|
||||
|
||||
|
@ -919,44 +907,6 @@ def find_command( command):
|
|||
return None
|
||||
|
||||
|
||||
def parse_itunes_xml(url):
|
||||
"""
|
||||
Parses an XML document in the "url" parameter (this has to be
|
||||
a itms:// or http:// URL to a XML doc) and searches all "<dict>"
|
||||
elements for the first occurence of a "<key>feedURL</key>"
|
||||
element and then continues the search for the string value of
|
||||
this key.
|
||||
|
||||
This returns the RSS feed URL for Apple iTunes Podcast XML
|
||||
documents that are retrieved by itunes_discover_rss().
|
||||
"""
|
||||
url = url.replace('itms://', 'http://')
|
||||
doc = http_get_and_gunzip(url)
|
||||
try:
|
||||
d = xml.dom.minidom.parseString(doc)
|
||||
except Exception, e:
|
||||
log('Error parsing document from itms:// URL: %s', e)
|
||||
return None
|
||||
last_key = None
|
||||
for pairs in d.getElementsByTagName('dict'):
|
||||
for node in pairs.childNodes:
|
||||
if node.nodeType != node.ELEMENT_NODE:
|
||||
continue
|
||||
|
||||
if node.tagName == 'key' and node.childNodes.length > 0:
|
||||
if node.firstChild.nodeType == node.TEXT_NODE:
|
||||
last_key = node.firstChild.data
|
||||
|
||||
if last_key != 'feedURL':
|
||||
continue
|
||||
|
||||
if node.tagName == 'string' and node.childNodes.length > 0:
|
||||
if node.firstChild.nodeType == node.TEXT_NODE:
|
||||
return node.firstChild.data
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def http_get_and_gunzip(uri):
|
||||
"""
|
||||
Does a HTTP GET request and tells the server that we accept
|
||||
|
@ -975,31 +925,6 @@ def http_get_and_gunzip(uri):
|
|||
return data
|
||||
|
||||
|
||||
def itunes_discover_rss(url):
|
||||
"""
|
||||
Takes an iTunes-specific podcast URL and turns it
|
||||
into a "normal" RSS feed URL. If the given URL is
|
||||
not a phobos.apple.com URL, we will simply return
|
||||
the URL and assume it's already an RSS feed URL.
|
||||
|
||||
Idea from Andrew Clarke's itunes-url-decoder.py
|
||||
"""
|
||||
|
||||
if url is None:
|
||||
return url
|
||||
|
||||
if not 'phobos.apple.com' in url.lower():
|
||||
# This doesn't look like an iTunes URL
|
||||
return url
|
||||
|
||||
try:
|
||||
data = http_get_and_gunzip(url)
|
||||
(url,) = re.findall("itmsOpen\('([^']*)", data)
|
||||
return parse_itunes_xml(url)
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
def idle_add(func, *args):
|
||||
"""
|
||||
This is a wrapper function that does the Right
|
||||
|
|
Loading…
Reference in New Issue