From 661a4381e1b5bec348e3234b565b4e307f28a24b Mon Sep 17 00:00:00 2001 From: Justin Forest Date: Mon, 13 Oct 2008 17:28:05 +0400 Subject: [PATCH] Split util.get_episode_info_from_url() for code reuse. The part that issues different requests depending on the availability of a proxy server is now reusable. --- src/gpodder/util.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/gpodder/util.py b/src/gpodder/util.py index 4113d993..4630e8cb 100644 --- a/src/gpodder/util.py +++ b/src/gpodder/util.py @@ -865,6 +865,18 @@ def format_seconds_to_hour_min_sec(seconds): else: return result[0] +def proxy_request(url, proxy=None): + if proxy is None or proxy.strip() == '': + (scheme, netloc, path, parms, qry, fragid) = urlparse.urlparse(url) + conn = httplib.HTTPConnection(netloc) + start = len(scheme) + len('://') + len(netloc) + conn.request('HEAD', url[start:]) + else: + (scheme, netloc, path, parms, qry, fragid) = urlparse.urlparse(proxy) + conn = httplib.HTTPConnection(netloc) + conn.request('HEAD', url) + + return conn.getresponse() def get_episode_info_from_url(url, proxy=None): """ @@ -886,17 +898,7 @@ def get_episode_info_from_url(url, proxy=None): if not (url.startswith('http://') or url.startswith('https://')): return {} - if proxy is None or proxy.strip() == '': - (scheme, netloc, path, parms, qry, fragid) = urlparse.urlparse(url) - conn = httplib.HTTPConnection(netloc) - start = len(scheme) + len('://') + len(netloc) - conn.request('HEAD', url[start:]) - else: - (scheme, netloc, path, parms, qry, fragid) = urlparse.urlparse(proxy) - conn = httplib.HTTPConnection(netloc) - conn.request('HEAD', url) - - r = conn.getresponse() + r = proxy_request(url, proxy) result = {} log('Trying to get metainfo for %s', url) -- 2.11.4.GIT