Skip to content

Commit

Permalink
add dummy torrent client. resolves #1122
Browse files Browse the repository at this point in the history
  • Loading branch information
garfield69 committed Oct 10, 2018
1 parent 4a2ef6d commit e72d369
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 0 deletions.
Binary file added img/torrentclients/none-colored.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/torrentclients/none-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/torrentclients/none.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
167 changes: 167 additions & 0 deletions js/services/TorrentClients/None.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/**
* None
*
* This is a dummy torrent client that responds as connected and returns as if all torrents are completed.
* For use by those that either: are using an unsupported torrent client or don't want to connect to any of the existing ones.
* This has the benefit of preventing unnecessary log clutter with failed connection attempts,
* and allows other processes to complete successfully, such as marking a torrent as downloaded after the user launches a torrent manually.
*
*/
NoneData = function(data) {
this.update(data);
};

NoneData.extends(TorrentData, {
getName: function() {
return this.name;
},
getProgress: function() {
return 100;
},
getDownloadSpeed: function() {
return 0; // Bytes/second
},
start: function() {
return true;
},
stop: function() {
return true;
},
pause: function() {
return true;
},
remove: function() {
this.getClient().getAPI().remove(this.hash);
},
getDownloadDir: function() {
return null;
},
getFiles: function() {
return this.getClient().getAPI().getFiles(this.hash).then(function(results) {
this.files = results;
return results;
}.bind(this));
},
isStarted: function() {
return false;
}
});

/**
* None
*/
DuckieTorrent.factory('NoneRemote', ["BaseTorrentRemote",
function(BaseTorrentRemote) {

var NoneRemote = function() {
BaseTorrentRemote.call(this);
this.dataClass = NoneData;
};
NoneRemote.extends(BaseTorrentRemote);

return NoneRemote;
}
])

.factory('NoneAPI', ['BaseHTTPApi', '$http', '$q', 'TorrentHashListService', 'SettingsService',
function(BaseHTTPApi, $http, $q, TorrentHashListService, SettingsService) {

var NoneAPI = function() {
BaseHTTPApi.call(this);
};
NoneAPI.extends(BaseHTTPApi, {
portscan: function() {
return new Promise(function(resolve) {
return resolve(true);
});
},
getTorrents: function() {
return new Promise(function(resolve) {
var output = [];
Object.keys(TorrentHashListService.hashList).map(function(hash) {
output.push({hash: hash, name: hash});
});
return resolve(output);
});
},
getFiles: function() {
return new Promise(function(resolve) {
return resolve([]);
});
},
remove: function(hash) {
return new Promise(function(resolve) {
TorrentHashListService.removeFromHashList(hash);
return resolve(true);
});
},
addMagnet: function(magnetURI) {
var self = this;
return new Promise(function(resolve) {
self.openUrl('magnet', magnetURI);
return resolve(true);
});
},
addTorrentByUrl: function(torrentUrl, infoHash, releaseName) {
var self = this;
return new Promise(function(resolve) {
self.openUrl('torrent', torrentUrl);
return resolve(infoHash);
});
},
openUrl: function(id, url) {
if (SettingsService.isStandalone() && id === 'magnet') {
// for standalone, open magnet url direct to os https://github.com/SchizoDuckie/DuckieTV/issues/834
nw.Shell.openExternal(url);
//console.debug("Open via OS", id, url);
} else {
// for chrome extension, open url on chromium via iframe
var d = document.createElement('iframe');
d.id = id + 'url_' + new Date().getTime();
d.style.visibility = 'hidden';
d.src = url;
document.body.appendChild(d);
//console.debug("Open via Chromium", d.id, url);
var dTimer = setInterval(function() {
var dDoc = d.contentDocument || d.contentWindow.document;
if (dDoc.readyState == 'complete') {
document.body.removeChild(d);
clearInterval(dTimer);
return;
}
}, 1500);
}
}
});

return NoneAPI;
}
])

.factory('None', ["BaseTorrentClient", "NoneRemote", "NoneAPI",
function(BaseTorrentClient, NoneRemote, NoneAPI) {

var None = function() {
BaseTorrentClient.call(this);
};
None.extends(BaseTorrentClient, {});

var service = new None();
service.setName('None');
service.setAPI(new NoneAPI());
service.setRemote(new NoneRemote());
service.setConfigMappings({});
service.setEndpoints({});
service.readConfig();

return service;
}
])

.run(["DuckieTorrent", "None", "SettingsService",
function(DuckieTorrent, None, SettingsService) {
if (SettingsService.get('torrenting.enabled')) {
DuckieTorrent.register('None', None);
}
}
]);
1 change: 1 addition & 0 deletions tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
<script src="js/services/TorrentClients/uTorrent.js"></script>
<script src="js/services/TorrentClients/uTorrentWebUI.js"></script>
<script src="js/services/TorrentClients/Vuze.js"></script>
<script src="js/services/TorrentClients/None.js"></script>
<script src="js/services/TorrentSearchEngines/TorrentSearchEngines.js"></script>
<script src="js/services/TorrentSearchEngines/GenericTorrentSearchEngine.js"></script>
<script src="js/services/TorrentSearchEngines/ThePirateBayMirrorResolver.js"></script>
Expand Down
3 changes: 3 additions & 0 deletions templates/settings/none.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="buttons">
<h2>None <h2cont translate-once>COMMON/integration/hdr</h2cont></h2>
</div>

0 comments on commit e72d369

Please sign in to comment.