Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2021 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of torrent-download.
6torrent-download is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11torrent-download is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with torrent-download. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from typing import Optional
21from puffotter.units import human_readable_bytes
24class TorrentInfo:
25 """
26 Class that stores information for a torrent
27 """
29 def __init__(
30 self,
31 filename: Optional[str],
32 torrent_file: Optional[str],
33 magnet_link: Optional[str],
34 size: Optional[int]
35 ):
36 """
37 Initializes the torrent info object
38 :param filename: The name of the file for the torrent
39 :param torrent_file: The link to the torrent file
40 :param magnet_link: A magnet link to the torrent
41 :param size: The size of the file in bytes
42 """
43 if torrent_file is None and magnet_link is None:
44 raise ValueError("No torrent information provided")
45 self.filename = filename
46 self.torrent_file = torrent_file
47 self.magnet_link = magnet_link
48 self.size = size
50 def __str__(self) -> str:
51 """
52 :return: A string representation of the torrent
53 """
54 return f"{self.filename} [{human_readable_bytes(self.size)}]"