实现种子的简单控制,暂停/继续/强制继续/设置自动管理/超级做种/重新校验/手动汇报

This commit is contained in:
ngfchl
2022-09-29 12:39:36 +08:00
parent 43636a3fd5
commit cde1251e25
3 changed files with 120 additions and 23 deletions

View File

@@ -15,6 +15,7 @@ urlpatterns = [
path(r'page_downloading', views.page_downloading, name='page_downloading'),
path(r'get_downloader', views.get_downloader, name='get_downloader'),
path(r'downloading', views.get_downloading, name='downloading'),
path(r'control_torrent', views.control_torrent, name='control_torrent'),
path(r'torrent_info_page', views.render_torrents_page, name='torrent_info_page'),
path(r'get_torrent_info_list', views.get_torrent_info_list, name='get_torrent_info_list'),
path(r'do_sql', views.do_sql, name='do_sql'),

View File

@@ -10,11 +10,9 @@ import qbittorrentapi
from django.http import JsonResponse
from django.shortcuts import render
from pt_site import views as tasks
from pt_site.UtilityTool import FileSizeConvert
from pt_site.models import SiteStatus, MySite, Site, Downloader, TorrentInfo
from pt_site.views import scheduler, pt_spider
from ptools.base import CommonResponse, StatusCodeEnum, DownloaderCategory, TorrentBaseInfo
from ptools.base import CommonResponse, StatusCodeEnum, DownloaderCategory
def add_task(request):
@@ -110,6 +108,10 @@ def get_downloading(request):
try:
qb_client.auth_log_in()
torrents = qb_client.torrents_info()
transfer = qb_client.transfer_info()
main_data = qb_client.sync_maindata()
print(transfer)
print(json.dumps(main_data))
for torrent in torrents:
# 时间处理
# 添加于
@@ -147,7 +149,7 @@ def get_downloading(request):
torrent['uploaded'] = '' if torrent['uploaded'] == 0 else torrent['uploaded']
torrent['upspeed'] = '' if torrent['upspeed'] == 0 else torrent['upspeed']
torrent['dlspeed'] = '' if torrent['dlspeed'] == 0 else torrent['dlspeed']
print(torrents)
print(len(torrents))
return JsonResponse(CommonResponse.success(data=torrents).to_dict(), safe=False)
except Exception as e:
print(e)
@@ -156,6 +158,38 @@ def get_downloading(request):
).to_dict(), safe=False)
def control_torrent(request):
ids = request.POST.get('ids')
command = request.POST.get('command')
downloader_id = request.POST.get('downloader_id')
print(request.POST)
# print(command, type(ids), downloader_id)
downloader = Downloader.objects.filter(id=downloader_id).first()
qb_client = qbittorrentapi.Client(
host=downloader.host,
port=downloader.port,
username=downloader.username,
password=downloader.password,
SIMPLE_RESPONSES=True
)
try:
qb_client.auth_log_in()
# qb_client.torrents.resume()
# 根据指令字符串定位函数
command_exec = getattr(qb_client.torrents, command)
print(command_exec)
command_exec(torrent_hashes=ids.split(','))
# 延缓2秒等待操作生效
time.sleep(2)
except Exception as e:
print(e)
return JsonResponse(CommonResponse.success(data={
'ids': ids.split(','),
'command': command,
'downloader_id': downloader_id
}).to_dict(), safe=False)
def import_from_ptpp(request):
if request.method == 'GET':
return render(request, 'auto_pt/import_ptpp.html')

View File

@@ -29,22 +29,29 @@
{# :name="downloader.id"#}
:id="downloader.id">
<div>
<el-dropdown split-button type="primary" size="mini">
查看
<el-dropdown split-button type="primary" size="mini" @command="handleSelected">
操作
<el-dropdown-menu slot="dropdown">
<el-dropdown-item>继续</el-dropdown-item>
<el-dropdown-item>暂停</el-dropdown-item>
<el-dropdown-item>强制继续</el-dropdown-item>
<el-dropdown-item>删除</el-dropdown-item>
<el-dropdown-item>限速</el-dropdown-item>
<el-dropdown-item>分类</el-dropdown-item>
<el-dropdown-item>更改路径</el-dropdown-item>
<el-dropdown-item>自动管理</el-dropdown-item>
<el-dropdown-item>重新校验</el-dropdown-item>
<el-dropdown-item>复制链接</el-dropdown-item>
<el-dropdown-item>复制HASH</el-dropdown-item>
<el-dropdown-item command="resume">继续</el-dropdown-item>
<el-dropdown-item command="set_force_start">强制继续</el-dropdown-item>
<el-dropdown-item command="pause">暂停</el-dropdown-item>
<el-dropdown-item command="set_auto_management">自动管理</el-dropdown-item>
<el-dropdown-item command="set_super_seeding">超级做种</el-dropdown-item>
<el-dropdown-item command="recheck">重新校验</el-dropdown-item>
<el-dropdown-item command="reannounce">重新汇报</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<el-dropdown split-button type="success" size="mini">
操作
<el-dropdown-menu slot="dropdown">
<el-dropdown-item @click="handleDelete">删除</el-dropdown-item>
<el-dropdown-item @click="setCategory">分类</el-dropdown-item>
<el-dropdown-item @click="limitSpeed">限速</el-dropdown-item>
{# <el-dropdown-item @click="setLocation">更改路径</el-dropdown-item>#}
</el-dropdown-menu>
</el-dropdown>
{# <el-button @click="copyMagnet">复制链接</el-button>#}
{# <el-button @click="copyHash">复制HASH</el-button>#}
<el-button size="mini" type="warning" @click="clearTimer" v-if="refresh"> 暂停刷新</el-button>
{# <el-button size="mini" type="success" @click="handleRefresh" v-else="refresh"> 开始刷新</el-button>#}
<el-dropdown split-button type="success" size="mini" v-else="refresh" @click="handleRefresh(10)"
@@ -67,6 +74,7 @@
showHeaderOverflow="title"
@row-dblclick="handleRow"
@row-contextmenu="rtClick"
@selection-change="tableSelected"
:data="torrents"
height="740"
size="mini"
@@ -299,7 +307,8 @@
{color: '#5cb87a', percentage: 60},
{color: '#1989fa', percentage: 80},
{color: '#6f7ad3', percentage: 100}
]
],
selected_rows: []
},
beforeMount() {
},
@@ -314,10 +323,9 @@
})
}
this.stateFilters = data
console.log(this.stateFilters)
{#console.log(this.stateFilters)#}
this.get_downloader()
console.log("下载器:", this.downloaders.length)
},
// 清除定时器,不然页面会卡死
beforeDestroy() {
@@ -330,6 +338,51 @@
},
watch: {},
methods: {
tableSelected(rows) {
this.selected_rows = rows
console.log(this.selected_rows)
},
handleDelete() {
},
setCategory() {
},
limitSpeed() {
},
{#setLocation(){},#}
handleSelected(command) {
let ids = []
if (this.selected_rows.length <= 0) {
this.$message({
type: 'warning',
message: '未选中任何种子!!'
})
return
}
this.selected_rows.forEach((item, index) => {
console.log(item['hash'], index)
ids.push(item['hash'])
})
let data = new FormData()
data.append('ids', ids)
data.append('command', command)
data.append('downloader_id', this.downloader_id)
axios.post(
"{% url "control_torrent" %}",
data
).then(res => {
console.log(res.data)
this.get_downloading(this.downloader_id)
this.$message({
type: 'success',
message: '指令发送成功!!'
})
}).catch(res => {
this.$message({
type: 'warning',
message: '指令发送失败!!'
})
})
},
get_downloader() {
axios.get(
"{% url "get_downloader" %}"
@@ -340,7 +393,7 @@
this.downloaders = res.data.data
this.downloader_id = this.downloaders[0].id
this.get_downloading(this.downloader_id)
console.log(this.torrents)
console.log(this.torrents.length)
this.loading = false
} else {
this.loading = false
@@ -382,10 +435,19 @@
}
}
).then(res => {
if (res.data.code === 0) {
console.log(res.data.data)
console.log(res.data.data.length)
this.torrents = res.data.data
this.$message({
type: 'success',
message: '任务加载成功!!'
})
} else {
console.log(res.data.data)
this.$message({
type: 'warning',
message: '任务加载出错!!'
})
}
})
},