Example #1
0
 def setUp(self):
     VimeoTestCase.setUp(self)
     feed_file = open(os.path.join(self.data_file_dir, 'feed.json'))
     response = json.loads(feed_file.read())
     self.feed = self.suite.get_feed('http://vimeo.com/jakob/videos/rss')
     self.feed._first_response = response
     self.entries = self.suite.get_feed_entries(self.feed, response)
     info_file = open(os.path.join(self.data_file_dir, 'info.json'))
     self.info_response = json.load(info_file)
Example #2
0
 def setUp(self):
     VimeoTestCase.setUp(self)
     search_file = open(os.path.join(self.data_file_dir, 'search.json'))
     response = json.loads(search_file.read())
     self.search = self.suite.get_search(
         'search query',
         api_keys={'vimeo_key': 'BLANK',
                   'vimeo_secret': 'BLANK'})
     self.results = self.suite.get_search_results(self.search, response)
Example #3
0
 def get_search_response(self, search, search_url):
     if oauth2 is None:
         raise NotImplementedError("OAuth2 library must be installed.")
     api_key = search.api_keys.get("vimeo_key") if search.api_keys else None
     api_secret = search.api_keys.get("vimeo_secret") if search.api_keys else None
     if api_key is None or api_secret is None:
         raise NotImplementedError("API Key and Secret missing.")
     consumer = oauth2.Consumer(api_key, api_secret)
     client = oauth2.Client(consumer)
     request = client.request(search_url)
     return json.loads(request[1])
Example #4
0
 def test_get_search_with_deleted_video(self):
     search_file = open(os.path.join(self.data_file_dir,
                                     'search_with_deleted.json'))
     response = json.loads(search_file.read())
     search = self.suite.get_search(
         'search query',
         api_keys={'vimeo_key': 'BLANK',
                   'vimeo_secret': 'BLANK'})
     results = self.suite.get_search_results(search, response)
     self.assertEqual(len(results), 50)
     self.assertRaises(VideoDeleted,
                       self.suite.parse_search_result,
                       search, results[49])
Example #5
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
Example #6
0
    def parse_api_response(self, response_text):
        parsed = json.loads(response_text)
        video = parsed['entry']
        username = video['author'][0]['name']['$t']
        if 'published' in video:
            date_key = 'published'
        else:
            date_key = 'updated'

        media_group = video['media$group']
        description = media_group['media$description']
        if description['type'] != 'plain':
            # HTML-ified description. SB: Is this correct? Added in
            # 5ca9e928 originally.
            soup = BeautifulSoup(description['$t']).findAll('span')[0]
            description = unicode(soup.string)
        else:
            description = description['$t']

        thumbnail_url = None
        for thumbnail in media_group['media$thumbnail']:
            if thumbnail_url is None and thumbnail['yt$name'] == 'default':
                thumbnail_url = thumbnail['url']
            if thumbnail['yt$name'] == 'hqdefault':
                thumbnail_url = thumbnail['url']
                break
        if '$t' in media_group['media$keywords']:
            tags = media_group['media$keywords']['$t'].split(', ')
        else:
            tags = []
        tags.extend(
            [cat['$t'] for cat in media_group['media$category']])
        data = {
            'link': video['link'][0]['href'].split('&', 1)[0],
            'title': video['title']['$t'],
            'description': description.replace('\r', ''),
            'thumbnail_url': thumbnail_url,
            'publish_datetime': datetime.strptime(video[date_key]['$t'],
                                                  "%Y-%m-%dT%H:%M:%S.000Z"),
            'tags': tags,
            'user': username,
            'user_url': u'http://www.youtube.com/user/{0}'.format(username),
            'guid' : 'http://gdata.youtube.com/feeds/api/videos/{0}'.format(
                        video['id']['$t'].split(':')[-1]),
            'license': media_group['media$license']['href'],
            'flash_enclosure_url': media_group['media$player']['url']
        }
        return data
Example #7
0
 def parse_api_response(self, response_text):
     parsed = json.loads(response_text)["results"]
     url = parsed["embedTagSourceUrl"]
     publish_date = datetime.datetime.strptime(parsed["createdAt"], "%Y-%m-%d %H:%M:%S")
     data = {
         "link": parsed["url"],
         "title": parsed["title"],
         "description": parsed["description"],
         "flash_enclosure_url": url,
         "embed_code": "<iframe src='%s' width='320' height='260' />" % url,
         "thumbnail_url": parsed["imageUrl"]["medium"],
         "publish_date": publish_date,
         "tags": [unicode(tag) for tag in parsed["tags"]],
         "user": parsed["user"]["userName"],
         "user_url": parsed["user"]["url"],
     }
     return data
Example #8
0
    def parse_oembed_response(self, response_text):
        """
        Parses oembed response text into a dictionary mapping
        :class:`Video` field names to values. By default, this assumes
        that the commonly-available fields ``title``, ``author_name``,
        ``author_url``, ``thumbnail_url``, and ``html`` are available.

        """
        parsed = json.loads(response_text)
        data = {
            'title': parsed['title'],
            'user': parsed['author_name'],
            'user_url': parsed['author_url'],
            'thumbnail_url': parsed['thumbnail_url'],
            'embed_code': parsed['html']
        }
        return data
Example #9
0
 def get_feed_response(self, feed, feed_url):
     response_text = urllib2.urlopen(feed_url, timeout=5).read()
     return json.loads(response_text)
Example #10
0
 def parse_api_response(self, response_text):
     parsed = json.loads(response_text)[0]
     return self._data_from_api_video(parsed)