Repository: Flexget/Flexget

Issue:
Incompatibility with Libtorrent version 1.1.3 and above
### Actual behaviour:
flexget crashes when converting magnet URI to a torrent file with libtorrent versions 1.1.3 and higher

### Steps to reproduce:
upgrade libtorrent to 1.1.3 or higher (I'm using 1.1.4 but the change occurred in 1.1.3)
download torrent with convert_magnet plugin 

#### Config:
```
tasks:
  stage:
    convert_magnet: yes
    rss: http://xxx.xxx/rss
    accept_all: yes
    download:
      path: /home/flexget/test/
```
  
#### Log:
```
2017-10-09 15:36 VERBOSE  task_queue                    There are 1 tasks to execute. Shutdown will commence when they have completed.
2017-10-09 15:36 VERBOSE  details       stage           Produced 74 entries.
2017-10-09 15:36 INFO     series        stage           identified_by has locked in to type `ep` for Lucifer
2017-10-09 15:36 VERBOSE  task          stage           ACCEPTED: `Lucifer S03E02 1080p HDTV X264 DIMENSION` by series plugin because choosing best available quality
2017-10-09 15:36 VERBOSE  task          stage           ACCEPTED: `Lucifer S03E01 1080p HDTV X264 DIMENSION` by series plugin because choosing best available quality
2017-10-09 15:36 INFO     convert_magnet stage           Converting entry Lucifer S03E02 1080p HDTV X264 DIMENSION magnet URI to a torrent file
2017-10-09 15:36 INFO     convert_magnet stage           lt_ver caught
2017-10-09 15:36 CRITICAL task          stage           BUG: Unhandled error in plugin convert_magnet: 'str' object has no attribute 'to_bytes'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
    return method(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in __call__
    return self.func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/modify/convert_magnet.py", line 93, in on_task_download
    torrent_file = self.magnet_to_torrent(entry['url'], converted_path, timeout)
  File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/modify/convert_magnet.py", line 41, in magnet_to_torrent
    params['info_hash'] = params['info_hash'].to_bytes()
AttributeError: 'str' object has no attribute 'to_bytes'
```

### Additional information:

- FlexGet version: 2.10.97
- Python version: 2.7.13
- Installation method: pip
- Using daemon (yes/no): no
- OS and version: Debian Stretch 9.1
- Link to crash log: see above

flexget/plugins/modify/convert_magnet.py line 40 converts the info_hash to bytes if the libtorrent version is above 0.16.13.  The comments seem to indicate this was done as a work around because the info_hash value did not comply with the defined structure.  according to the release notes on libtorrent v1.1.3 this has been corrected, info_hash is now a string value which does not contain the attribute to_bytes, this causes the crash.  Since the underlying issue in libtorrent has been corrected, the info_hash value can be used as is without converting to_bytes if the libtorrent versions above 1.1.3.  Standby for PR


### References: 
https://github.com/arvidn/libtorrent/releases/tag/libtorrent-1_1_3
https://github.com/arvidn/libtorrent/commit/2e367ea53b1ce36d42eec73d12056ca4cd8029a4




Discussion:

Resolving patch:
diff --git a/flexget/plugins/modify/convert_magnet.py b/flexget/plugins/modify/convert_magnet.py
--- a/flexget/plugins/modify/convert_magnet.py
+++ b/flexget/plugins/modify/convert_magnet.py
@@ -35,7 +35,7 @@ def magnet_to_torrent(self, magnet_uri, destination_folder, timeout):
         params = libtorrent.parse_magnet_uri(magnet_uri)
         session = libtorrent.session()
         lt_version = [int(v) for v in libtorrent.version.split('.')]
-        if lt_version > [0,16,13,0]:
+        if lt_version > [0,16,13,0] and lt_version < [1,1,3,0]:
             # for some reason the info_hash needs to be bytes but it's a struct called sha1_hash
             params['info_hash'] = params['info_hash'].to_bytes()
         handle = libtorrent.add_magnet_uri(session, magnet_uri, params)


Test patch: