yb.youtube.api¶
YouTube video operations: get, upload, update metadata, thumbnail, chapters.
These wrap the YouTube Data API v3 videos/thumbnails resources for both
creating videos and editing already-published ones (titles, descriptions,
tags, languages, and chapter blocks in the description).
Module Attributes
Privacy values |
Functions
|
Fetch a video resource (raises |
|
Insert/replace a chapters block in the video's description. |
|
Set a custom thumbnail ( |
|
Retire an upload that |
|
Update a video's snippet ( |
|
Patch selected snippet fields, preserving the rest. |
|
Change a video's privacy (or synthetic-media flag), keeping the rest. |
|
Resumably upload a video with the given |
Exceptions
|
- yb.youtube.api.PRIVACY_STATUSES = ('private', 'unlisted', 'public')¶
Privacy values
videos.update(part="status")accepts, least visible first.
- exception yb.youtube.api.VisibilityDropWarning[source]¶
Bases:
UserWarningsupersede()leaves the re-cut less visible than the original was.Emitted before anything is changed, so escalating it refuses the call:
warnings.simplefilter("error", VisibilityDropWarning)
- yb.youtube.api.get_video(video_id, *, part='snippet,status', service=None, **cred_kwargs)[source]¶
Fetch a video resource (raises
KeyErrorif not found/visible).- Return type:
- yb.youtube.api.set_chapters(video_id, chapters, *, header='Chapters:', service=None, **cred_kwargs)[source]¶
Insert/replace a chapters block in the video’s description.
Strips any prior block under
headerand appends the new one. YouTube renders interactive chapters when the first timestamp is0:00.- Return type:
- yb.youtube.api.set_thumbnail(video_id, image_path, *, service=None, **cred_kwargs)[source]¶
Set a custom thumbnail (
thumbnails.set).- Return type:
- yb.youtube.api.supersede(old_id, new_id, *, old_privacy='private', new_privacy=None, move_playlists=True, service=None, **cred_kwargs)[source]¶
Retire an upload that
new_idreplaces (yb#19).YouTube cannot replace a video’s file, so a re-cut is a new upload. This puts the new one where the old one was and takes the old one out of view:
refuses, before changing anything, unless
new_idhas finished processing (uploadStatus == "processed"): retiring the old video for a failed or rejected upload would leave the public neither;sets
new_idtonew_privacywhen given (e.g."public");for every playlist of yours that holds
old_id(whenmove_playlists): insertsnew_idat the old one’s position (or appends, if the playlist is not sorted manually), THEN removesold_id, so a failure part-way never leaves a playlist with neither;sets
old_idtoold_privacy(default"private"), clearing any scheduled publish. It is never deleted.
The new video keeps its own privacy unless
new_privacyis given, and an upload isunlistedby default: so the re-cut of a public video is NOT made public for you. When the result is less visible than the old video was (a public original, an unlisted re-cut), aVisibilityDropWarningis emitted before anything changes; passnew_privacy="public"to publish the re-cut, or turn the warning into an error to refuse such calls.Captions and thumbnails are not copied: upload them with the new video (
yb.youtube.publish_video()). Safe to re-run: every step checks before it acts. Quota: seeyb.youtube.playlists_containing(); each write (insert, delete, update) is 50 units.- Return type:
- Returns:
{"old_id", "new_id", "playlists", "old_privacy", "new_privacy"}whereplaylistslists{"playlist_id", "added_new", "position", "removed_old"}.
- yb.youtube.api.update_video(video_id, snippet, *, service=None, **cred_kwargs)[source]¶
Update a video’s snippet (
videos.update).categoryIdis required.- Return type:
- yb.youtube.api.update_video_fields(video_id, *, title=None, description=None, tags=None, category_id=None, default_language=None, default_audio_language=None, service=None, **cred_kwargs)[source]¶
Patch selected snippet fields, preserving the rest.
Fetches the current snippet, overlays the provided fields, and updates.
categoryIdmust be present (kept from the existing snippet if not given).- Return type:
- yb.youtube.api.update_video_status(video_id, *, privacy_status=None, contains_synthetic_media=None, keep_schedule=False, service=None, **cred_kwargs)[source]¶
Change a video’s privacy (or synthetic-media flag), keeping the rest.
Read-modify-write of the
statuspart (yb#19):videos.updatereplaces the part wholesale, so the current writable fields are carried over and only the ones given change. Making a video private never deletes it.Setting
privacy_statusclears a scheduled publish (publishAt): otherwise a video made private while scheduled would still go public at that time, and a pastpublishAtread back is refused by the API. Passkeep_schedule=Trueto keep it (only meaningful with"private").- Raises:
ValueError –
privacy_statusis not one ofPRIVACY_STATUSES.- Return type: