Repository: pymedusa/Medusa

Issue:
Torznab via Newnab issue
### Before submitting your issue:

Enable debug logging in Medusa settings, reproduce the error (be sure to disable after the bug is fixed)

**Branch/Commit:** master/3f23fd272652b10cf781e3058fee50daf79f11b6
**OS:** Linux
**What you did:** manual and auto search of a episode
**What happened:** torrents snatched via newsnab (jackett indexer) are not created in blackhole folder. After a lenghty discussion on irc with @medusabot ,he/she stated that medusa basically thinks we are downloading an nzb. Like lots of people, i have always added jackett torznab link in the newsnab section because there was no torznab section when i was using sickrage and it always worked. Now i switch over to medusa and it was working at first and now it stopped working. This is really a deal breaker right now because my primary French torrent indexer, ethor.net is only accessible via jackett.

**Logs:**
```
2017-10-05 16:14:48 DEBUG    TORNADO :: [3f23fd2] API :: history: {'limit': '100', 'type': 'downloaded'}
2017-10-05 16:14:48 DEBUG    TORNADO :: [3f23fd2] API :: all kwargs: {'type': 'downloaded', 'cmd': 'history', 'limit': '100'}
2017-10-05 16:14:48 DEBUG    TORNADO :: [3f23fd2] API :: all args: ()
2017-10-05 16:14:48 DEBUG    TORNADO :: [3f23fd2] API :: 192.168.13.198 - gave correct API KEY. ACCESS GRANTED
2017-10-05 16:14:48 DEBUG    TORNADO :: [3f23fd2] API :: future: {'sort': 'date', 'type': 'missed|today|soon|later'}
2017-10-05 16:14:48 DEBUG    TORNADO :: [3f23fd2] API :: all kwargs: {'sort': 'date', 'cmd': 'future', 'type': 'missed|today|soon|later'}
2017-10-05 16:14:48 DEBUG    TORNADO :: [3f23fd2] API :: all args: ()
2017-10-05 16:14:48 DEBUG    TORNADO :: [3f23fd2] API :: 192.168.13.198 - gave correct API KEY. ACCESS GRANTED
2017-10-05 16:14:41 DEBUG    TORNADO :: [3f23fd2] API :: history: {'limit': '100', 'type': 'downloaded'}
2017-10-05 16:14:41 DEBUG    TORNADO :: [3f23fd2] API :: all kwargs: {'type': 'downloaded', 'cmd': 'history', 'limit': '100'}
2017-10-05 16:14:41 DEBUG    TORNADO :: [3f23fd2] API :: all args: ()
2017-10-05 16:14:41 DEBUG    TORNADO :: [3f23fd2] API :: 192.168.13.198 - gave correct API KEY. ACCESS GRANTED
2017-10-05 16:14:41 DEBUG    TORNADO :: [3f23fd2] API :: future: {'sort': 'date', 'type': 'missed|today|soon|later'}
2017-10-05 16:14:41 DEBUG    TORNADO :: [3f23fd2] API :: all kwargs: {'sort': 'date', 'cmd': 'future', 'type': 'missed|today|soon|later'}
2017-10-05 16:14:41 DEBUG    TORNADO :: [3f23fd2] API :: all args: ()
2017-10-05 16:14:41 DEBUG    TORNADO :: [3f23fd2] API :: 192.168.13.198 - gave correct API KEY. ACCESS GRANTED
2017-10-05 16:14:30 DEBUG    TORNADO :: [3f23fd2] API :: history: {'limit': '100', 'type': 'downloaded'}
2017-10-05 16:14:30 DEBUG    TORNADO :: [3f23fd2] API :: all kwargs: {'type': 'downloaded', 'cmd': 'history', 'limit': '100'}
2017-10-05 16:14:30 DEBUG    TORNADO :: [3f23fd2] API :: all args: ()
2017-10-05 16:14:30 DEBUG    TORNADO :: [3f23fd2] API :: 192.168.13.198 - gave correct API KEY. ACCESS GRANTED
2017-10-05 16:14:30 DEBUG    TORNADO :: [3f23fd2] API :: future: {'sort': 'date', 'type': 'missed|today|soon|later'}
2017-10-05 16:14:30 DEBUG    TORNADO :: [3f23fd2] API :: all kwargs: {'sort': 'date', 'cmd': 'future', 'type': 'missed|today|soon|later'}
2017-10-05 16:14:30 DEBUG    TORNADO :: [3f23fd2] API :: all args: ()
2017-10-05 16:14:30 DEBUG    TORNADO :: [3f23fd2] API :: 192.168.13.198 - gave correct API KEY. ACCESS GRANTED
2017-10-05 16:14:18 DEBUG    SNATCHQUEUE-MANUALSNATCH-316544 :: [3f23fd2] Transaction with 1 queries executed
2017-10-05 16:14:18 DEBUG    SNATCHQUEUE-MANUALSNATCH-316544 :: [3f23fd2] 316544: Formatting pattern: %SN - %Sx%0E - %EN - %QN -> District 31 - 015 - Épisode 15 - 720p WEB-DL
2017-10-05 16:14:18 DEBUG    SNATCHQUEUE-MANUALSNATCH-316544 :: [3f23fd2] Found codec for District 31 Épisode 15
2017-10-05 16:14:18 DEBUG    SNATCHQUEUE-MANUALSNATCH-316544 :: [3f23fd2] Checking if we should stop searching for a better quality for for episode District.31.S02E15.WEBRiP.720p.x264
2017-10-05 16:14:18 INFO     SNATCHQUEUE-MANUALSNATCH-316544 :: [3f23fd2] Saved District.31.S02E15.WEBRiP.720p.x264 to District.31.S02E15.WEBRiP.720p.x264.torrent
2017-10-05 16:14:18 DEBUG    SNATCHQUEUE-MANUALSNATCH-316544 :: [3f23fd2] No parent path provided in District.31.S02E15.WEBRiP.720p.x264.torrent, unable to get permissions from it
2017-10-05 16:14:18 DEBUG    SNATCHQUEUE-MANUALSNATCH-316544 :: [3f23fd2] GET URL: http://192.168.13.198:8086/jackett/dl/ethor/?jackett_apikey=b66if81o0czme93f44ooj49rb0a9ta8a&path=LzJBaGhZSERiT045RXFsU2o0aGJYSjBaV3dNYVFKVUxzVmV1Z0Q5ckhnWmJZNXd2eDdVUEtZUzhTN2Z1SVpUMjgvSmk2eUJ5VTZHWmdvb0d1T2VpREFZSUZLbm9pV3ZDUGg2Nk5oMW03NktpaS9xWmloSkxqZlhWcXNWcytYSEtXTkxBQ2VmMC92bTlZT3VTYk5rWk9YOGhjMjV4Z1NwVGQ5Uld6R0hCOStEZUxlem1iQ1lnMXZEdnArSDVsZUZFZVA3VEd1enhlUExOSTNBSDBVZk1oYTF2WEdrUWxIaVhrZm90UUdtMTUrVUVRM09laVhCcG83c2lvQVYxM0FQYi9Dd0gvRTlvb1l4UHZBVk03T1BHb3ZZOCtrclc3dkpYcUZJblBVMDBHZ1puSmRqMWZxNmtqWnF0ZVo4TFhOdnRZeTEvNDJudWxGa3d5ekpuTnByb3R3PT01&file=District+31+S02E15+WEBRiP+720p+x264.torrent [Status: 200]
2017-10-05 16:14:17 INFO     SNATCHQUEUE-MANUALSNATCH-316544 :: [3f23fd2] Downloading District.31.S02E15.WEBRiP.720p.x264 from Ethor at http://192.168.13.198:8086/jackett/dl/ethor/?jackett_apikey=b66if81o0czme93f44ooj49rb0a9ta8a&path=LzJBaGhZSERiT045RXFsU2o0aGJYSjBaV3dNYVFKVUxzVmV1Z0Q5ckhnWmJZNXd2eDdVUEtZUzhTN2Z1SVpUMjgvSmk2eUJ5VTZHWmdvb0d1T2VpREFZSUZLbm9pV3ZDUGg2Nk5oMW03NktpaS9xWmloSkxqZlhWcXNWcytYSEtXTkxBQ2VmMC92bTlZT3VTYk5rWk9YOGhjMjV4Z1NwVGQ5Uld6R0hCOStEZUxlem1iQ1lnMXZEdnArSDVsZUZFZVA3VEd1enhlUExOSTNBSDBVZk1oYTF2WEdrUWxIaVhrZm90UUdtMTUrVUVRM09laVhCcG83c2lvQVYxM0FQYi9Dd0gvRTlvb1l4UHZBVk03T1BHb3ZZOCtrclc3dkpYcUZJblBVMDBHZ1puSmRqMWZxNmtqWnF0ZVo4TFhOdnRZeTEvNDJudWxGa3d5ekpuTnByb3R3PT01&file=District+31+S02E15+WEBRiP+720p+x264.torrent
2017-10-05 16:14:17 INFO     SNATCHQUEUE-MANUALSNATCH-316544 :: [3f23fd2] Downloading District.31.S02E15.WEBRiP.720p.x264 with 124 seeders and 0 leechers and size 463.77 MB from Ethor
2017-10-05 16:14:17 INFO     SNATCHQUEUE-MANUALSNATCH-316544 :: [3f23fd2] Beginning to manual snatch release: District.31.S02E15.WEBRiP.720p.x264
```



Discussion:
Seems that if i dont use blackhole and i use rtorrent, it does work, so it is only a problem when using blackhole
Do you have the **Black hole folder location** set for **NZB Search**?
![img](https://i.imgur.com/e49pwBd.png)
No only in torrent? Do I need to set it in NZB also? Since it says for  NZB files I figured I didn't. Also I never did that in sickrage. 
It's a workaround. If you confirm that's the issue it will be fixed properly ASAP.
@saitoh183 Did it solve the issue?
@medariox yes adding the path to the nzb blackhole works. This is a good workaround if you dont use nzb but if you do, this is a problem. Ideally having a real torznab section would be better.

Resolving patch:
diff --git a/medusa/providers/generic_provider.py b/medusa/providers/generic_provider.py
--- a/medusa/providers/generic_provider.py
+++ b/medusa/providers/generic_provider.py
@@ -33,7 +33,6 @@
 )
 from medusa.db import DBConnection
 from medusa.helper.common import (
-    replace_extension,
     sanitize_filename,
 )
 from medusa.helpers import (
@@ -139,9 +138,6 @@ def download_result(self, result):
             log.info('Downloading {result} from {provider} at {url}',
                      {'result': result.name, 'provider': self.name, 'url': url})
 
-            if url.endswith(GenericProvider.TORRENT) and filename.endswith(GenericProvider.NZB):
-                filename = replace_extension(filename, GenericProvider.TORRENT)
-
             verify = False if self.public else None
 
             if download_file(url, filename, session=self.session, headers=self.headers,
@@ -720,7 +716,13 @@ def _make_url(self, result):
         else:
             urls = [result.url]
 
-        filename = join(self._get_storage_dir(), sanitize_filename(result.name) + '.' + self.provider_type)
+        result_name = sanitize_filename(result.name)
+
+        # Some NZB providers (e.g. Jackett) can also download torrents
+        if result.url.endswith(GenericProvider.TORRENT) and self.provider_type == GenericProvider.NZB:
+            filename = join(app.TORRENT_DIR, result_name + '.torrent')
+        else:
+            filename = join(self._get_storage_dir(), result_name + '.' + self.provider_type)
 
         return urls, filename
 
@@ -775,7 +777,8 @@ def add_cookies_from_ui(self):
             return {'result': False,
                     'message': 'Cookie is not correctly formatted: {0}'.format(self.cookies)}
 
-        if not all(req_cookie in [x.rsplit('=', 1)[0] for x in self.cookies.split(';')] for req_cookie in self.required_cookies):
+        if not all(req_cookie in [x.rsplit('=', 1)[0] for x in self.cookies.split(';')]
+                   for req_cookie in self.required_cookies):
             return {
                 'result': False,
                 'message': "You haven't configured the requied cookies. Please login at {provider_url}, "


Test patch: