Module stor

Module responsible for downloading multimedia from Internet services. As for now only YouTube is supported.

class ytfs.stor.Downloader[source]

Class responsible for data downloading. Every object similiar to YTStor can use it. (Currently no class, other than aforementioned YTStor, is capable of using Downloader).

static fetch(yts, needed_range, fh)[source]

Download desired range of data and put it in yts object (e.g. YTStor).

Parameters:

yts : YTStor

Stor-like object to which we will write.

needed_range : tuple

Two element tuple that represents a data range - compliant with range_t subrange definition.

fh : int

Descriptor used by a process for filesystem operations.

Returns:

None

Method does not return; data is written directly to yts object.

class ytfs.stor.YTMetaStor(init_data, opts={})[source]

Class that holds metadata in a seperate file. Should always correspond to existing *Stor object, though this relation isn’t held anywhere in *Stor objects, they’ll just share a filename, but with different extensions.

clean()[source]

Close file-like object.

obtainInfo()[source]

Just return.

read(offset, length, fh)[source]

Read data.

Parameters:

offset : int

Read offset.

length : int

Length of data.

fh : int

File descriptor, ignored.

registerHandler(fh)[source]

Update atime.

unregisterHandler(fh)[source]

Just pass.

class ytfs.stor.YTStor(init_data, opts={})[source]

YTStor - the heart of YTFS. Class responsible for obtaining and storing data and information about a movie of given id.

Parameters:

init_data : dict

Initial data object needed for further operation. YTStor needs yid (str, YouTube video id) and pub_date (video publication date as Unix timestamp).

opts : dict

Options that will override globally set preferences.

Attributes

data (SpooledTemporaryFile) Temporary file object - actual data is stored here.
lock (Lock) Lock to sync multiple threads.
fds (set) Set of file descriptors assigned to the object.
closing (bool) True if data is scheduled for closing.
avail (range_t) Object saying how much data we have.
filesize (int) Total data size. Not yet downloaded data is also considered.
disk (int) How much data is cached on disk (8M factor).
extension (str) File extension.
rickastley (bool) Make every video rickroll
r_session (requests.Session) Object that holds HTTP session. Thanks to that, we avoid useless TCP window size negotiations whenever we start a download.
yid (str) YouTube id of a video which this object represents.
preferences (dict) Current object preferences.
url (str or tuple) Url to file. If tuple, then merging is needed; indices: 0: video, 1: audio.
clean()[source]

Clear data. Explicitly close self.data if object is unused.

obtainInfo()[source]

Method for obtaining information about the movie.

read(offset, length, fh)[source]

Read data. Method returns data instantly, if they’re avaialable and in self.safe_range. Otherwise data is downloaded and then returned.

Parameters:

offset : int

Read offset

length : int

Length of data to read.

fh : int

File descriptor.

registerHandler(fh)[source]

Register new file descriptor.

Parameters:

fh : int

File descriptor.

unregisterHandler(fh)[source]

Unregister a file descriptor. Clean data, if such operation has been scheduled.

Parameters:

fh : int

File descriptor.