Module actions

Module responsible for searching movies in Internet services. As for now only YouTube is supported.

class ytfs.actions.YTActions(search_query)[source]

Class responsible for searching in YouTube service and holding information about search results.

Parameters:

search_query : str

Currently used search phrase.

Attributes

avail_files (OrderedDict) Contains tuples of following format: avail_files = { “token”: (adj_tokens, files), ... } adj_tokens contains adjacent tokens, files contains files of given search. (just as described below).
visible_files (dict) Current search results. Key is a movie name, value is a YTStor object for given movie.
adj_tokens (dict) Dictionary of tokens for adjacent search pages. Under False key the previous page is kept, under True - the next. Other keys are not allowed.
vf_iter (obj) Here the YTActions obejct stores an iterator allowing for current directory content listing. Used by __iter__ and __next__ methods.
search_params (dict) Additional search params for __search.
yts_opts (dict) Custom options passed to YTStor objects created in this class.
api_key (str) YouTube API key.
preferences (dict) Current object preferences.
_YTActions__getChannelId()

Obtain channel id for channel name, if present in self.search_params.

Method responsible for searching using YouTube API.

Parameters:

pt : str

Token of search results page. If None, then the first page is downloaded.

Returns:

results : dict

Parsed JSON returned by YouTube API.

_YTActions__searchParser(query)

Parse query for advanced search options.

Parameters:

query : str

Search query to parse. Besides a search query, user can specify additional search parameters and YTFS specific options. Syntax: Additional search parameters: option:value. if value contains spaces, then surround it with parentheses; available parameters: channel, max, before, after. YTFS options: specify options between [ and ]; Available options: a, v, f, P, s, m. If an option takes a parameter, then specify it beetween parentheses.

Examples: channel:foo search query, my favourite music [a], channel:(the famous funny cats channel) [vf(240)P] funny cats max:20.

Invalid parameters/options are ignored.

Returns:

params : tuple

Tuple: 0 - dictionary of url GET parameters; 1 - dictionary of YTStor options.

__getitem__(key)[source]

Read elements from YTActions object by using key. One can use object like a dict (and like a boss, ofc).

Parameters:

key : str

The key (e.g. YTActions['Rick Astley - Never Gonna Give You Up.mp4']).

Returns:

YTStor

YTStor object associated with name key.

__in__(arg)[source]

Check, if movie of name arg is present in the object.

Parameters:

arg : str

Filename.

__iter__()[source]

Create an iterator. Method allows - in a simple manner - for obtaining a generator which contains filenames. The real generator is self.vf_iter; YTActions object (used as iterator) is only a wrapper.

Returns:

self : YTActions

This very same object with self.vf_iter constructed and initialised.

__next__()[source]

next() support. Returns next filename.

Returns:

file_name : str

Next filename from self.vf_iter.

clean()[source]

Clear the data. For each YTStor object present in this object clean method is executed.

updateResults(forward=None)[source]

Reload search results or load another “page”.

Parameters:

forward : bool or None, optional

Whether move forwards or backwards (True or False). If None, then first page is loaded.