Guest User

Untitled

a guest
May 20th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. def update_video(youtube, args):
  2.  
  3.  
  4. # Call the API's videos.list method to retrieve the video resource.
  5. videos_list_response = youtube.videos().list(
  6. id=args.video_id,
  7. part='snippet'
  8. ).execute()
  9. print ('Call the APIs videos.list method to retrieve the video resource')
  10.  
  11. print(videos_list_response);
  12.  
  13.  
  14. # If the response does not contain an array of 'items' then the video was not found.
  15. if not videos_list_response['items']:
  16. print ('Video "%s" was not found.' % args.video_id)
  17. sys.exit(1)
  18.  
  19.  
  20. print ('Copiando todos los metadatos viejos del video')
  21. videos_list_snippet = videos_list_response['items'][0]['snippet']
  22.  
  23. print('Cambiando el Valor del título del video');
  24. videos_list_snippet['title'] = "args.title"
  25. print(videos_list_snippet);
  26.  
  27.  
  28. # Update the video resource by calling the videos.update() method.
  29. videos_update_response = youtube.videos().update(
  30. part='snippet',
  31. body=dict(
  32. snippet=videos_list_response,
  33. id=args.video_id
  34. )).execute()
  35.  
  36.  
  37. print('The updated video metadata is:n' +
  38. 'Title: ' + videos_update_response['snippet']['title'] + 'n')
  39.  
  40. print(videos_list_response);
  41.  
  42. {'publishedAt': '2018-04-15T23:40:19.000Z', 'channelId': 'xxxxx', 'title': 'Titulo Viejo', 'description': "Algo", 'defaultAudioLanguage': 'zxx'}
  43.  
  44. print('Cambiando el Valor del título del video');
  45. videos_list_snippet['title'] = "Titulo nuevo"
  46. print(videos_list_snippet);
  47.  
  48. {'publishedAt': '2018-04-15T23:40:19.000Z', 'channelId': 'xxxxx', 'title': 'Titulo nuevo', 'description': "Algo", 'defaultAudioLanguage': 'zxx'}
  49.  
  50. # Update the video resource by calling the videos.update() method.
  51. videos_update_response = youtube.videos().update(
  52. part='snippet',
  53. body=dict(
  54. snippet=videos_list_snippet,
  55. id=args.video_id
  56. )).execute()
  57.  
  58. An HTTP error 400 occurred:
  59. b'{n "error": {n "errors": [n {n "domain": "youtube.video",n "reason": "invalidVideoMetadata",n "message": "The request metadata is invalid.",n "locationType": "other",n "location": "body"n }n ],n "code": 400,n "message": "The request metadata is invalid."n }n}n'
  60.  
  61. # Update the video resource by calling the videos.update() method.
  62. videos_update_response = youtube.videos().update(
  63. part='snippet',
  64. body=dict(
  65. snippet=videos_list_response,
  66. id=args.video_id
  67. )).execute
  68.  
  69. An HTTP error 400 occurred:
  70. b'{n "error": {n "errors": [n {n "domain": "youtube.video",n "reason": "invalidTitle",n "message": "The request metadata specifies an invalid or empty video title.",n "locationType": "other",n "location": "body.snippet.title"n }n ],n "code": 400,n "message": "The request metadata specifies an invalid or empty video title."n }n}n
Add Comment
Please, Sign In to add comment