KTorrent:在 shell 腳本中移動數據

KTorrent:在 shell 腳本中移動數據

我正在嘗試為我的神奇資料夾建立一個腳本,它將檔案移至種子目錄,而 KTorrent 不會遺失資料所在的位置,類似於應用程式中的「移動資料」上下文功能表操作。我已經研究了 dbus API,這就是我到目前為止所擁有的:

for x in `qdbus org.ktorrent.ktorrent /core org.ktorrent.core.torrents`; do
    name=`qdbus org.ktorrent.ktorrent /torrent/$x org.ktorrent.torrent.name`
    if [ "$name" = "$1" ]; then
        # Tell KTorrent to move the data to the seeding directory
    fi
done

問題是我找不到任何東西應用程式介面為此,甚至可以在手動移動後設定新位置。

我想透過直接操作 GUI 來啟動上下文選單操作來實現這一點(如果我能做到這一點,我會很滿意),並發現了這一點:

qdbus org.ktorrent.ktorrent /ktorrent/MainWindow_1 org.kde.KMainWindow.activateAction view_move_data

它可以滿足我的需求,但總是針對當前選擇的 torrent,而且我甚至不知道選擇我真正想要移動的 torrent 的第一步。

有任何想法嗎?

答案1

我找到了更好的解決方案來解決我的問題。我沒有將已完成的下載移至特定目錄,然後在完成後移回,而是製作了一個 KTorrent 腳本來捕獲已完成的信號並創建一個符號連結到我想要查看它們的目錄中的文件。

我已在此處提供打包的腳本和源代碼:

http://schmunsler.no-ip.org/code/shared/file_linker/

但為了以防萬一,我會在這裡發布主腳本的內容。

#!/usr/bin/env kross
# -*- coding: utf-8 -*-
import KTorrent
import KTScriptingPlugin
import Kross

import os
import socket

class FileLinker:
    def __init__(self):
        self.link_dir = KTScriptingPlugin.readConfigEntry("downloads","completedDir",os.path.expanduser("~/"))+"/"
        if self.link_dir.startswith("file://"):
            self.link_dir = self.link_dir[7:]
        KTorrent.log("linkDir is "+self.link_dir)
        KTorrent.connect("torrentAdded(const QString &)",self.torrentAdded)
        tors = KTorrent.torrents()
        # bind to signals for each torrent
        for t in tors:
            self.torrentAdded(t)

    def torrentFinished(self,tor):
        KTorrent.log("Symlinking "+tor.pathOnDisk()+" to "+self.link_dir+tor.name())
        os.symlink(""+tor.pathOnDisk(),""+self.link_dir+tor.name())

    def connectSignals(self,tor):
        KTorrent.log("connectSignals " + tor.name())
        tor.connect("finished(QObject* )",self.torrentFinished)

    def torrentAdded(self,ih):
        tor = KTorrent.torrent(ih)
        self.connectSignals(tor)

# load settings
linker = FileLinker()

def unload():
    global linker
    del linker

相關內容