Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.

Added torrent support for Synology downloader. #1791

Closed
wants to merge 3 commits into from

Conversation

saxicek
Copy link
Contributor

@saxicek saxicek commented May 28, 2013

Added support for torrents to Synology downloader.

It uses remote torrent URL so the URL should point directly to torrent without the need for authentication. I also tried to push the torrent file downloaded by CouchPotato directly to Synology, but the Synology API returns errors and documentation does not provide any hints on possible error cause. File upload is tricky. :-(

@RuudBurger
Copy link
Member

Thanks for the PR, but I can't add this if it doesn't allow the pushing of torrents.
Private trackers need the file to be downloaded and sometimes don't have a direct url.

@saxicek
Copy link
Contributor Author

saxicek commented May 28, 2013

Ok, will try harder to make the file upload work.

@RuudBurger
Copy link
Member

I can't help you out but maybe @clinton-hall can, he is always bragging about all his NAS systems ;)

@clinton-hall
Copy link
Contributor

Lol. The only problem there is that I don't have Synology.
I can actually try porting this over to Asustor download centre, but at the end of the day this is a different device.

@saxicek can you provide details of the errors encountered when you tried to push the file?

@saxicek
Copy link
Contributor Author

saxicek commented May 28, 2013

Well Synology Download Station uses Transmission to download torrents which may be fall back variant to make it work. Other option is that it has undocumented API used for their own web frontend (it seems that Synodroid DS is using it). And finally there is official API from Synology for Download Station but it does not provide all the functionlaity and is not documented well.

The existing Synology provider is using the official API. So I tried to extend it to send file via Python-requests but it failed with HTTP 200 and {u'success': False, u'error': {u'code': 101}} -- that should mean invalid parameters. But no more details, no example so I have to experiment. :-/

@clinton-hall
Copy link
Contributor

Create
Request

Parameter
Description
Availability

uri
Optional. Accepts HTTP/FTP/magnet/ED2K links, separated by ",".
1 and later

file
Optional. File uploading from client. For more info, please see Limitations on page 29.
1 and later

username

Optional. Login username
1 and later
password

Optional. Login password
1 and later

unzip_password

Optional. Password for unzipping download tasks
1 and later

Example:

POST /webapi/DownloadStation/task.cgi
api=SYNO.DownloadStation.Task&version=1&method=create&uri=ftps://192.0.0.1:2
1/test/test.zip&username=admin&password=123

Limitations
1 create_time is currently not supported by eMule tasks (create_time = null for eMule tasks).
2 Due to multipart upload limitations, creating tasks by uploading files should adhere to one of the following
implementations:
a Set the upload files as the only POST request method data, and set other files as GET parameters.
b Set all the parameters as POST data, and the upload file should implement LAST parameters.

All from page 24 and 29 of http://download.synology.com/download/ds/userguide/Synology_Download_Station_Official_API.pdf

Does any of this help? It looks like file upload is possible (and documented)

@saxicek
Copy link
Contributor Author

saxicek commented May 29, 2013

Well yes, it is documented, but I just cannot make it work. I tried both approaches from file upload limitaions, below is the a) variant:

    args = {'api':'SYNO.DownloadStation.Task', 'version':1, 'method':'create', '_sid':self.sid}
    url = self.download_url + '?' + urllib.urlencode(args)
    files = {'file': (data['name'] + '.' + data['type'], filedata)}
    r = requests.post(url, files=files)
    response = json.loads(r.text)

But it returns the error HTTP 200 and {u'success': False, u'error': {u'code': 101}}. Not really sure what is wrong. :-/

@RuudBurger
Copy link
Member

Could you try using the urlopen functions provided by the Downloader class?
Something like

args = {'api':'SYNO.DownloadStation.Task', 'version':1, 'method':'create', '_sid':self.sid}
url = self.download_url + '?' + urllib.urlencode(args)
files = {'file': (data['name'] + '.' + data['type'], filedata)}
response = self.getJsonData(url, params = files, cache_timeout = 1, multipart = True)

@saxicek
Copy link
Contributor Author

saxicek commented May 29, 2013

Tried but same result. :-( Will try the frontend API since there I can at least track successful requests.

@Gui13
Copy link
Contributor

Gui13 commented May 29, 2013

Did you zip the data?
Also, I see that the front end api pass all the parameters as multipart post; nothing through the URL.
This might be what the official API expects?

@saxicek
Copy link
Contributor Author

saxicek commented Jun 7, 2013

I made it working using requests, but the issue is that current bundled version is too old (0.14.1). Is it possible to update it? I tested it with the latest - 1.2.3.

args = {'api': 'SYNO.DownloadStation.Task',
        'version': '1',
        'method': 'create',
        '_sid': self.sid}
files = {'file': (data['name']+'.'+data['type'], filedata)}
resp_raw = requests.post(self.download_url, data=args, files=files)
response = json.loads(resp_raw.text)

@RuudBurger
Copy link
Member

Yeah, just update the lib folder.

@saxicek
Copy link
Contributor Author

saxicek commented Jun 7, 2013

Commited version that works for both magnets (tested on PirateBay) and torrents (tested on TorrentShack). Can you please merge?

There is one more thing - Synology DownloadStation also supports nzb and it would be very easy to add it (same method like for torrents). But you can also have SABnzbd installed on Synology. And if user prefers DownloadStation for torrents and SABnzbd for nzb, it is not possible to configure it when Synology has nzb support enabled. Any idea?

@Gui13
Copy link
Contributor

Gui13 commented Jun 7, 2013

Maybe duplicate the downloader and rename it for NZB? You could simply inherit the current Syno downloader and replace the supported protocols by NZB?

@clinton-hall
Copy link
Contributor

Or a new option in settings, downloaders, Synology
Use_for =
Possible options would be:
usenet
torrents
torrents & usenet.

@saxicek
Copy link
Contributor Author

saxicek commented Jun 7, 2013

I would prefer solution as suggested by @clinton-hall but that would require to implement such support in CouchPotatoServer.

@RuudBurger
Copy link
Member

Have a look at the blackhole downloader, that implements the same thing.
That way you can set Syno for "torrents" and enable the SAB downloader next to it.

@RuudBurger
Copy link
Member

Merged. Can't test this, so I trust you on this ;)

@RuudBurger RuudBurger closed this Jun 14, 2013
@saxicek
Copy link
Contributor Author

saxicek commented Jun 18, 2013

I am asking probably a stupid question but where was it merged? I added nzb support as discussed above but when trying to create pull request to master it is trying to add also revisions where I added the torrent support. Don't want to cause you issues with duplicities... Thanks.

@clinton-hall
Copy link
Contributor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants