Fix problems with get_real_url() (bug 573)

Don't fail hard when we cannot get the real
URL of an episode while searching for files.

Only partially fixes bug 573, as the reporter
has posted the traceback in the wrong bug.
This commit is contained in:
Thomas Perl 2009-09-28 16:03:15 +02:00
parent 80ca2b7fe4
commit 4af2e0682f
2 changed files with 17 additions and 12 deletions

View File

@ -771,7 +771,8 @@ class PodcastEpisode(PodcastModelObject):
xml.sax.saxutils.escape(self.channel.title))
def age_in_days(self):
return util.file_age_in_days(self.local_filename(create=False))
return util.file_age_in_days(self.local_filename(create=False, \
check_only=True))
def get_age_string(self):
return util.file_age_to_string(self.age_in_days())

View File

@ -790,17 +790,21 @@ def get_real_url(url):
"""
Gets the real URL of a file and resolves all redirects.
"""
username, password = username_password_from_url(url)
if username or password:
url = url_strip_authentication(url)
log('url=%s, username=%s, password=%s', url, username, password)
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, url, username, password)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(handler)
return opener.open(url).geturl()
else:
return urllib2.urlopen(url).geturl()
try:
username, password = username_password_from_url(url)
if username or password:
url = url_strip_authentication(url)
log('url=%s, username=%s, password=%s', url, username, password)
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, url, username, password)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(handler)
return opener.open(url).geturl()
else:
return urllib2.urlopen(url).geturl()
except:
log('Error getting real url for %s', url, traceback=True)
return url
def find_command( command):