Beispiel #1
0
    def __init__(self, client, data):
        assert data[u'version'] == u'1.0', "Youtube API version mismatch"
        self.client = client
        entry = data[u'entry']

        self.id = entry[u'yt$username'][u'$t']
        self.api_id = entry[u'id'][u'$t']
        self.thumbnail = entry[u'media$thumbnail'][u'url']
        self.title = entry[u'title'][u'$t']
        self.updated = yt_ts_to_datetime(entry[u'updated'][u'$t'])
        self.author = {
            'name': entry[u'author'][0][u'name'][u'$t'],
            'username': entry[u'yt$username'][u'$t'],
            'age': entry[u'yt$age'][u'$t'],
            'location': entry[u'yt$location'][u'$t'],
        }
        if u'yt$gender' in entry:
            self.author['gender'] = entry[u'yt$gender'][u'$t']

        self.statistics = entry[u'yt$statistics'].copy()
        self.statistics[u'lastWebAccess'] = yt_ts_to_datetime(self.statistics[u'lastWebAccess'])
        self.statistics[u'subscriberCount'] = int(self.statistics[u'subscriberCount'])
        self.statistics[u'totalUploadViews'] = int(self.statistics[u'totalUploadViews'])
        self.statistics[u'videoWatchCount'] = int(self.statistics[u'videoWatchCount'])
        self.statistics[u'viewCount'] = int(self.statistics[u'viewCount'])

        self._parse_feeds(entry['gd$feedLink'])
        self._parse_links(entry['link'])
Beispiel #2
0
 def __init__(self, data):
     self.id = data[u'id'][u'$t']
     self.author = data[u'author'][0][u'name'][u'$t']
     self.title = data[u'title'][u'$t']
     self.content = data[u'content'][u'$t']
     self.published = yt_ts_to_datetime(data[u'published'][u'$t'])
     self.updated = yt_ts_to_datetime(data[u'updated'][u'$t'])
Beispiel #3
0
    def __init__(self, client, data):
        self.client = client
        self._parse_links(data[u'link'])
        self._parse_categories(data[u'category'])

        self.title = data[u'title'][u'$t']
        self.author = data[u'author'][0][u'name'][u'$t']
        self.api_id = data[u'id']['$t']
        try:
            self.id = data[u'media$group'][u'yt$videoid'][u'$t']
        except KeyError:
            assert data[u'id'][u'$t'].startswith('http://gdata.youtube.com/feeds/api/videos/')
            assert len(data[u'id'][u'$t']) == 53
            self.id = data[u'id'][u'$t'][-11:]

        self.published = yt_ts_to_datetime(data[u'published'][u'$t'])
        self.updated = yt_ts_to_datetime(data[u'updated'][u'$t'])

        if u'yt$rating' in data:
            self.like_count = int(data[u'yt$rating'][u'numLikes'])
            self.dislike_count = int(data[u'yt$rating'][u'numDislikes'])

        self.comments = self.client.video_comments(self.id)

        self.access_control = dict((d[u'action'], d[u'permission']) for d in data[u'yt$accessControl'])

        # All the following attributes don't exist for certain restricted videos
        if u'media$description' in data[u'media$group']:
            self.description = data[u'media$group'][u'media$description'][u'$t']
        if u'media$thumbnail' in data[u'media$group']:
            self.thumbnails = {'default':'', 'hqdefault': ''}
            for thumb in data[u'media$group']['media$thumbnail']:
                if thumb['yt$name'] == 'default':
                    self.thumbnails['default'] = thumb
                if thumb['yt$name'] == 'hqdefault':
                    self.thumbnails['hqdefault'] = thumb
        if u'yt$uploaded' in data[u'media$group']:
            self.uploaded = yt_ts_to_datetime(data[u'media$group'][u'yt$uploaded'][u'$t'])
        if u'yt$duration' in data[u'media$group']:
            self.duration = int(data[u'media$group'][u'yt$duration'][u'seconds'])
        if u'yt$aspectRatio' in data[u'media$group']:
            self.aspect_ratio = data[u'media$group'][u'yt$aspectRatio'][u'$t']
        if u'yt$statistics' in data:
            self.favorite_count = int(data[u'yt$statistics'][u'favoriteCount'])
            self.view_count = int(data[u'yt$statistics'][u'viewCount'])
        if u'gd$comments' in data:
            self.comment_count = int(data[u'gd$comments'][u'gd$feedLink'][u'countHint'])
            self.comments._count = self.comment_count

        if u'yt$private' in data[u'media$group']:
            self.private = True
        else:
            self.private = False
Beispiel #4
0
 def _handle_data(self, data):
     assert data[u'version'] == u'1.0', "Youtube API version mismatch"
     self._count = int(data[u'feed'][u'openSearch$totalResults'][u'$t'])
     self.title = data[u'feed'][u'title'][u'$t']
     self.updated = yt_ts_to_datetime(data[u'feed'][u'updated'][u'$t'])
     self._parse_links(data[u'feed'][u'link'])
     return [Comment(d) for d in data['feed']['entry']]
Beispiel #5
0
 def _handle_data(self, data):
     assert data[u'version'] == u'1.0', "Youtube API version mismatch"
     self._count = int(data[u'feed'][u'openSearch$totalResults'][u'$t'])
     self.title = data[u'feed'][u'title'][u'$t']
     self.updated = yt_ts_to_datetime(data[u'feed'][u'updated'][u'$t'])
     self._parse_links(data[u'feed'][u'link'])
     videos = data['feed'].get('entry', ())
     return [Video(self.client, x) for x in videos]
Beispiel #6
0
 def _init_jsonc(self, data):
     # missing insight_url and private fields when compared to json resposne
     self.id = data['id']
     self.title = data['title']
     self.author = data['uploader']
     self.category = data['category']
     self.description = data['description']
     self.comment_count = int(data['commentCount'])
     self.comments = self.client.video_comments(self.id)
     self.duration = int(data['duration'])
     self.favorite_count = int(data['favoriteCount'])
     self.like_count = int(data['likeCount'])
     self.updated = yt_ts_to_datetime(data['updated'])
     self.uploaded = yt_ts_to_datetime(data['uploaded'])
     self.published = self.uploaded
     self.view_count = int(data['viewCount'])
     self.aspect_ratio = data['aspectRatio']
     self.keywords = data['tags']
     self.dislike_count = int(data['ratingCount']) - self.like_count
     self.private = False # Not returned by jsonc for now
Beispiel #7
0
    def __init__(self, client, data):
        assert data[u'version'] == u'1.0', "Youtube API version mismatch"
        data = data['feed']

        self.client = client
        self.id = data[u'yt$playlistId'][u'$t']
        self.author = data[u'author'][0][u'name'][u'$t']
        self.title = data[u'media$group'][u'media$description'][u'$t']
        self.description = data[u'media$group'][u'media$title'][u'$t']
        self.updated = yt_ts_to_datetime(data[u'updated'][u'$t'])

        self._handle_videos(data)
Beispiel #8
0
    def __init__(self, client, data):
        self.client = client
        self._parse_links(data[u'link'])
        self._parse_categories(data[u'category'])

        self.title = data[u'title'][u'$t']
        self.author = data[u'author'][0][u'name'][u'$t']
        self.api_id = data[u'id']['$t']
        try:
            self.id = data[u'media$group'][u'yt$videoid'][u'$t']
        except KeyError:
            assert data[u'id'][u'$t'].startswith('http://gdata.youtube.com/feeds/api/videos/')
            assert len(data[u'id'][u'$t']) == 53
            self.id = data[u'id'][u'$t'][-11:]

        self.published = yt_ts_to_datetime(data[u'published'][u'$t'])
        self.updated = yt_ts_to_datetime(data[u'updated'][u'$t'])

        if u'yt$rating' in data:
            self.like_count = int(data[u'yt$rating'][u'numLikes'])
            self.dislike_count = int(data[u'yt$rating'][u'numDislikes'])

        self.comments = self.client.video_comments(self.id)

        # All the following attributes don't exist for certain restricted videos
        if u'media$description' in u'media$group':
            self.description = data[u'media$group'][u'media$description']
        if u'yt$uploaded' in data[u'media$group']:
            self.uploaded = yt_ts_to_datetime(data[u'media$group'][u'yt$uploaded'][u'$t'])
        if u'yt$duration' in data[u'media$group']:
            self.duration = int(data[u'media$group'][u'yt$duration'][u'seconds'])
        if u'yt$aspectRatio' in data[u'media$group']:
            self.aspect_ratio = data[u'media$group'][u'yt$aspectRatio'][u'$t']
        if u'yt$statistics' in data:
            self.favorite_count = int(data[u'yt$statistics'][u'favoriteCount'])
            self.view_count = int(data[u'yt$statistics'][u'viewCount'])
        if u'gd$comments' in data:
            self.comment_count = int(data[u'gd$comments'][u'gd$feedLink'][u'countHint'])
            self.comments._count = self.comment_count