jonnekaunisto / simple-youtube-api

Object-oriented Wrapper for Youtube API in Python
https://simple-youtube-api.rtfd.io
Other
74 stars 16 forks source link

Can we schedule youtube videos for release via the API? #13

Closed robbiedood closed 4 years ago

robbiedood commented 4 years ago

Dear jonnekaunisto,

Maybe I miss something, so hope to hear your expertise. I was wondering if we could schedule a video upload, e.g. set publishAt using your wrapper. Is there any example of use ?

robbiedood commented 4 years ago

Dear jonnekaunisto,

Maybe I miss something, so hope to hear your expertise. I was wondering if we could schedule a video upload, e.g. set publishAt using your wrapper. Is there any example of use ?

Just found there is set_publish_at(self, time: str) in Video.py, will use it :)

jonnekaunisto commented 4 years ago

Yeah, also make sure to use the YouTube's format(ISO 8601) for time for it and keep in mind that the videos can only be scheduled in intervals of 30 minutes. So at 9:30, 10:00, ect.

You can get that formatting from datetime library by doing publish_time.strftime('%G-%m-%dT%H:%M:%S.000Z')

I probably should add an option for passing in the publish time as datetime too, because that formatting can get confusing.

robbiedood commented 4 years ago

Thanks for your reply. I first follow the example without doing scheduling , however, Receive the error message at this line: video = channel.upload_video(video)

"raise ResumableUploadError(resp, content) googleapiclient.errors.ResumableUploadError: <HttpError 400 "The request metadata is invalid."> Upload: 100% || | Time: 0:00:00 1.7 KiB/s"

Don't know if title or description is too simple or this error occurs if the request updates the snippet part of a video resource but does not set a value for both the snippet.title and snippet.categoryId properties.

I was wondering if you have any though about the error.

Thank you !

jonnekaunisto commented 4 years ago

That error means that some of the metadata is not there properly. Did you make sure to add a title to the video that is not and empty string. Also the title cannot have the characters '<' or '>'.

Can you provide the code you're trying to run so I could try to replicate the issue?

robbiedood commented 4 years ago

Yes, I ran the same code with example_youtube_upload.py as a hello-world test:

from simple_youtube_api.Channel import Channel from simple_youtube_api.LocalVideo import LocalVideo

channel = Channel() channel.login("use_my_client_secret.json", "use_my_credentials.storage")

video = LocalVideo(file_path="test_vid.mp4")

video.set_title("My Title") video.set_description("This is a description") video.set_tags(["this", "tag"]) video.set_category("gaming") video.set_default_language("english")

video.set_embeddable(True) video.set_license("creativeCommon") video.set_privacy_status("private") video.set_public_stats_viewable(True)

video.set_thumbnail_path("test_thumb.png")

video = channel.upload_video(video) # error is from this line print(video.get_video_id()) print(video)

video.like()

That error means that some of the metadata is not there properly. Did you make sure to add a title to the video that is not and empty string. Also the title cannot have the characters '<' or '>'.

Can you provide the code you're trying to run so I could try to replicate the issue?

jonnekaunisto commented 4 years ago

Oh yeah sorry about that. I was able to debug what was wrong with the example. You have to have the video.set_default_language("en-US). Or you could just take it out as it is not mandatory to state the default language.

I fixed the example if you want to refer back to it again.

https://github.com/jonnekaunisto/simple-youtube-api/blob/d619c04304cef8f60a03ddab42480245ed77d55b/examples/example_youtube_upload.py#L16

Thank you for finding the issue in the example!

robbiedood commented 4 years ago

Great ! Thanks for fixing the example !!