Skip to content

Commit

Permalink
Allow Transmission users to set a base dir for ftp download url const…
Browse files Browse the repository at this point in the history
…ruction; fixes #518
  • Loading branch information
erickok committed Jul 9, 2020
1 parent 1149e0a commit 77af027
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/org/transdroid/daemon/Daemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public static boolean supportsFineDetails(Daemon type) {
}

public static boolean needsManualPathSpecified(Daemon type) {
return type == uTorrent || type == BitTorrent || type == KTorrent || type == BuffaloNas;
return type == uTorrent || type == BitTorrent || type == KTorrent || type == BuffaloNas || type == Transmission;
}

public static boolean supportsFilePaths(Daemon type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
*/
package org.transdroid.daemon.Transmission;

import net.iharder.Base64;
import net.iharder.Base64.InputStream;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import net.iharder.Base64;
import net.iharder.Base64.InputStream;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -579,6 +580,18 @@ private TorrentStatus getStatus(int status) {

private ArrayList<TorrentFile> parseJsonFileList(JSONObject response, Torrent torrent) throws JSONException {

String absoluteDir = torrent.getLocationDir();
String relativeDir = settings.getDownloadDir();
if (relativeDir == null) {
// We can make no assumptions except the torrent's location is the main download dir
relativeDir = "";
} else if (absoluteDir.startsWith(relativeDir)) {
relativeDir = absoluteDir.substring(relativeDir.length());
if (relativeDir.startsWith("/")) {
relativeDir = relativeDir.substring(1);
}
}

// Parse response
ArrayList<TorrentFile> torrentfiles = new ArrayList<>();
JSONArray rarray = response.getJSONArray("torrents");
Expand All @@ -592,8 +605,8 @@ private ArrayList<TorrentFile> parseJsonFileList(JSONObject response, Torrent to
torrentfiles.add(new TorrentFile(
String.valueOf(i),
file.getString(RPC_FILE_NAME),
file.getString(RPC_FILE_NAME),
torrent.getLocationDir() + file.getString(RPC_FILE_NAME),
relativeDir + file.getString(RPC_FILE_NAME),
absoluteDir + file.getString(RPC_FILE_NAME),
file.getLong(RPC_FILE_LENGTH),
file.getLong(RPC_FILE_COMPLETED),
convertTransmissionPriority(stat.getBoolean(RPC_FILESTAT_WANTED), stat.getInt(RPC_FILESTAT_PRIORITY))));
Expand Down

0 comments on commit 77af027

Please sign in to comment.