Hide keyboard shortcuts

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> 

3 

4This file is part of torrent-download. 

5 

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. 

10 

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. 

15 

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""" 

19 

20import os 

21from typing import Optional 

22from puffotter.os import makedirs 

23from torrent_download.entities.TorrentInfo import TorrentInfo 

24 

25 

26class TorrentDownload: 

27 """ 

28 Class used to store all information required for downloading a torrent 

29 """ 

30 

31 def __init__( 

32 self, 

33 torrent_info: TorrentInfo, 

34 destination_dir: str, 

35 destination_filename: Optional[str] = None 

36 ): 

37 """ 

38 Initializes the TorrentDownload object 

39 :param torrent_info: The torrent information 

40 :param destination_dir: The destination directory 

41 :param destination_filename: Optional filename, if not provided will 

42 be automatically inferred 

43 """ 

44 self.torrent_info = torrent_info 

45 self.destination_dir = destination_dir 

46 makedirs(destination_dir) 

47 if destination_filename is None: 

48 if torrent_info.filename is None: 

49 self.destination = destination_dir 

50 else: 

51 self.destination = os.path.join( 

52 destination_dir, torrent_info.filename 

53 ) 

54 else: 

55 self.destination = os.path.join( 

56 destination_dir, destination_filename 

57 ) 

58 

59 def add_extension(self, ext: str): 

60 """ 

61 Adds an extension to the destination filename 

62 :param ext: The extension to add 

63 :return: None 

64 """ 

65 if not self.destination.endswith(f".{ext}"): 

66 self.destination += f".{ext}"