|
@@ -149,8 +149,56 @@ def run_main(parser, options, args, output=sys.stdout):
|
|
|
for index, video_path in enumerate(args):
|
|
|
video_id = upload_video(youtube, options, video_path, len(args), index)
|
|
|
video_url = WATCH_VIDEO_URL.format(id=video_id)
|
|
|
+
|
|
|
if options.thumb:
|
|
|
youtube.thumbnails().set(videoId=video_id, media_body=options.thumb).execute()
|
|
|
+
|
|
|
+ if options.playlist:
|
|
|
+ # find playlist with given name
|
|
|
+ existing_playlist_id = None
|
|
|
+ playlists = youtube.playlists()
|
|
|
+ request = playlists.list(mine=True, part='id,snippet')
|
|
|
+ while request is not None:
|
|
|
+ results = request.execute()
|
|
|
+ for item in results['items']:
|
|
|
+ if item.get('snippet', {}).get('title') == options.playlist:
|
|
|
+ existing_playlist_id = item.get('id')
|
|
|
+
|
|
|
+ # stop paginating playlists on first matching playlist title
|
|
|
+ if existing_playlist_id is None:
|
|
|
+ request = playlists.list_next(request, results)
|
|
|
+ else:
|
|
|
+ break
|
|
|
+
|
|
|
+ # create playlist, if necessary
|
|
|
+ if existing_playlist_id is None:
|
|
|
+ playlists_insert_response = youtube.playlists().insert(part="snippet,status", body={
|
|
|
+ "snippet": {
|
|
|
+ "title": options.playlist
|
|
|
+ },
|
|
|
+ "status": {
|
|
|
+ "privacyStatus": options.privacy
|
|
|
+ }
|
|
|
+ }).execute()
|
|
|
+ existing_playlist_id = playlists_insert_response.get('id', None)
|
|
|
+
|
|
|
+ # something has gone wrong
|
|
|
+ if existing_playlist_id is None:
|
|
|
+ debug('Error creating playlist')
|
|
|
+ sys.exit(1)
|
|
|
+
|
|
|
+ # add video to playlist
|
|
|
+ youtube.playlistItems().insert(part='snippet', body={
|
|
|
+ "snippet": {
|
|
|
+ "playlistId": existing_playlist_id,
|
|
|
+ "resourceId": {
|
|
|
+ "kind": "youtube#video",
|
|
|
+ "videoId": video_id
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).execute()
|
|
|
+ debug("Added video to playlist '{0}'".format(options.playlist))
|
|
|
+
|
|
|
debug("Video URL: {0}".format(video_url))
|
|
|
output.write(video_id + "\n")
|
|
|
else:
|
|
@@ -179,6 +227,8 @@ def main(arguments):
|
|
|
help='Video location"')
|
|
|
parser.add_option('', '--thumbnail', dest='thumb', type="string",
|
|
|
help='Video thumbnail')
|
|
|
+ parser.add_option('', '--playlist', dest='playlist', type="string",
|
|
|
+ help='Playlist title (will create if necessary)')
|
|
|
parser.add_option('', '--title-template', dest='title_template',
|
|
|
type="string", default="{title} [{n}/{total}]", metavar="STRING",
|
|
|
help='Template for multiple videos (default: {title} [{n}/{total}])')
|