Example #1
0
 def test_update_video_description(self):
     mocker = test_utils.RequestsMocker()
     mocker.expect_request('get',
                           'https://www.googleapis.com/youtube/v3/videos',
                           params={
                               'part': 'snippet',
                               'id': 'test-video-id',
                           },
                           headers={
                               'Authorization': 'Bearer test-access-token',
                           },
                           body=json.dumps({
                               'items': [{
                                   'snippet': {
                                       'title': 'test-title',
                                       'channelId': 'test-channel-id',
                                       'description': 'test-description',
                                       'thumbnails': {
                                           'high': {
                                               'url': 'test-thumbnail-url',
                                           }
                                       }
                                   }
                               }]
                           }))
     mocker.expect_request('put',
                           'https://www.googleapis.com/youtube/v3/videos',
                           params={
                               'part': 'snippet',
                           },
                           headers={
                               'Authorization': 'Bearer test-access-token',
                               'content-type': 'application/json',
                           },
                           data=json.dumps({
                               'id': 'test-video-id',
                               'snippet': {
                                   'title': 'test-title',
                                   'channelId': 'test-channel-id',
                                   'description':
                                   'test-updated-description',
                                   'thumbnails': {
                                       'high': {
                                           'url': 'test-thumbnail-url',
                                       }
                                   }
                               }
                           }))
     google.update_video_description.run_original_for_test()
     with mocker:
         google.update_video_description('test-video-id',
                                         'test-access-token',
                                         'test-updated-description')
Example #2
0
def add_credit_to_video_url(video_url, account):
    """Add credit to a video on an external site

    This method checks if we have an account linked to the site and if so, we
    add credit to the description.  It will only add credit once per video
    URL.
    """
    creditedvideourl, created = models.CreditedVideoUrl.objects.get_or_create(
        video_url=video_url)
    if not created:
        return
    access_token = google.get_new_access_token(account.oauth_refresh_token)
    video_id = video_url.videoid
    credit_text = calc_credit_text(video_url.video)
    current_description = google.get_video_info(video_id).description
    if credit_text not in current_description:
        new_description = '%s\n\n%s' % (current_description, credit_text)
        google.update_video_description(video_id, access_token,
                                        new_description)