Repository: Flexget/Flexget

Issue:
 <urlopen error [Errno 2] No such file or directory with # in filename
<!---
Before opening an issue, verify:

- Is this a feature request? Post it on https://feathub.com/Flexget/Flexget
- Is this an issue with webui? Make an issue over on https://github.com/Flexget/webui
- Did you recently upgrade? Look at the Change Log and Upgrade Actions to make sure that you don't need to make any changes to your config https://flexget.com/ChangeLog https://flexget.com/UpgradeActions
- Are you running FlexGet as a daemon? Stop it completely and then start it again https://flexget.com/CLI/daemon
- Did you search to see if the issue already exists? https://github.com/Flexget/Flexget/issues
- Did you fill out the issue template as completely as possible?

The issue template is here because it helps to ensure you submitted all the necessary information the first time, and allows us to more quickly review issues. Please fill it out correctly and do not ignore it, no matter how irrelevant you think it may be. Thanks in advance for your help with this!
--->

### Expected behaviour:
Magnet link file would be copied over to download folder.  Doesnt seem to be any issues with other magnet links 
<!---
Please don't just say "it doesn't crash" or "it works". Explain what the expected result is.
--->

### Actual behaviour:
Receive a error and file is not copied over to download folder.

### Steps to reproduce:
- Step 1: 

#### Config:
```yaml
tasks:
  music_task:
    rss: http://rarbg.to/rssdd.php?categories=2;23;24;25;26
    series:
      - VA
    download: /mnt_qbittorrent/watch_music/
    convert_magnet: yes
```
  
#### Log:
<details>
 <summary>(click to expand)</summary>

```
2022-06-07 15:57:56 VERBOSE  task          music_task      ACCEPTED: `VA - Beatport Jackin House: Sound Pack #530 (2022) MP3 [320 kbps]` by series plugin because choosing first acceptable match
2022-06-07 15:57:56 VERBOSE  task          music_task      ACCEPTED: `VA - 100 Greatest Southern Rap Songs (2022) MP3 [320 kbps]` by series plugin because choosing first acceptable match
2022-06-07 15:57:56 VERBOSE  task          music_task      REJECTED: `VA - Disco Schlager Mix Sommer (2022) MP3 [320 kbps]` by series plugin because quality already downloaded
2022-06-07 15:57:56 VERBOSE  task          music_task      REJECTED: `VA - Cafe Del Mar [Music Essentials Collection] (2022) MP3 [320 kbps]` by series plugin because quality already downloaded
2022-06-07 15:57:56 VERBOSE  task          music_task      ACCEPTED: `VA - Beatport Future House: Sound Pack #531 (2022) MP3 [320 kbps]` by series plugin because choosing first acceptable match
2022-06-07 15:57:56 INFO     convert_magnet music_task      Converting entry VA - Beatport Jackin House: Sound Pack #530 (2022) MP3 [320 kbps] magnet URI to a torrent file
2022-06-07 15:58:11 INFO     convert_magnet music_task      Converting entry VA - 100 Greatest Southern Rap Songs (2022) MP3 [320 kbps] magnet URI to a torrent file
2022-06-07 15:58:26 INFO     convert_magnet music_task      Converting entry VA - Beatport Future House: Sound Pack #531 (2022) MP3 [320 kbps] magnet URI to a torrent file
2022-06-07 15:58:41 INFO     download      music_task      Downloading: VA - Beatport Jackin House: Sound Pack #530 (2022) MP3 [320 kbps]
2022-06-07 15:58:41 ERROR    utils.requests music_task      Error getting file:///flexget/converted/Beatport Jackin House. Sound Pack #530.torrent: <urlopen error [Errno 2] No such file or directory: '/flexget/converted/Beatport Jackin House. Sound Pack '>
2022-06-07 15:58:41 WARNING  download      music_task      RequestException Error getting file:///flexget/converted/Beatport Jackin House. Sound Pack #530.torrent: <urlopen error [Errno 2] No such file or directory: '/flexget/converted/Beatport Jackin House. Sound Pack '>, while downloading file:///flexget/converted/Beatport Jackin House. Sound Pack #530.torrent
2022-06-07 15:58:41 WARNING  download      music_task      Can't download magnet url
2022-06-07 15:58:41 ERROR    entry         music_task      Failed VA - Beatport Jackin House: Sound Pack #530 (2022) MP3 [320 kbps] (Network error during request: Error getting file:///flexget/converted/Beatport Jackin House. Sound Pack #530.torrent: <urlopen error [Errno 2] No such file or directory: '/flexget/converted/Beatport Jackin House. Sound Pack '>, Magnet URL)
2022-06-07 15:58:41 INFO     task          music_task      Plugin retry_failed has requested task to be ran again after execution has completed.
2022-06-07 15:58:41 VERBOSE  task          music_task      FAILED: `VA - Beatport Jackin House: Sound Pack #530 (2022) MP3 [320 kbps]` by download plugin because network error during request: Error getting file:///flexget/converted/Beatport Jackin House. Sound Pack #530.torrent: <urlopen error [Errno 2] No such file or directory: '/flexget/converted/Beatport Jackin House. Sound Pack '>, Magnet URL
2022-06-07 15:58:41 INFO     download      music_task      Downloading: VA - 100 Greatest Southern Rap Songs (2022) MP3 [320 kbps]
2022-06-07 15:58:41 INFO     download      music_task      Downloading: VA - Beatport Future House: Sound Pack #531 (2022) MP3 [320 kbps]
2022-06-07 15:58:41 ERROR    utils.requests music_task      Error getting file:///flexget/converted/Beatport Future House. Sound Pack #531.torrent: <urlopen error [Errno 2] No such file or directory: '/flexget/converted/Beatport Future House. Sound Pack '>
2022-06-07 15:58:41 WARNING  download      music_task      RequestException Error getting file:///flexget/converted/Beatport Future House. Sound Pack #531.torrent: <urlopen error [Errno 2] No such file or directory: '/flexget/converted/Beatport Future House. Sound Pack '>, while downloading file:///flexget/converted/Beatport Future House. Sound Pack #531.torrent
2022-06-07 15:58:41 WARNING  download      music_task      Can't download magnet url
2022-06-07 15:58:41 ERROR    entry         music_task      Failed VA - Beatport Future House: Sound Pack #531 (2022) MP3 [320 kbps] (Network error during request: Error getting file:///flexget/converted/Beatport Future House. Sound Pack #531.torrent: <urlopen error [Errno 2] No such file or directory: '/flexget/converted/Beatport Future House. Sound Pack '>, Magnet URL)
2022-06-07 15:58:41 VERBOSE  task          music_task      FAILED: `VA - Beatport Future House: Sound Pack #531 (2022) MP3 [320 kbps]` by download plugin because network error during request: Error getting file:///flexget/converted/Beatport Future House. Sound Pack #531.torrent: <urlopen error [Errno 2] No such file or directory: '/flexget/converted/Beatport Future House. Sound Pack '>, Magnet URL
2022-06-07 15:58:41 VERBOSE  details       music_task      Summary - Accepted: 1 (Rejected: 7 Undecided: 19 Failed: 2)
2022-06-07 15:58:41 INFO     download      music_task      File `/mnt_qbittorrent/watch_music/100 Greatest Southern Rap Songs (2022).torrent` already exists and is not identical, download failed.
2022-06-07 15:58:41 ERROR    entry         music_task      Failed VA - 100 Greatest Southern Rap Songs (2022) MP3 [320 kbps] (File `/mnt_qbittorrent/watch_music/100 Greatest Southern Rap Songs (2022).torrent` already exists and is not identical.)
2022-06-07 15:58:41 VERBOSE  task          music_task      FAILED: `VA - 100 Greatest Southern Rap Songs (2022) MP3 [320 kbps]` by download plugin because file `/mnt_qbittorrent/watch_music/100 Greatest Southern Rap Songs (2022).torrent` already exists and is not identical.
2022-06-07 15:58:41 INFO     task          music_task      Rerunning the task in case better resolution can be achieved.
2022-06-07 15:58:41 VERBOSE  input_cache   music_task      Restored entries from cache
2022-06-07 15:58:41 VERBOSE  backlog       music_task      Added 4 entries from backlog
2022-06-07 15:58:41 VERBOSE  details       music_task      Produced 29 entries.
2022-06-07 15:58:41 VERBOSE  task          music_task      REJECTED: `VA - Deep House Summer Charts (2022) MP3 [320 kbps]` by seen plugin because entry with title `VA - Deep House Summer Charts (2022) MP3 [320 kbps]` is already marked seen in the task music_task at 2022-06-07 15:06
2022-06-07 15:58:41 VERBOSE  task          music_task      REJECTED: `VA - Beatport Jackin House: Sound Pack #530 (2022) MP3 [320 kbps]` by retry_failed plugin because waiting before retrying entry which has failed in the past. (failure reason: Network error during request: Error getting file:///flexget/converted/Beatport Jackin House. Sound Pack #530.torrent: <urlopen error [Errno 2] No such file or directory: '/flexget/converted/Beatport Jackin House. Sound Pack '>, Magnet URL)
2022-06-07 15:58:41 VERBOSE  task          music_task      REJECTED: `VA - 100 Greatest Southern Rap Songs (2022) MP3 [320 kbps]` by retry_failed plugin because waiting before retrying entry which has failed in the past. (failure reason: File `/mnt_qbittorrent/watch_music/100 Greatest Southern Rap Songs (2022).torrent` already exists and is not identical.)
2022-06-07 15:58:41 VERBOSE  task          music_task      REJECTED: `VA - Beatport Future House: Sound Pack #531 (2022) MP3 [320 kbps]` by retry_failed plugin because waiting before retrying entry which has failed in the past. (failure reason: Network error during request: Error getting file:///flexget/converted/Beatport Future House. Sound Pack #531.torrent: <urlopen error [Errno 2] No such file or directory: '/flexget/converted/Beatport Future House. Sound Pack '>, Magnet URL)
2022-06-07 15:58:41 VERBOSE  task          music_task      REJECTED: `VA - Cafe Del Mar [Music Essentials Collection] (2022) MP3 [320 kbps]` by retry_failed plugin because waiting before retrying entry which has failed in the past. (failure reason: File `/mnt_qbittorrent/watch_music/Cafe Del Mar Music Essentials Collection (2022).torrent` already exists and is not identical.)
2022-06-07 15:58:41 VERBOSE  task          music_task      REJECTED: `VA - Beatport Jackin House: Sound Pack #530 (2022) MP3 [320 kbps]` by retry_failed plugin because waiting before retrying entry which has failed in the past. (failure reason: Network error during request: Error getting file:///flexget/converted/Beatport Jackin House. Sound Pack #530.torrent: <urlopen error [Errno 2] No such file or directory: '/flexget/converted/Beatport Jackin House. Sound Pack '>, Magnet URL)
2022-06-07 15:58:41 VERBOSE  task          music_task      REJECTED: `VA - Beatport Future House: Sound Pack #531 (2022) MP3 [320 kbps]` by retry_failed plugin because waiting before retrying entry which has failed in the past. (failure reason: Network error during request: Error getting file:///flexget/converted/Beatport Future House. Sound Pack #531.torrent: <urlopen error [Errno 2] No such file or directory: '/flexget/converted/Beatport Future House. Sound Pack '>, Magnet URL)
2022-06-07 15:58:41 VERBOSE  task          music_task      REJECTED: `VA - 100 Greatest Southern Rap Songs (2022) MP3 [320 kbps]` by retry_failed plugin because waiting before retrying entry which has failed in the past. (failure reason: File `/mnt_qbittorrent/watch_music/100 Greatest Southern Rap Songs (2022).torrent` already exists and is not identical.)
2022-06-07 15:58:41 VERBOSE  task          music_task      REJECTED: `VA - Disco Schlager Mix Sommer (2022) MP3 [320 kbps]` by series plugin because quality already downloaded
2022-06-07 15:58:41 VERBOSE  task          music_task      REJECTED: `VA - Cafe Del Mar [Music Essentials Collection] (2022) MP3 [320 kbps]` by series plugin because quality already downloaded
2022-06-07 15:58:41 VERBOSE  details       music_task      Summary - Accepted: 0 (Rejected: 10 Undecided: 19 Failed: 0)
2022-06-07 15:58:42 INFO     performance                   Performance results for task music_task:
2022-06-07 15:58:42 INFO     performance                   convert_magnet  took 44.67 sec (0 queries)
2022-06-07 15:58:42 INFO     performance                   rss             took 0.83 sec (0 queries)
```
</details>

### Additional information:

- FlexGet version: 3.3.15
- Python version: 3.6.9
- Installation method: pip
- Using daemon (yes/no): no
- OS and version: Ubuntu 18.04
- Link to crash log:

<!---
In config and debug/crash logs, remember to redact any personal or sensitive information such as passwords, API keys, private URLs and so on.

Please verify that the following data is present before submitting your issue:

- Link to a paste service or paste above the relevant config (preferably full config, including templates if present). Please make sure the paste does not expire, if possible.
- Link to a paste service or paste above debug-level logs of the relevant task/s (use `flexget -L debug execute --tasks <Task_name>`).
- FlexGet version (use `flexget -V` to get it).
- Full Python version, for example `2.7.11` (use `python -V` to get it). 
- Installation method (pip, git install, etc).
- Whether or not you're running FlexGet as a daemon.
- OS and version.
- Attach crash log if one was generated, in addition to the debug-level log. It can be found in the directory with your config file.
--->



Discussion:

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
@@ -1,5 +1,6 @@
 import os
 import time
+from urllib.parse import quote
 
 from loguru import logger
 
@@ -114,7 +115,7 @@ def on_task_download(self, task, config):
                 entry['url'] = torrent_file
                 entry['file'] = torrent_file
                 # make sure it's first in the list because of how download plugin works
-                entry['urls'].insert(0, 'file://{}'.format(torrent_file))
+                entry['urls'].insert(0, 'file://{}'.format(quote(torrent_file)))
 
 
 @event('plugin.register')


Test patch: