Repository: Flexget/Flexget

Issue:
 BUG: Unhandled error in plugin convert_magnet: 'save_path must be set in add_torrent_params'

### Expected behaviour:

<!---
Should be convert the magnet URI to torrent file
--->

### Actual behaviour:

### Steps to reproduce:
- Step 1: flexget execute 

#### Config:
```yaml
templates:
  torrent:
    transmission:
      host: localhost
      port: 9091
      username: XXXXX
      password: XXXXXX

  tv_showrss:
    all_series: yes
    convert_magnet: yes
    seen: local
    download: /mnt/kodi/complete/peliculas/
    template: torrent


  movies:
    template: torrent
    imdb:
      min_score: 5
      min_votes: 100
      min_year: 2020
      reject_genres:
        - horror
        - porn
        - anime
        - xxx
      accept_languages:
        - english
    imdb_lookup: yes
    unique:
      field:
        - imdb_id
        - movie_name
      action: reject
    seen: local
    convert_magnet: yes
    quality: 2160p
    download: /mnt/kodi/complete/peliculas/

tasks:
  series_task:
    rss:
      url: http://showrss.info/user/XXXXX.rss?magnets=true&namespaces=true&name=clean&quality=null&re=null
      escape: yes
      link:
        - link
        - magneturl
    template: tv_showrss
    retry_failed:
      retry_time: 30 minutes # Base time in between retries
      retry_time_multiplier: 2 # Amount retry time will be multiplied by after each successive failure
      max_retries: 5

  movies_task:
    rss:
      url: https://XXXXX.org/rssdd.php?categories=50;52
      escape: yes
      link:
        - link
        - magneturl
    template: movies
 

  move-episodes:
    metainfo_series: yes
    require_field: series_name
    accept_all: yes
    thetvdb_lookup: yes
    all_series:
      parse_only: yes
    filesystem:
      path: /mnt/kodi/complete/peliculas/
      regexp: '.*\.(avi|mkv|mp4|mpg)$'
      recursive: yes
    regexp:
      reject:
        - sample
    move:
      clean_source: 50
      to: '/mnt/kodi/complete/series/{{series_name}}/'
      clean_source: 1000
      along:
        extensions:
          - sub
          - srt
```
  
#### Log:
<details>
 <summary>(click to expand)</summary>

```
2023-05-28 12:27:57 CRITICAL task          movies_task     BUG: Unhandled error in plugin convert_magnet: 'save_path must be set in add_torrent_params'
Traceback (most recent call last):

  File "/usr/lib/python3.10/threading.py", line 973, in _bootstrap
    self._bootstrap_inner()
    │    └ <function Thread._bootstrap_inner at 0x7f6954bddb40>
    └ <Thread(task_queue, started daemon 140090266555968)>
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
    │    └ <function Thread.run at 0x7f6954bdd870>
    └ <Thread(task_queue, started daemon 140090266555968)>
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
    │    │        │    │        │    └ {}
    │    │        │    │        └ <Thread(task_queue, started daemon 140090266555968)>
    │    │        │    └ ()
    │    │        └ <Thread(task_queue, started daemon 140090266555968)>
    │    └ <bound method TaskQueue.run of <flexget.task_queue.TaskQueue object at 0x7f694ed09a50>>
    └ <Thread(task_queue, started daemon 140090266555968)>
  File "/usr/local/lib/python3.10/dist-packages/flexget/task_queue.py", line 46, in run
    self.current_task.execute()
    │    │            └ <function Task.execute at 0x7f6951d9dc60>
    │    └ <flexget.task.Task object at 0x7f694e9a7d30>
    └ <flexget.task_queue.TaskQueue object at 0x7f694ed09a50>
  File "/usr/local/lib/python3.10/dist-packages/flexget/task.py", line 87, in wrapper
    return func(self, *args, **kw)
           │    │      │       └ {}
           │    │      └ ()
           │    └ <flexget.task.Task object at 0x7f694e9a7d30>
           └ <function Task.execute at 0x7f6951d9dbd0>
  File "/usr/local/lib/python3.10/dist-packages/flexget/task.py", line 725, in execute
    self._execute()
    │    └ <function Task._execute at 0x7f6951d9db40>
    └ <flexget.task.Task object at 0x7f694e9a7d30>
  File "/usr/local/lib/python3.10/dist-packages/flexget/task.py", line 694, in _execute
    self.__run_task_phase(phase)
    │                     └ 'download'
    └ <flexget.task.Task object at 0x7f694e9a7d30>
  File "/usr/local/lib/python3.10/dist-packages/flexget/task.py", line 514, in __run_task_phase
    response = self.__run_plugin(plugin, phase, args)
               │                 │       │      └ (<flexget.task.Task object at 0x7f694e9a7d30>, True)
               │                 │       └ 'download'
               │                 └ <PluginInfo(name=convert_magnet)>
               └ <flexget.task.Task object at 0x7f694e9a7d30>
> File "/usr/local/lib/python3.10/dist-packages/flexget/task.py", line 547, in __run_plugin
    result = method(*args, **kwargs)
             │       │       └ {}
             │       └ (<flexget.task.Task object at 0x7f694e9a7d30>, True)
             └ <Event(name=plugin.convert_magnet.download,func=on_task_download,priority=130)>
  File "/usr/local/lib/python3.10/dist-packages/flexget/event.py", line 20, in __call__
    return self.func(*args, **kwargs)
           │    │     │       └ {}
           │    │     └ (<flexget.task.Task object at 0x7f694e9a7d30>, True)
           │    └ <bound method ConvertMagnet.on_task_download of <flexget.components.bittorrent.convert_magnet.ConvertMagnet object at 0x7f694...
           └ <Event(name=plugin.convert_magnet.download,func=on_task_download,priority=130)>
  File "/usr/local/lib/python3.10/dist-packages/flexget/components/bittorrent/convert_magnet.py", line 102, in on_task_download
    torrent_file = self.magnet_to_torrent(entry['url'], converted_path, timeout)
                   │    │                 │             │               └ 30.0
                   │    │                 │             └ '/home/wooltar/.flexget/converted'
                   │    │                 └ <Entry(title=Venom.Let.There.Be.Carnage.2021.2160p.UHD.BluRay.x265.10bit.HDR.TrueHD.7.1.Atmos-RARBG,state=accepted)>
                   │    └ <function ConvertMagnet.magnet_to_torrent at 0x7f69500f1900>
                   └ <flexget.components.bittorrent.convert_magnet.ConvertMagnet object at 0x7f694ecbee60>
  File "/usr/local/lib/python3.10/dist-packages/flexget/components/bittorrent/convert_magnet.py", line 47, in magnet_to_torrent
    handle = session.add_torrent(params)
             │       │           └ <libtorrent.add_torrent_params object at 0x7f69483267f0>
             │       └ <Boost.Python.function object at 0x7f6948036b80>
             └ <libtorrent.session object at 0x7f694ec13150>```
```
</details>

### Additional information:

- FlexGet version: 3.7.2
- Python version: 3.10.6
- Installation method: pip3 
- Using daemon (yes/no): no
- OS and version: Ubuntu 22.04.2 LTS
- Link to crash log:




Discussion:
fixed downgrading libtorrent to 2.0.7
Yes, downgrading indeed works around the issue. This is not a proper fix however, and this should be reopened.
Still observing this issue, let's open up if possible.
FWIW the problem was introduced by [this commit](https://github.com/arvidn/libtorrent/commit/c5be3bd9980ff4be5b2b09f55f27e21698c99870) (that came after 2.0.8 and is included in 2.0.9), that fixes a missing parameter check.
We need changes to work with newer libtorrent then? And they will still work with the older libtorrent? I think we should do that, if someone could open a PR that would be great.
I've run into this and ended up inserting  `params.save_path = destination_folder` before the call to `session.add_torrent(params)`. That got rid of the error, but torrents are not being copied from the `.flexget/converted` directory to the path specified by the `download:` directive. This however may or may not be related to my grotty attempt at fixing the error.

Edit: Copying the torrent files into place started working. No idea what was up with that.
tried the @elfez workaround, seems that's working as temp fix. Will check if there's any errors on my side on different cases.

Resolving patch:
diff --git a/flexget/components/bittorrent/convert_magnet.py b/flexget/components/bittorrent/convert_magnet.py
--- a/flexget/components/bittorrent/convert_magnet.py
+++ b/flexget/components/bittorrent/convert_magnet.py
@@ -44,6 +44,7 @@ def magnet_to_torrent(self, magnet_uri, destination_folder, timeout):
             params['url'] = magnet_uri
         else:
             params.url = magnet_uri
+        params.save_path = destination_folder
         handle = session.add_torrent(params)
         logger.debug('Acquiring torrent metadata for magnet {}', magnet_uri)
         timeout_value = timeout


Test patch: