Example #1
0
    def from_youtube(cls, track):
        snippet = track['snippet']
        player = track['player']
        statistics = track['statistics']
        duration = isodate.parse_duration(track['contentDetails']['duration'])

        artist = Account(
            id=snippet['channelId'],
            provider_id='youtube',
            image=None,
            title=snippet['channelTitle'])

        return cls(
            id=track['id'],
            provider_id='youtube',
            account=artist,
            aspect_ratio=(
                float(player['embedHeight']) / float(player['embedWidth'])),
            duration=int(duration.total_seconds()),
            favourite_count=statistics.get('likeCount', 0),
            image=Image.from_youtube(snippet.get('thumbnails')),
            play_count=statistics.get('viewCount', 0),
            title=snippet['title'],
            created=datetime.datetime.strptime(
                snippet['publishedAt'], '%Y-%m-%dT%H:%M:%S.%fZ'))
Example #2
0
 def _update_account_profile(self, account_info):
     snippet = account_info.get('snippet', {})
     self.account.image = Image.from_youtube(snippet.get('thumbnails'))
     self.account.title = snippet.get('title')