Skip to content

Commit

Permalink
nightly-202412031239
Browse files Browse the repository at this point in the history
  • Loading branch information
garfield69 committed Dec 3, 2024
1 parent 8c3b4e4 commit 8583058
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 236 deletions.
230 changes: 0 additions & 230 deletions js/services/TorrentClients/qBittorrent.js

This file was deleted.

95 changes: 91 additions & 4 deletions js/services/TorrentClients/qBittorrent41plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,70 @@
* https://github.com/qbittorrent/qBittorrent/wiki/Web-API-Documentation v4.1+ APIv2 (appear to have been deleted)
*
*/
var qBittorrentData = function(data) {
this.update(data)
}

DuckieTorrent.factory('qBittorrent41plusAPI', ['qBittorrentAPI', '$http', '$q',
function(qBittorrentAPI, $http, $q) {
qBittorrentData.extends(TorrentData, {
getName: function() {
return this.name
},
getDownloadSpeed: function() {
return this.dlspeed // Bytes/second
},
getProgress: function() {
return this.round(this.progress * 100, 1)
},
start: function() {
this.getClient().getAPI().execute('resume', this.hash)
},
stop: function() {
this.pause()
},
pause: function() {
this.getClient().getAPI().execute('pause', this.hash)
},
remove: function() {
this.getClient().getAPI().remove(this.hash)
},
getFiles: function() {
var self = this
return this.getClient().getAPI().getFiles(this.hash).then(function(results) {
self.files = results
return results
})
},
getDownloadDir: function() {
return this.files.downloaddir
},
isStarted: function() {
return ['downloading', 'uploading', 'stalledDL', 'stalledUP'].indexOf(this.state) > -1
}
})

/**
* qBittorrent client
*/
DuckieTorrent.factory('qBittorrentRemote', ['BaseTorrentRemote',
function(BaseTorrentRemote) {
var qBittorrentRemote = function() {
BaseTorrentRemote.call(this)
this.dataClass = qBittorrentData
}
qBittorrentRemote.extends(BaseTorrentRemote)

return qBittorrentRemote
}
])

DuckieTorrent.factory('qBittorrent41plusAPI', ['BaseHTTPApi', '$http', '$q',
function(BaseHTTPApi, $http, $q) {
var qBittorrent41plusAPI = function() {
qBittorrentAPI.call(this)
BaseHTTPApi.call(this)
this.config.apiVersion = 2
this.config.apiSubVersion = 0
}
qBittorrent41plusAPI.extends(qBittorrentAPI, {
qBittorrent41plusAPI.extends(BaseHTTPApi, {
login: function() {
var self = this
return $http.post(this.getUrl('login'), 'username=' + encodeURIComponent(this.config.username) + '&password=' + encodeURIComponent(this.config.password), {
Expand Down Expand Up @@ -113,6 +168,38 @@ DuckieTorrent.factory('qBittorrent41plusAPI', ['qBittorrentAPI', '$http', '$q',
})
})
},
addTorrentByUrl: function(url, infoHash, releaseName) {
var self = this
return this.addMagnet(url).then(function(result) {
var currentTry = 0
var maxTries = 5
// wait for qBittorrent to add the torrent to the list. we poll 5 times until we find it, otherwise abort.
return $q(function(resolve, reject) {
function verifyAdded() {
currentTry++
self.getTorrents().then(function(result) {
var hash = null
// for each torrent compare the torrent.hash with .torrent infoHash
result.map(function(torrent) {
if (torrent.hash.toUpperCase() == infoHash) {
hash = infoHash
}
})
if (hash !== null) {
resolve(hash)
} else {
if (currentTry < maxTries) {
setTimeout(verifyAdded, 1000)
} else {
throw 'Hash ' + infoHash + ' not found for torrent ' + releaseName + ' in ' + maxTries + ' tries.'
}
}
})
}
setTimeout(verifyAdded, 1000)
})
})
},
/**
* Supports setting the Download Path when adding magnets and .torrents.
*/
Expand Down
1 change: 0 additions & 1 deletion tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@
<script src="js/services/TorrentClients/Aria2.js"></script>
<script src="js/services/TorrentClients/BiglyBT.js"></script>
<script src="js/services/TorrentClients/Deluge.js"></script>
<script src="js/services/TorrentClients/qBittorrent.js"></script>
<script src="js/services/TorrentClients/qBittorrent41plus.js"></script>
<script src="js/services/TorrentClients/Ktorrent.js"></script>
<script src="js/services/TorrentClients/rTorrent.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion templates/settings/qbittorrent41plus.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h2>qBittorrent v4.1+ <h2cont translate-once>COMMON/integration/hdr</h2cont></h2

<img src="img/torrentclients/qbittorrent-colored.png" style='width:200px; margin: 0 auto'>

<p><a href='https://github.com/SchizoDuckie/DuckieTV/wiki/Setting-up-qBitTorrent-4.1-with-DuckieTV' target='_blank' translate-once>COMMON/set-up-instructions/lbl</a></p>
<p><a href='https://github.com/SchizoDuckie/DuckieTV/wiki/Setting-up-qBitTorrent-with-DuckieTV' target='_blank' translate-once>COMMON/set-up-instructions/lbl</a></p>

<p ng-show="qbt.isConnected()"><span translate-once>COMMON/status/hdr</span>:
<span translate-once>COMMON/connected/lbl</span> qBittorrent 4.1+ API &#64; {{qbt.model.server}}:{{qbt.model.port}}
Expand Down

0 comments on commit 8583058

Please sign in to comment.