sites Module¶
YouTubeChatDownloader¶
-
class
chat_downloader.sites.YouTubeChatDownloader(**kwargs)¶ Bases:
chat_downloader.sites.common.BaseChatDownloader-
__init__(**kwargs)¶ Initialise a session with various parameters
- Raises
CookieError – if unable to read or parse the cookie file
-
generate_urls(**kwargs)¶ This method should be implemented in a subclass and should return a generator which yields URLs for testing.
- Raises
NotImplementedError – if not implemented and called from a subclass
-
get_chat_by_channel_id(channel_id, params)¶
-
get_chat_by_custom_username(custom_username, params)¶
-
get_chat_by_user_id(user_id, params)¶ Such as NASAtelevision in https://www.youtube.com/user/NASAtelevision
- Parameters
user_id ([type]) –
-
get_chat_by_video_id(video_id, params)¶ Get chat messages for a YouTube video, given its ID.
- Parameters
video_id (str) – YouTube video ID
- Returns
Chat object for the corresponding YouTube video
- Return type
Chat
-
get_playlist_items(playlist_url)¶
-
get_user_videos(channel_id=None, user_id=None, custom_username=None, video_type='live')¶ [summary] If more than one of channel_id, user_id and custom_username are specifed, the first one specified will be returned.
- Parameters
channel_id ([type], optional) – [description], defaults to None
user_id ([type], optional) – [description], defaults to None
custom_username ([type], optional) – [description], defaults to None
- Raises
ValueError – [description]
-
TwitchChatDownloader¶
-
class
chat_downloader.sites.TwitchChatDownloader(**kwargs)¶ Bases:
chat_downloader.sites.common.BaseChatDownloader-
__init__(**kwargs)¶ Initialise a session with various parameters
- Raises
CookieError – if unable to read or parse the cookie file
-
generate_urls(livestream_limit=10, vod_limit=5, clip_limit=5, **kwargs)¶ This method should be implemented in a subclass and should return a generator which yields URLs for testing.
- Raises
NotImplementedError – if not implemented and called from a subclass
-
get_chat_by_clip_id(clip_id, params)¶
-
get_chat_by_stream_id(stream_id, params)¶
-
get_chat_by_vod_id(vod_id, params)¶
-
get_featured_videos(username)¶
-
get_top_livestreams(limit=30)¶
-
get_user_clips(username, limit=100, filter_by='LAST_WEEK')¶
-
get_user_videos(username, limit=30, video_type=None, sort='TIME')¶
-
BaseChatDownloader¶
-
class
chat_downloader.sites.BaseChatDownloader(**kwargs)¶ Bases:
objectBase class for chat downloaders. Each supported site should have its own chat downloader. Subclasses should redefine the _VALID_URLS dictionary which creates a mapping between functions and their matching regular expressions. Optionally, subclasses should also redefine _NAME, _SITE_DEFAULT_PARAMS and _TESTS fields.
-
__init__(**kwargs)¶ Initialise a session with various parameters
- Raises
CookieError – if unable to read or parse the cookie file
-
static
check_for_invalid_types(messages_types_to_add, allowed_message_types)¶ Used to check for invalid message types
- Parameters
messages_types_to_add (list) – List of message types to add
allowed_message_types (list) – List of allowed message type
- Raises
InvalidParameter – if invalid types are specified
Clear the session’s cookies.
-
close()¶ Close the session. Once this has been called, no more requests can be made.
-
generate_urls(**kwargs)¶ This method should be implemented in a subclass and should return a generator which yields URLs for testing.
- Raises
NotImplementedError – if not implemented and called from a subclass
-
get_chat(**kwargs)¶ This method should be implemented in a subclass and should return the appropriate Chat object with respect to the specified parameters.
- Raises
NotImplementedError – if not implemented and called from a subclass
Return the value for key if key is in the cookie dictionary, else default.
- Parameters
name (str) – The key of the cookie
default (object, optional) – Return this value if the specified cookie cannot be found, defaults to None
- Returns
The cookie value, or default
- Return type
Union[str, object, None]
-
static
get_mapped_keys(remapping)¶
-
get_session_headers(key)¶
-
get_site_value(value)¶ Get the site’s default value for a certain parameter
- Parameters
value (Union[SiteDefault, object]) – The value
- Returns
The site’s default value
- Return type
object
-
classmethod
matches(url)¶ Used to check if a url matches any of the regular expressions specified in the classes _VALID_URLS dictionary.
- Returns
If a match is found, the function name and match object is returned, otherwise None.
- Return type
(str, re.Match)
-
static
retry(attempt_number, max_attempts, error, retry_timeout=None, text=None)¶ Retry to occur after an error occurs
- Parameters
attempt_number (int) – The current attempt number
max_attempts (int) – The maximum number of attempts allowed
error (Exception) – The error which was raised
retry_timeout (float, optional) – The number of seconds to sleep after failing, defaults to None (i.e. use exponential back-off)
text (object, optional) – Items to display on retry, defaults to None
- Raises
RetriesExceeded – if the maximum number of retries has been exceeded
-
update_session_headers(new_headers)¶
-