The seedbox.torrent.parser Module

Parses a torrent file.

class seedbox.torrent.parser.Bdecode(data)

Bases: object

decode()

Decode torrent content.

Returns:parsed content
classmethod parse(data)

Helper method that creates decoder and decodes content.

Returns:parsed content
exception seedbox.torrent.parser.ParsingError(error_msg)

Bases: exceptions.Exception

Holds parsing error messages.

Error class representing errors that occur while parsing the torrent content.

class seedbox.torrent.parser.TorrentParser(filepath)

Bases: object

Reads the torrent file and parses content.

Parameters:filepath (str) – Path to the torrent file to be parsed
Raises IOError:when a file does not exists
content
get_file_details()

Retrieves details of the file(s) contained in the torrent.

File details tuple:
  • name
  • length (size)
Returns:file details embedded within torrent
Return type:list of tuples (name, length)
load_content()

Reads the torrent file and decodes content.

Note

bencode is supremely more efficient parser for torrents but extremely strict in the format of the file. A custom parser based on another implementation handles parsing that is more flexible but it is not as efficient. Therefore when the file is well formed bencode is used but if it fails then the custom parser is used. If the custom parser fails then a ParsingError is raised.