|
| 1 | +name = "Event Handler Example" |
| 2 | +version = "0.1" |
| 3 | + |
| 4 | +function onTorrentAdded(torrent) |
| 5 | + qBittorrent.log(string.format("%s: Torrent '%s' is added.", name, torrent.name)) |
| 6 | + |
| 7 | + qBittorrent.debug(string.format("Torrent: %s", torrent.name)) |
| 8 | + qBittorrent.debug(string.format(" ID: %s", torrent.id)) |
| 9 | + qBittorrent.debug(string.format(" Info hash v1: %s", torrent.infoHashV1)) |
| 10 | + qBittorrent.debug(string.format(" Info hash v2: %s", torrent.infoHashV2)) |
| 11 | + qBittorrent.debug(string.format(" Creator: %s", torrent.creator)) |
| 12 | + qBittorrent.debug(string.format(" Creation time: %s", os.date("%c", torrent.creationTime))) |
| 13 | + qBittorrent.debug(string.format(" Comment: %s", torrent.comment)) |
| 14 | + qBittorrent.debug(string.format(" Category: %s", torrent.category)) |
| 15 | + qBittorrent.debug(string.format(" Tags: %s", table.concat(torrent.tags, ", "))) |
| 16 | + qBittorrent.debug(string.format(" Save path: %s", torrent.savePath)) |
| 17 | + qBittorrent.debug(string.format(" Download path: %s", torrent.downloadPath)) |
| 18 | + qBittorrent.debug(string.format(" Content path: %s", torrent.contentPath)) |
| 19 | + qBittorrent.debug(string.format(" Root path: %s", torrent.rootPath)) |
| 20 | + qBittorrent.debug(string.format(" Current tracker: %s", torrent.currentTracker)) |
| 21 | + qBittorrent.debug(" Trackers:") |
| 22 | + for _, trackerStatus in ipairs(torrent.trackerStatuses) do |
| 23 | + qBittorrent.debug(string.format(" %s", trackerStatus.url)) |
| 24 | + end |
| 25 | + qBittorrent.debug(" URL seeds:") |
| 26 | + for _, urlSeed in ipairs(torrent.urlSeeds) do |
| 27 | + qBittorrent.debug(string.format(" %s", urlSeed)) |
| 28 | + end |
| 29 | + qBittorrent.debug(string.format(" Has metadata: %s", tostring(torrent.hasMetadata))) |
| 30 | +end |
| 31 | + |
| 32 | +function onTorrentMetadataReady(torrent) |
| 33 | + qBittorrent.log(string.format("%s: Torrent '%s' has metadata ready.", name, torrent.name)) |
| 34 | + |
| 35 | + qBittorrent.debug(string.format("Torrent: %s", torrent.name)) |
| 36 | + qBittorrent.debug(string.format(" ID: %s", torrent.id)) |
| 37 | + qBittorrent.debug(string.format(" Info hash v1: %s", torrent.infoHashV1)) |
| 38 | + qBittorrent.debug(string.format(" Info hash v2: %s", torrent.infoHashV2)) |
| 39 | + qBittorrent.debug(string.format(" Private: %s", tostring(torrent.private))) |
| 40 | + qBittorrent.debug(string.format(" Total size: %s", qBittorrent.friendlySizeUnit(torrent.totalSize))) |
| 41 | + qBittorrent.debug(string.format(" Piece size: %s", qBittorrent.friendlySizeUnit(torrent.pieceSize))) |
| 42 | + qBittorrent.debug(string.format(" Pieces count: %d", torrent.piecesCount)) |
| 43 | + qBittorrent.debug(string.format(" Files count: %d", torrent.filesCount)) |
| 44 | + qBittorrent.debug(" Files:") |
| 45 | + for i = 0, (torrent.filesCount - 1) do |
| 46 | + qBittorrent.debug(string.format(" %s (%s)", torrent:filePath(i) |
| 47 | + , qBittorrent.friendlySizeUnit(torrent:fileSize(i)))) |
| 48 | + end |
| 49 | +end |
| 50 | + |
| 51 | +function onTorrentFinished(torrent) |
| 52 | + qBittorrent.log(string.format("%s: Torrent '%s' is finished.", name, torrent.name)) |
| 53 | +end |
| 54 | + |
| 55 | +function onTorrentStarted(torrent) |
| 56 | + qBittorrent.log(string.format("%s: Torrent '%s' is started.", name, torrent.name) ) |
| 57 | +end |
| 58 | + |
| 59 | +function onTorrentStopped(torrent) |
| 60 | + qBittorrent.log(string.format("%s: Torrent '%s' is stopped.", name, torrent.name)) |
| 61 | +end |
| 62 | + |
| 63 | +function onTorrentSavePathChanged(torrent) |
| 64 | + qBittorrent.log(string.format("%s: Torrent '%s' has changed save path.", name, torrent.name)) |
| 65 | +end |
| 66 | + |
| 67 | +function onTorrentSavingModeChanged(torrent) |
| 68 | + qBittorrent.log(string.format("%s: Torrent '%s' has changed saving mode.", name, torrent.name)) |
| 69 | +end |
| 70 | + |
| 71 | +function onTorrentCategoryChanged(torrent, oldCategory) |
| 72 | + qBittorrent.log(string.format("%s: Torrent '%s' has changed category.", name, torrent.name)) |
| 73 | + qBittorrent.debug(string.format("Torrent: %s. Old category: %s. New category: %s.", torrent.name, oldCategory, torrent.category)) |
| 74 | +end |
| 75 | + |
| 76 | +function onTorrentTagAdded(torrent, tag) |
| 77 | + qBittorrent.log(string.format("%s: Torrent '%s' has tag added.", name, torrent.name)) |
| 78 | + qBittorrent.debug(string.format("Torrent: %s. Added tag: %s.", torrent.name, tag)) |
| 79 | +end |
| 80 | + |
| 81 | +function onTorrentTagRemoved(torrent, tag) |
| 82 | + qBittorrent.log(string.format("%s: Torrent '%s' has tag removed.", name, torrent.name)) |
| 83 | + qBittorrent.debug(string.format("Torrent: %s. Removed tag: %s.", torrent.name, tag)) |
| 84 | +end |
| 85 | + |
| 86 | +function onTorrentContentFileRenamed(torrent, fileIndex, oldPath) |
| 87 | + qBittorrent.log(string.format("%s: Torrent '%s' has file renamed.", name, torrent.name)) |
| 88 | + qBittorrent.debug(string.format("Torrent: %s. Renamed file: '%s'. Old name: '%s'.", torrent.name, torrent:filePath(fileIndex), oldPath)) |
| 89 | +end |
| 90 | + |
| 91 | +function onTorrentContentFolderRenamed(torrent, newPath, oldPath, renamedFiles) |
| 92 | + qBittorrent.log(string.format("%s: Torrent '%s' has folder renamed.", name, torrent.name)) |
| 93 | + qBittorrent.debug(string.format("Torrent: %s. Renamed folder: '%s'. Old name: '%s'.", torrent.name, newPath, oldPath)) |
| 94 | +end |
| 95 | + |
| 96 | +function onTorrentContentFolderRenamingFailed(torrent, newPath, oldPath, renamedFiles, failedFileIndexes) |
| 97 | + qBittorrent.log(string.format("%s: Torrent '%s' has folder renaming failed.", name, torrent.name)) |
| 98 | + qBittorrent.debug(string.format("Torrent: %s. Folder: '%s'. New name: '%s'.", torrent.name, oldPath, newPath)) |
| 99 | +end |
| 100 | + |
| 101 | +function onTorrentIOError(torrent, message) |
| 102 | + qBittorrent.log(string.format("%s: Torrent '%s' has IO error.", name, torrent.name)) |
| 103 | + qBittorrent.debug(string.format("Torrent: %s. IO error message: %s.", torrent.name, message)) |
| 104 | +end |
| 105 | + |
| 106 | +function onTorrentAboutToBeRemoved(torrent) |
| 107 | + qBittorrent.log(string.format("%s: Torrent '%s' is about to be removed.", name, torrent.name)) |
| 108 | +end |
| 109 | + |
| 110 | +function onTorrentAnnounceSuccess(torrent, tracker) |
| 111 | + qBittorrent.log(string.format("%s: Torrent '%s' has announced successfully.", name, torrent.name)) |
| 112 | + qBittorrent.debug(string.format("Torrent: %s. Announced tracker: %s.", torrent.name, tracker)) |
| 113 | +end |
| 114 | + |
| 115 | +function onTorrentAnnounceWarning(torrent, tracker) |
| 116 | + qBittorrent.log(string.format("%s: Torrent '%s' has announced with warning.", name, torrent.name)) |
| 117 | + qBittorrent.debug(string.format("Torrent: %s. Announced tracker: %s.", torrent.name, tracker)) |
| 118 | +end |
| 119 | + |
| 120 | +function onTorrentAnnounceError(torrent, tracker) |
| 121 | + qBittorrent.log(string.format("%s: Torrent '%s' has failed announce.", name, torrent.name)) |
| 122 | + qBittorrent.debug(string.format("Torrent: %s. Failed tracker: %s.", torrent.name, tracker)) |
| 123 | +end |
| 124 | + |
| 125 | +function onTorrentsTrackersAdded(torrent, addedTrackers) |
| 126 | + qBittorrent.log(string.format("%s: Torrent '%s' has added trackers.", name, torrent.name)) |
| 127 | + |
| 128 | + qBittorrent.debug(string.format("Torrent: %s. Added trackers:", torrent.name)) |
| 129 | + for tracker in addedTrackers do |
| 130 | + qBittorrent.debug(string.format("\t%s", tracker.url)) |
| 131 | + end |
| 132 | +end |
| 133 | + |
| 134 | +function onTorrentTrackersRemoved(torrent, removedTrackers) |
| 135 | + qBittorrent.log(string.format("%s: Torrent '%s' has removed trackers.", name, torrent.name)) |
| 136 | + qBittorrent.debug(string.format("Torrent: %s. Removed trackers:", torrent.name)) |
| 137 | + for tracker in removedTrackers do |
| 138 | + qBittorrent.debug(string.format("\t%s", tracker)) |
| 139 | + end |
| 140 | +end |
| 141 | + |
| 142 | +function onTorrentTrackerStatusesUpdated(torrent, updatedTrackers) |
| 143 | + qBittorrent.log(string.format("%s: Torrent '%s' has updated tracker statuses.", name, torrent.name)) |
| 144 | + qBittorrent.debug(string.format("Torrent: %s. Updated trackers:", torrent.name)) |
| 145 | + for trackerURL, trackerStatus in pairs(updatedTrackers) do |
| 146 | + qBittorrent.debug(string.format("\t%s", trackerURL)) |
| 147 | + end |
| 148 | +end |
0 commit comments