Reputation: 582
I'm pretty new to coding and have been trying to use googles API to upload videos to youtube using python.
I've read https://developers.google.com/youtube/v3/guides/uploading_a_video and gone through the information, I'm able to upload a video by typing into terminal python upload_video.py --file="test.mp4"
, but what I'm struggling to figure out is a way to have a file with all the arguments that will upload the video.
An example they give is
python upload_video.py --file="/tmp/test_video_file.flv"
--title="Summer vacation in California"
--description="Had fun surfing in Santa Cruz"
--keywords="surfing,Santa Cruz"
--category="22"
--privacyStatus="private"
Is there any way I can save this information in a file that will run, or that I can edit certain aspects of to be reusable with different files but similar arguments? Currently I'm only able to type into my terminal manually to get it to upload, any information would be amazing, and I apologize if this has been covered before but my searching found nothing.
Upvotes: 3
Views: 2594
Reputation: 1961
Here is a very simple version of what you want. You can change this to suit your needs.
On each line of the text file, type your desired information
/tmp/test_video_file.flv
Summer vacation in California
Had fun surfing in Santa Cruz
surfing,Santa Cruz
22
private
Use the following code to open and read the file
lines = []
for line in open('textfile.txt'):
lines.append(line)
file = lines[0]
title = lines[1]
description= lines[2]
keywords = lines[3]
category = lines[4]
privacy_status = lines[5]
Note that you would need to include the same variables in the file every time if written this way. You could easily make those variables optional, etc.
In their code, they are passing in the options in this line
def initialize_upload(youtube, options):
So you would just change 'options' to all of the variables listed above.
EDIT
Based on your comment, I'm guessing you are very new to coding (which is totally cool!).
What I would suggest you do, is read every single line of the code and try to understand what it means, then make the changes you think will get you where you need to go. Stackoverflow is not meant to be a "code this for me" website, meaning you really need to try and struggle with what you're doing, report what you've tried, and then ask for help troubleshooting.
You may not be ready to dive into this if the lines of code don't make sense (or you aren't at least roughly able to reason what they do) and need to get more fundamental knowledge through courses, etc.
Let's look at this line of code from their example
if __name__ == '__main__':
argparser.add_argument("--file", required=True, help="Video file to
upload")
You may not know what an 'argparser' is, but it has the word '--file' in it. It also has required=True
What would happen if you made required False? What would happen if you deleted this line?
You don't actually need that line or any of the argparser lines if you write the program similar to the way I described. It sounds like the issue is, you aren't sure how to progress at all, which is where most of us were at at some point in time (I'm still there in many ways).
See if you can learn each line does and try to understand it in the context of the whole code example. If that's too challenging, take some more courses and come back when you have the tools you need.
Upvotes: 1