Skip to content

Commit

Permalink
Use default settings for downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Apr 13, 2022
1 parent 0dc490c commit 2a96c4e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import base64

from configobj import ConfigObj

from validate import Validator

from tribler.core.components.libtorrent.settings import DownloadDefaultsSettings
from tribler.core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt
from tribler.core.exceptions import InvalidConfigException
from tribler.core.utilities.install_dir import get_lib_path
Expand Down Expand Up @@ -40,6 +40,21 @@ def load(config_path=None):
return DownloadConfig(ConfigObj(infile=Path.fix_win_long_file(config_path), file_error=True,
configspec=str(CONFIG_SPEC_PATH), default_encoding='utf-8'))

@staticmethod
def convert(settings: DownloadDefaultsSettings):
config = DownloadConfig()

config.set_hops(settings.number_hops)
config.set_safe_seeding(settings.safeseeding_enabled)

destination_directory = settings.saveas
if destination_directory is None:
destination_directory = get_default_dest_dir()

config.set_dest_dir(destination_directory)

return config

def copy(self):
return DownloadConfig(ConfigObj(self.config, configspec=str(CONFIG_SPEC_PATH), default_encoding='utf-8'),
state_dir=self.state_dir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,12 @@ async def start_download_from_uri(self, uri, config=None):
return self.start_download(torrent_file=file, config=config)
raise Exception("invalid uri")

def start_download(self, torrent_file=None, tdef=None, config=None, checkpoint_disabled=False, hidden=False):
self._logger.debug("Starting download: filename: %s, torrent def: %s", torrent_file, tdef)
def start_download(self, torrent_file=None, tdef=None, config: DownloadConfig = None, checkpoint_disabled=False,
hidden=False) -> Download:
self._logger.debug(f'Starting download: filename: {torrent_file}, torrent def: {tdef}')
if config is None:
config = DownloadConfig.convert(self.download_defaults)
self._logger.debug(f'Use a default config.')

# the priority of the parameters is: (1) tdef, (2) torrent_file.
# so if we have tdef, and torrent_file will be ignored, and so on.
Expand All @@ -548,7 +552,6 @@ def start_download(self, torrent_file=None, tdef=None, config=None, checkpoint_d

assert tdef is not None, "tdef MUST not be None after loading torrent"

config = config or DownloadConfig()
infohash = tdef.get_infohash()
download = self.get_download(infohash)

Expand Down
4 changes: 2 additions & 2 deletions src/tribler/core/components/libtorrent/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from pydantic import validator

from tribler.core.components.libtorrent.download_manager.download_config import get_default_dest_dir
from tribler.core.config.tribler_config_section import TriblerConfigSection
from tribler.core.utilities.network_utils import NetworkUtils


# pylint: disable=no-self-argument


Expand Down Expand Up @@ -51,7 +51,7 @@ class DownloadDefaultsSettings(TriblerConfigSection):
anonymity_enabled: bool = True
number_hops: int = 1
safeseeding_enabled: bool = True
saveas: Optional[str] = str(get_default_dest_dir())
saveas: Optional[str] = None
seeding_mode: SeedingMode = SeedingMode.forever
seeding_ratio: float = 2.0
seeding_time: float = 60
Expand Down

0 comments on commit 2a96c4e

Please sign in to comment.