Repository: pymedusa/Medusa

Issue:
IndexError sending to uTorrent
**Describe the bug**
Sending an magnet link to uTorret goes into error

**To Reproduce**
Steps to reproduce the behavior:
1. Just add an existing episode to the wanted category and click go

**Expected behavior**
An download into uTorrent

**Medusa (please complete the following information):**
 - OS: Windows 10
 - Branch: master
 - Commit: 4614efc77151ded92ef458a09dec39f8bd5acfc6 

**Logs:**
<details>

```
2018-09-10 10:48:55 DEBUG    SEARCHQUEUE-BACKLOG-80379 :: [4614efc] uTorrent: Exception raised when sending torrent Rarbg @ magnet:?xt=urn:btih:04a442a9f4ec4f968897faa4bce27f6b2d6f9083&dn=The.Big.Bang.Theory.S11E24.The.Bow.Tie.Asymmetry.720p.AMZN.WEBRip.DDP5.1.x264-NTb%5Brartv%5D&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2710&tr=udp%3A%2F%2F9.rarbg.to%3A2710&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce&tr=udp://tracker.coppersurfer.tk:6969/announce&tr=udp://tracker.leechers-paradise.org:6969/announce&tr=udp://tracker.zer0day.to:1337/announce&tr=udp://tracker.opentrackr.org:1337/announce&tr=http://tracker.opentrackr.org:1337/announce&tr=udp://p4p.arenabg.com:1337/announce&tr=http://p4p.arenabg.com:1337/announce&tr=udp://explodie.org:6969/announce&tr=udp://9.rarbg.com:2710/announce&tr=http://explodie.org:6969/announce&tr=http://tracker.dler.org:6969/announce&tr=udp://public.popcorn-tracker.org:6969/announce&tr=udp://tracker.internetwarriors.net:1337/announce&tr=udp://ipv4.tracker.harry.lu:80/announce&tr=http://ipv4.tracker.harry.lu:80/announce&tr=udp://mgtracker.org:2710/announce&tr=http://mgtracker.org:6969/announce&tr=udp://tracker.mg64.net:6969/announce&tr=http://tracker.mg64.net:6881/announce&tr=http://torrentsmd.com:8080/announce
Extra Info:
Episodes:
 u'The Big Bang Theory' - u'S11E24' - u'The Bow Tie Asymmetry'
location: u''
description: u'When Amy\u2019s parents and Sheldon\u2019s family arrive for the wedding, everybody is focused on making sure all goes according to plan \u2013 everyone except the bride and groom.'
subtitles: u''
subtitles_searchcount: 0
subtitles_lastsearch: u'0001-01-01 00:00:00'
airdate: 736824 (datetime.date(2018, 5, 10))
hasnfo: False
hastbn: False
status: 3
quality: 64
Quality: 720p WEB-DL
Name: The.Big.Bang.Theory.S11E24.The.Bow.Tie.Asymmetry.720p.AMZN.WEBRip.DDP5.1.x264-NTb[rartv]
Size: 770147134
Release Group: NTb
. Error: list index out of range
2018-09-10 10:48:55 ERROR    SEARCHQUEUE-BACKLOG-80379 :: [4614efc] uTorrent: Failed Sending Torrent
Traceback (most recent call last):
  File "C:\medusa\medusa\clients\torrent\generic.py", line 261, in send_torrent
    r_code = self._add_torrent_uri(result)
  File "C:\medusa\medusa\clients\torrent\utorrent_client.py", line 92, in _add_torrent_uri
    torrent_subfolder = get_torrent_subfolder(result)
  File "C:\medusa\medusa\clients\torrent\utorrent_client.py", line 27, in get_torrent_subfolder
    root_location = root_dirs[int(root_dirs[0]) + 1]
IndexError: list index out of range
```
</details>

**Additional context**
Add any other context about the problem here.



Discussion:
Did you add at least one shows root directory?
`General > Show root directories`

Tagging this as a bug as there needs to be a check that prevents the exception.


OMG. What a beginner error. Mediariox, you where right. That was the only thing that didn't got merged from Sickrage. Thank you.
You're welcome! Just keeping the issue open to remind myself to fix the exception.
No problem :) Thanks again.

Resolving patch:
diff --git a/medusa/clients/torrent/utorrent_client.py b/medusa/clients/torrent/utorrent_client.py
--- a/medusa/clients/torrent/utorrent_client.py
+++ b/medusa/clients/torrent/utorrent_client.py
@@ -24,10 +24,11 @@ def get_torrent_subfolder(result):
     """Retrieve the series destination-subfolder required for uTorrent WebUI 'start' action."""
     # Get the subfolder name the user has assigned to that series
     root_dirs = app.ROOT_DIRS
-    root_location = root_dirs[int(root_dirs[0]) + 1]
+    if root_dirs:
+        root_location = root_dirs[int(root_dirs[0]) + 1]
     torrent_path = result.series.raw_location
 
-    if not root_location == torrent_path:
+    if root_dirs and root_location != torrent_path:
         # Subfolder is under root, but possibly not directly under
         if torrent_path.startswith(root_location):
             torrent_subfolder = torrent_path.replace(root_location, '')


Test patch: