Пример #1
0
    def get_feed_response(self, feed, feed_url):
        # NB: for urllib2, Vimeo always returns the first page, so use the
        # lying agent when requesting pages.

        # XXX: we could use the lying agent for everything, but I'd rather let
        # them know that people are using Python to access their API.
        if '?page=' in feed_url:
            response = open_url_while_lying_about_agent(feed_url)
        else:
            response = urllib2.urlopen(feed_url, timeout=5)
        response_text = response.read()
        try:
            return json.loads(response_text)
        except ValueError:
            return None
Пример #2
0
 def get_api_url(self, video):
     if '/play/' in video.url:
         # ugh, it's a redirect to a flash player; load the redirect to get
         # the real URL.
         req = open_url_while_lying_about_agent(video.url)
         redirect_url = req.geturl()
         flash_url = urlparse.parse_qs(
             urlparse.urlparse(redirect_url).fragment)['file'][0]
         return flash_url.replace('/rss/flash/', '/rss/')
     elif '-' not in video.url:
         # http://blip.tv/file/1077145/
         # oh no, an older URL; get the redirected URL
         resp = urllib.urlopen(video.url)
         video.url = resp.geturl()
         resp.close()
     parsed_url = urlparse.urlparse(video.url)
     post_id = parsed_url[2].rsplit('-', 1)[1]
     new_parsed_url = parsed_url[:2] + ("/rss/%s" % post_id,
                                         None, None, None)
     return urlparse.urlunparse(new_parsed_url)