Utils¶
- ayt_api.utils.extract_video_id(url: str) str | None [source]¶
This should work for every url listed here: https://gist.github.com/rodrigoborgesdeoliveira/987683cfbfcc8d800192da1e73adc486#file-activeyoutubeurlformats-txt and more such as i.ytimg.com urls.
- ayt_api.utils.extract_playlist_id(url: str) str | None [source]¶
This should work for every url listed here: https://github.com/Revnoplex/ayt-api/blob/main/test-playlist-urls.txt Don’t expect this to work on YouTube mixes.
- ayt_api.utils.extract_channel_id(url: str) str | None [source]¶
This should work for every url listed here: https://github.com/Revnoplex/ayt-api/blob/main/test-channel-urls.txt
- ayt_api.utils.extract_comment_id(url: str) str | None [source]¶
This should work for every url listed here: https://github.com/Revnoplex/ayt-api/blob/main/test-comment-urls.txt
- ayt_api.utils.id_str_to_int(youtube_id: str) int [source]¶
Converts a base 64 YouTube ID string into an integer.
- Parameters:
youtube_id (str) – The YouTube ID as a base 64 string.
- Returns:
The YouTube ID as an integer.
- Return type:
- Raises:
ValueError – There were invalid characters in the YouTube ID.
- ayt_api.utils.camel_to_snake(string: str) str [source]¶
Converts words in the camel case convention to the snake case convention.
e.g. Converts
fooBar
tofoo_bar
.
- ayt_api.utils.snake_to_camel(string: str) str [source]¶
Converts words in the snake case convention to the camel case convention.
e.g. Converts
foo_bar
tofooBar
.
- ayt_api.utils.snake_keys(dictionary: dict) dict [source]¶
Converts keys in a dictionary from camel case to snake case.
- ayt_api.utils.censor_token(call_url: str) str [source]¶
Alias of censor_key
Deprecated since version 0.4.0: Use
censor_key()
instead
- ayt_api.utils.basic_html_page(title: str, description: str) str [source]¶
Builds a basic html page
Added in version 0.4.0.
This is used in
ayt_api.api.AsyncYoutubeAPI.with_oauth_flow_generator()
- ayt_api.utils.use_existing(existing_value: Any, argument: Any) Any [source]¶
A check used in the updated functions to decide when to use the existing value if the argument has a value of
EXISTING
or use the value of the argument.Added in version 0.4.0.
- Parameters:
existing_value (Any) – The existing value that will be used if
argument
isEXISTING
.argument (Any) – The value to overwrite
existing_value
if notEXISTING
.
- Returns:
The existing value or argument.
- Return type:
Any
- ayt_api.utils.ensure_missing_keys(original: dict, minimised: dict) dict [source]¶
Ensure a dictionary with possible missing keys from the first dictionary includes them if the value for the key was
None
or an empty value.Added in version 0.4.0.
Note
This util will only check the first layer of keys and will not check any deeper nested keys.
- Parameters:
- Returns:
- The
minimised
version of the dictionary with values added back from the original depending on if they were empty values.
- The
- Return type: