compuglobal package

Submodules

compuglobal.aio module

class compuglobal.aio.CapitalBeatUs(timeout=15)

Bases: compuglobal.aio.CompuGlobalAPI

An API Wrapper for accessing CapitalBeatUs API endpoints (West Wing).

class compuglobal.aio.CompuGlobalAPI(url, title, timeout)

Bases: object

Represents an API Wrapper used for accessing the cghmc API endpoints.

Parameters
  • url (str) – The url of the API.

  • title (str) – The title of the tv show/movie/skit that the url leads to.

  • timeout (float) – The timeout for websocket read.

Variables
  • random_url (str) – Endpoint used for getting a random screencap.

  • caption_url (str) – Endpoint for getting caption info using episode and timestamp e = episode & t = timestamp.

  • search_url (str) – Endpoint for getting screencaps using a search query q = search query.

  • frames_url (str) – Endpoint for getting all valid frames before & after an episode and timestamp episode/timestamp/before/after.

  • nearby_url (str) – Endpoint for getting all valid frames nearby an episode and timestamp e = episode & t = timestamp.

  • episode_url (str) – Endpoint for getting episode info and subtitles from start to end for episode episode/start/end.

static encode_caption(caption)

Loops through the caption and formats it using max_lines and max_chars and finally encodes it in base64 for use in the url.

Parameters

caption (str) – The caption to format and encode.

Returns

The caption encoded in base64.

Return type

str

format_caption(caption, max_lines=4, max_chars=24, shorten=True)

Loops through the caption and formats it using max_lines and max_chars and returns the formatted outcome.

Parameters
  • caption (str) – The caption to format.

  • max_lines (int, optional) – The maximum number of lines of captions allowed.

  • max_chars (int, optional) – The maximum number of characters allowed per line.

  • shorten (bool, optional) – Whether to shorten the caption at its latest sentence ending.

Returns

The formatted caption.

Return type

str

coroutine generate_gif(gif_url)

Performs a GET request using gif_url and returns the direct url for the gif once it has been generated.

Parameters

gif_url (str) – The url of the gif to generate.

Returns

The direct url for the generated gif

Return type

str

Raises

APIPageStatusError – Raises an exception if the status code of the request is not 200.

coroutine get_frames(episode, timestamp, before, after)

Performs a GET request to the api/frames/{episode}/{timestamp}/{before}/{after} endpoint and gets a list of all valid frames before and after the timestamp of the episode.

Parameters
  • episode (str) – The episode key of the screencap.

  • timestamp (int) – The timestamp of the screencap.

  • before (int) – The number of milliseconds before the timestamp.

  • after (int) – The number of milliseconds after the timestamp.

Returns

A list of valid frames before and after the timestamp of the episode, containing the id, episode and timestamp for each frame.

Return type

list

Raises

APIPageStatusError – Raises an exception if the status code of the request is not 200.

Note

Used for displaying the valid frames available for the gifmaker.

coroutine get_random_screencap()

Performs a GET request to the api/random endpoint and gets a random TV Show screencap.

Returns

A random screencap object.

Return type

compuglobal.Screencap

Raises

APIPageStatusError – Raises an exception if the status code of the request is not 200.

Note

Used for getting a random screencap when clicking the “RANDOM” button.

coroutine get_screencap(episode=None, timestamp=None, frame=None)

Performs a GET request to the api/caption?e={}&t={} endpoint and gets a TV Show screencap using episode e={} and timestamp t={}

Parameters
  • episode (str) – The episode key of the screencap.

  • timestamp (int) – The timestamp of the screencap.

  • frame (compuglobal.Frame) – The frame of the screencap.

Returns

A Screencap objecct for the episode and timestamp.

Return type

compuglobal.Screencap

Raises
  • APIPageStatusError – Raises an exception if the status code of the request is not 200.

  • TypeError – Raises an exception if the constructor does not receive episode and timestamp, or compuglobal.Frame

Note

Used for getting the episode info and caption shown below each screencap.

static json_to_caption(subtitles_json)

Loops through the subtitles of the json response, concatenates all lines and returns all subtitles combined as a complete caption.

Parameters

subtitles_json (dict) – The json response containing the subtitles of the screencap.

Returns

caption – The subtitles combined as a complete caption.

Return type

str

coroutine search(search_text)

Performs a GET request to the api/search?q= endpoint and gets a list of search results using the search text as the search query q={} for the request.

Parameters

search_text (str) – The text/quote to search for.

Returns

search_results – A list of search results containing the id, episode and timestamp for each result.

Return type

list

Raises
  • APIPageStatusError – Raises an exception if the status code of the request is not 200.

  • NoSearchResultsFound – Raises an exception if there are no search results found using search_text.

Note

Used for displaying all the search results and their screencaps.

coroutine search_for_screencap(search_text)

Performs a GET request to the api/search?q= endpoint using search() to get a list of search results using search_text and gets a screencap using the episode and timestamp of the first search result.

Parameters

search_text (str) – The text/quote to search for.

Returns

A screencap object of the first search result found using search_text.

Return type

compuglobal.Screencap

Raises
  • APIPageStatusError – Raises an exception if the status code of the request is not 200.

  • NoSearchResultsFound – Raises an exception if there are no search results found using search_text.

static shorten_caption(caption)

Loops through the caption and trims it at its latest sentence ending (., !, ? or ♪).

Parameters

caption (str) – The caption to shorten/trim.

Returns

caption – The shortened caption, ending at its latest sentence ending.

Return type

str

class compuglobal.aio.FrinkiHams(timeout=15)

Bases: compuglobal.aio.CompuGlobalAPI

An API Wrapper for accessing FriniHams API endpoints (The Simpsons - Steamed Hams Skit).

class compuglobal.aio.Frinkiac(timeout=15)

Bases: compuglobal.aio.CompuGlobalAPI

An API Wrapper for accessing Frinkiac API endpoints (The Simpsons).

class compuglobal.aio.GoodGodLemon(timeout=15)

Bases: compuglobal.aio.CompuGlobalAPI

An API Wrapper for accessing GoodGodLemon API endpoints (30 Rock).

class compuglobal.aio.MasterOfAllScience(timeout=15)

Bases: compuglobal.aio.CompuGlobalAPI

An API Wrapper for accessing MasterOfAllScience API endpoints (Rick and Morty).

class compuglobal.aio.Morbotron(timeout=15)

Bases: compuglobal.aio.CompuGlobalAPI

An API Wrapper for accessing Morbotron API endpoints (Futurama).

compuglobal.aio_screencap module

class compuglobal.aio_screencap.AIOScreencap(api, json: dict)

Bases: compuglobal.screencap.Screencap

coroutine get_gif_url(caption=None, before=3000, after=4000)

Gets the timestamps of the frames before and after the timestamp of the screencap using the frames endpoint for the screencap’s API and returns the url for the gif with an embedded caption.

Parameters
  • caption (str, optional) – The caption to embed in the gif, if it is None, it will use the screencaps original caption.

  • before (int, optional) – The number of milliseconds before the screencap’s timestamp to begin the gif, defaults to 3 seconds (3000ms).

  • after (int, optional) – The number of milliseconds after the screencap’s timestamp to begin the gif, defaults to 4 seconds (4000ms).

Returns

The gif url for the screencap with an embedded caption.

Return type

str

Note

Defaults gif duration to ~7 seconds (7000ms).

coroutine get_mp4_url(caption=None, before=3000, after=4000)

Gets the timestamps of the frames before and after the timestamp of the screencap using the frames endpoint for the screencap’s API and returns the url for the mp4 with an embedded caption.

Parameters
  • caption (str, optional) – The caption to embed in the mp4, if it is None, it will use the screencaps original caption.

  • before (int, optional) – The number of milliseconds before the screencap’s timestamp to begin the mp4, defaults to 3 seconds (3000ms).

  • after (int, optional) – The number of milliseconds after the screencap’s timestamp to begin the mp4, defaults to 4 seconds (4000ms).

Returns

The mp4 url for the screencap with an embedded caption.

Return type

str

Note

Defaults mp4 duration to ~7 seconds (7000ms).

compuglobal.errors module

exception compuglobal.errors.APIPageStatusError(page_status, url)

Bases: Exception

Raised when the status code for the API is not 200.

Parameters
  • page_status (int) – The page status number for the error.

  • url (str) – The url page that encountered the error.

exception compuglobal.errors.NoSearchResultsFound

Bases: Exception

Raised when no search results are returned during a search query to the search endpoint of the API.

compuglobal.frame module

class compuglobal.frame.Frame(api, frame_json)

Bases: object

Represents a single frame of a TVShow/Movie/Skit generated using an instance of CompuGlobalAPI.

Parameters
  • api (CompuGlobalAPI) – The CompuGlobalAPI object that was used to generate the screencap.

  • frame_json (dict) – The json response from the API for the screencap.

Variables
  • json (dict) – The json response used to create the frame.

  • id (int) – The ID of the frame.

  • key (str) – The episode key (S01E01) of the frame.

  • timestamp (int) – The timestamp of the frame.

  • image_url (str) – The direct url for the frame image.

get_meme_url(caption=None)

Encodes the caption with base64 and then returns the meme url for the frame with an embedded caption.

Parameters

caption (str) – The caption to embed in the image.

Returns

The meme url for the frame with an embedded caption.

Return type

str

get_real_timestamp()

Gets a readable timestamp for the frame in format “mm:ss”

Returns

A readable timestamp for the frame in format mm:ss.

Return type

str

compuglobal.screencap module

class compuglobal.screencap.Screencap(api, json: dict)

Bases: object

Represents a screencap of a TVShow/Movie/Skit generated using an instance of CompuGlobalAPI.

Parameters
  • api (CompuGlobalAPI) – The CompuGlobalAPI object that was used to generate the screencap.

  • json (dict) – The json response from the API for the screencap.

Variables
  • frame (Frame) – The representative frame of the screencap.

  • id (int) – The screencap ID.

  • key (str) – The episode key (S01E01) of the screencap’s representative frame.

  • timestamp (int) – The timestamp of the screencap’s represenative frame.

  • episode (int) – The episode number of the screencap.

  • season (int) – The season number of the screencap.

  • title (str) – The title of the episode.

  • director (str) – The director(s) of the episode.

  • writer (str) – The writer(s) of the episode.

  • air_date (str) – The original air date of the episode.

  • wiki_url (str) – Url to the wiki of the episode.

  • caption (str) – The caption/subtitles during the screencap.

  • gif_url (str) – The gif url format for the screencap embedded with a caption.

  • mp4_url (str) – The mp4 url format for the screencap embedded with a caption.

get_gif_url(caption=None, before=3000, after=4000)

Gets the timestamps of the frames before and after the timestamp of the screencap using the frames endpoint for the screencap’s API and returns the url for the gif with an embedded caption.

Parameters
  • caption (str, optional) – The caption to embed in the gif, if it is None, it will use the screencaps original caption.

  • before (int, optional) – The number of milliseconds before the screencap’s timestamp to begin the gif, defaults to 3 seconds (3000ms).

  • after (int, optional) – The number of milliseconds after the screencap’s timestamp to begin the gif, defaults to 4 seconds (4000ms).

Returns

The gif url for the screencap with an embedded caption.

Return type

str

Note

Defaults gif duration to ~7 seconds (7000ms).

get_image_url()

Returns the direct image url for the screencap without any caption.

Returns

The image url for the screencap without any caption.

Return type

str

get_meme_url(caption=None)

Encodes the caption with base64 and then returns the meme url for the screencap with an embedded caption.

Parameters

caption (str, optional) – The caption to embed in the image, if it is None, it will use the screencaps original caption.

Returns

The meme url for the screencap with an embedded caption.

Return type

str

get_mp4_url(caption=None, before=3000, after=4000)

Gets the timestamps of the frames before and after the timestamp of the screencap using the frames endpoint for the screencap’s API and returns the url for the mp4 with an embedded caption.

Parameters
  • caption (str, optional) – The caption to embed in the mp4, if it is None, it will use the screencaps original caption.

  • before (int, optional) – The number of milliseconds before the screencap’s timestamp to begin the mp4, defaults to 3 seconds (3000ms).

  • after (int, optional) – The number of milliseconds after the screencap’s timestamp to begin the mp4, defaults to 4 seconds (4000ms).

Returns

The mp4 url for the screencap with an embedded caption.

Return type

str

Note

Defaults mp4 duration to ~7 seconds (7000ms).

get_real_timestamp()

Gets a readable timestamp for the frame in format “mm:ss”

Returns

A readable timestamp for the frame in format mm:ss.

Return type

str

static get_value(value)

Module contents

class compuglobal.CapitalBeatUs

Bases: compuglobal.CompuGlobalAPI

An API Wrapper for accessing CapitalBeatUs API endpoints (West Wing).

class compuglobal.CompuGlobalAPI(url, title)

Bases: object

Represents an API Wrapper used for accessing the cghmc API endpoints.

Parameters
  • url (str) – The url of the API.

  • title (str) – The title of the tv show/movie/skit that the url leads to.

Variables
  • random_url (str) – Endpoint used for getting a random screencap.

  • caption_url (str) – Endpoint for getting caption info using episode and timestamp e = episode & t = timestamp.

  • search_url (str) – Endpoint for getting screencaps using a search query q = search query.

  • frames_url (str) – Endpoint for getting all valid frames before & after an episode and timestamp episode/timestamp/before/after.

  • nearby_url (str) – Endpoint for getting all valid frames nearby an episode and timestamp e = episode & t = timestamp.

  • episode_url (str) – Endpoint for getting episode info and subtitles from start to end for episode episode/start/end.

static encode_caption(caption)

Loops through the caption and encodes it in base64 for use in the url.

Parameters

caption (str) – The caption to encode in base64.

Returns

The caption encoded in base64.

Return type

str

format_caption(caption, max_lines=4, max_chars=24, shorten=True)

Loops through the caption and formats it using max_lines and max_chars and returns the formatted outcome.

Parameters
  • caption (str) – The caption to format.

  • max_lines (int, optional) – The maximum number of lines of captions allowed.

  • max_chars (int, optional) – The maximum number of characters allowed per line.

  • shorten (bool, optional) – Whether to shorten the caption at its latest sentence ending.

Returns

The formatted caption.

Return type

str

generate_gif(gif_url)

Performs a GET request using gif_url and returns the direct url for the gif once it has been generated.

Parameters

gif_url (str) – The url of the gif to generate.

Returns

The direct url for the generated gif

Return type

str

Raises

APIPageStatusError – Raises an exception if the status code of the request is not 200.

get_frames(episode, timestamp, before, after)

Performs a GET request to the api/frames/{episode}/{timestamp}/{before}/{after} endpoint and gets a list of all valid frames before and after the timestamp of the episode.

Parameters
  • episode (str) – The episode key of the screencap.

  • timestamp (int) – The timestamp of the screencap.

  • before (int) – The number of milliseconds before the timestamp.

  • after (int) – The number of milliseconds after the timestamp.

Returns

A list of valid frames before and after the timestamp of the episode, containing the id, episode and timestamp for each frame.

Return type

list

Raises

APIPageStatusError – Raises an exception if the status code of the request is not 200.

Note

Used for displaying the valid frames available for the gifmaker.

get_nearby_frames(episode, timestamp)

Performs a GET request to the api/nearby?e={}&t={} endpoint and gets a list of seven nearby using the episode key e={} and timestamp t={} the episode.

Parameters
  • episode (str) – The episode key of the screencap.

  • timestamp (int) – The timestamp of the screencap.

Returns

A list of valid frames before and after the timestamp of the episode, containing the id, episode and timestamp for each frame.

Return type

list

Raises

APIPageStatusError – Raises an exception if the status code of the request is not 200.

Note

Used for displaying the seven frames in the “More from this scene:” frame selection screen with arrows.

get_random_screencap()

Performs a GET request to the api/random endpoint and gets a random TV Show screencap.

Returns

A random screencap object.

Return type

compuglobal.Screencap

Raises

APIPageStatusError – Raises an exception if the status code of the request is not 200.

Note

Used for getting a random screencap when clicking the “RANDOM” button.

get_screencap(episode=None, timestamp=None, frame=None)

Performs a GET request to the api/caption?e={}&t={} endpoint and gets a TV Show screencap using episode e={} and timestamp t={} or a frame

Parameters
  • episode (str, optional) – The episode key of the screencap.

  • timestamp (int, optional) – The timestamp of the screencap.

  • frame (compuglobal.Frame) – The frame of the screencap.

Returns

A Screencap objecct for the episode and timestamp.

Return type

compuglobal.Screencap

Raises

APIPageStatusError – Raises an exception if the status code of the request is not 200.

Note

Used for getting the episode info and caption shown below each screencap.

static json_to_caption(subtitles_json)

Loops through the subtitles of the json response, concatenates all lines and returns all subtitles combined as a complete caption.

Parameters

subtitles_json (dict) – The json response containing the subtitles of the screencap.

Returns

caption – The subtitles combined as a complete caption.

Return type

str

search(search_text)

Performs a GET request to the api/search?q= endpoint and gets a list of search results using the search text as the search query q={} for the request.

Parameters

search_text (str) – The text/quote to search for.

Returns

search_results – A list of search results containing the id, episode and timestamp for each result.

Return type

list

Raises
  • APIPageStatusError – Raises an exception if the status code of the request is not 200.

  • NoSearchResultsFound – Raises an exception if there are no search results found using search_text.

Note

Used for displaying all the search results and their screencaps.

search_for_screencap(search_text)

Performs a GET request to the api/search?q= endpoint using search() to get a list of search results using search_text and gets a screencap using the episode and timestamp of the first search result.

Parameters

search_text (str) – The text/quote to search for.

Returns

A screencap object of the first search result found using search_text.

Return type

compuglobal.Screencap

Raises
  • APIPageStatusError – Raises an exception if the status code of the request is not 200.

  • NoSearchResultsFound – Raises an exception if there are no search results found using search_text.

static shorten_caption(caption)

Loops through the caption and trims it at its latest sentence ending (., !, ? or ♪).

Parameters

caption (str) – The caption to shorten/trim.

Returns

caption – The shortened caption, ending at its latest sentence ending.

Return type

str

view_episode(episode, start, end)

Performs a GET request to the api/episode/{episode}/{start}/{end} endpoint and returns the json response containing episode information.

Parameters
  • episode (str) – The episode key of the screencap.

  • start (int) – The starting timestamp for the episode information.

  • end (int) – The ending timestamp for the episode information.

Returns

The json response containing the episode information and subtitles for the timestamps.

Return type

dict

Note

Used for displaying the rest of an episode when using the “View Episode” button next to each screencap.

class compuglobal.FrinkiHams

Bases: compuglobal.CompuGlobalAPI

An API Wrapper for accessing FriniHams API endpoints (The Simpsons - Steamed Hams Skit).

class compuglobal.Frinkiac

Bases: compuglobal.CompuGlobalAPI

An API Wrapper for accessing Frinkiac API endpoints (The Simpsons).

class compuglobal.GoodGodLemon

Bases: compuglobal.CompuGlobalAPI

An API Wrapper for accessing GoodGodLemon API endpoints (30 Rock).

class compuglobal.MasterOfAllScience

Bases: compuglobal.CompuGlobalAPI

An API Wrapper for accessing MasterOfAllScience API endpoints (Rick and Morty).

class compuglobal.Morbotron

Bases: compuglobal.CompuGlobalAPI

An API Wrapper for accessing Morbotron API endpoints (Futurama).