youtube-upload
youtube-upload copied to clipboard
oauth.json is deleted after upload
Problem
My directory looks like this:
client_secrets.json oauth.json test.mp4 test.py
and test.py like this:
from youtube_upload.client import YoutubeUploader
uploader = YoutubeUploader()
uploader.authenticate()
# Video options
options = {
"title" : "Example title", # The video title
"description" : "Example description", # The video description
"categoryId" : "22",
"privacyStatus" : "private", # Video privacy. Can either be "public", "private", or "unlisted"
"kids" : False, # Specifies if the Video if for kids or not. Defaults to False.
}
# upload video
uploader.upload("./test.mp4", options)
uploader.close()
After running test.py the oauth.json file is deleted for some reason, but I would like too keep it in order not to have authenticate everytime I use the script.
This is the code you are referring to.
https://github.com/pillargg/youtube-upload/blob/cc85eedc553aa31f060cfb113976fe7d5b62ecbb/youtube_upload/client.py#L317-L322
If you do not call uploader.close() it will not delete the file. Our upload procedure requires us to delete the file, so we added the close functionality. I will clarify the documentation.
I'm not calling the uploader.close and it deletes the file anyway? I have to set it to read only. I don't quite understand why does the script do this?! My code looks like this at the end:
uploader.authenticate("files/oauth.json")
print(f'[{video_id}]: Uploading...')
uploader.upload(file_path, options)
print(f'[{video_id}]: Upload successful.')
print(f'[{video_id}]: Done.')
the file is indeed deleted even if you don't call the close() function, what is happening ?
The problem is with the __del__ method here. __del__ is a finalizer and it is called when the object is garbage collected. So, at the end of the run it will delete the file, either you want or not. I think this is bug. In any case I have commented it in my local copy and things are alright.