Search code examples
pythonyoutube-apigdata

Is there a way to auto-resume interrupted uploads to youtube using Python GData?


I'm currently using the default settings (which I believe use API v. 1) and the standard youtube-upload python script to upload videos. However, any slight interruption in the network gets the entire upload aborted and it has to start all over from the beginning (plus, I need to clean up the failed uploads..)

Is there a simple way to get such uploads to auto-resume, through repeated connection attempts after each connection disruption? I assume the solution will have to include, among other things, using gdata api v.2


Solution

  • You should try out the V3 api. Here's a sample that includes doing resumable uploads.

    https://developers.google.com/youtube/v3/guides/uploading_a_video#Sample_Code

    def initialize_upload(options):
      youtube = get_authenticated_service()
    
      tags = None
      if options.keywords:
        tags = options.keywords.split(",")
    
      insert_request = youtube.videos().insert(
        part="snippet,status",
        body=dict(
          snippet=dict(
            title=options.title,
            description=options.description,
            tags=tags,
            categoryId=options.category
          ),
          status = dict(
            privacyStatus=options.privacyStatus
          )
        ),
        media_body=MediaFileUpload(options.file, chunksize=-1, resumable=True)
      )
    
      resumable_upload(insert_request)