Skip to content

Commit

Permalink
Merge pull request #2 from golift/dn2_upgrades
Browse files Browse the repository at this point in the history
Add Deluge 2 struct, version method, debug logs, cleanup.
  • Loading branch information
davidnewhall authored Jul 1, 2019
2 parents 84366a9 + c33319d commit 8fba78e
Show file tree
Hide file tree
Showing 2 changed files with 396 additions and 31 deletions.
265 changes: 258 additions & 7 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,38 @@ import (
"time"
)

// Deluge methods.
// Deluge WebUI methods.
const (
AuthLogin = "auth.login"
AddMagnet = "core.add_torrent_magnet"
AddTorrentURL = "core.add_torrent_url"
AddTorrentFile = "core.add_torrent_file"
GetTorrentStat = "core.get_torrent_status"
GetAllTorrents = "core.get_torrents_status"
HostStatus = "web.get_host_status"
GeHosts = "web.get_hosts"
)

// Config is the data needed to poll Deluge.
type Config struct {
URL string `json:"url" toml:"url" xml:"url" yaml:"url"`
Password string `json:"password" toml:"password" xml:"password" yaml:"password"`
HTTPPass string `json:"http_pass" toml:"http_pass" xml:"http_pass" yaml:"http_pass"`
HTTPUser string `json:"http_user" toml:"http_user" xml:"http_user" yaml:"http_user"`
Timeout time.Duration `json:"timeout" toml:"timeout" xml:"timeout" yaml:"timeout"`
URL string `json:"url" toml:"url" xml:"url" yaml:"url"`
Password string `json:"password" toml:"password" xml:"password" yaml:"password"`
HTTPPass string `json:"http_pass" toml:"http_pass" xml:"http_pass" yaml:"http_pass"`
HTTPUser string `json:"http_user" toml:"http_user" xml:"http_user" yaml:"http_user"`
Timeout Duration `json:"timeout" toml:"timeout" xml:"timeout" yaml:"timeout"`
VerifySSL bool `json:"verify_ssl" toml:"verify_ssl" xml:"verify_ssl" yaml:"verify_ssl"`
Version string `json:"version" toml:"version" xml:"version" yaml:"version"`

DebugLog func(msg string, fmt ...interface{}) `json:"-" toml:"-" xml:"-" yaml:"-"`
}

// Duration is used to UnmarshalTOML into a time.Duration value.
type Duration struct{ time.Duration }

// UnmarshalText parses a duration type from a config file.
func (d *Duration) UnmarshalText(data []byte) (err error) {
d.Duration, err = time.ParseDuration(string(data))
return
}

// Response from Deluge
Expand All @@ -34,7 +49,128 @@ type Response struct {
} `json:"error"`
}

// XferStatus represents a transfer in Deluge.
// Backend holds a WebUI's backend server data.
type Backend struct {
ID string
Addr string
Prot string
}

// XferStatus2 is the Deluge 2.0 WebUI API layout for Active Transfers.
type XferStatus2 struct {
ActiveTime float64 `json:"active_time"`
SeedingTime float64 `json:"seeding_time"`
FinishedTime float64 `json:"finished_time"`
AllTimeDownload float64 `json:"all_time_download"`
StorageMode string `json:"storage_mode"`
DistributedCopies float64 `json:"distributed_copies"`
DownloadPayloadRate float64 `json:"download_payload_rate"`
FilePriorities []int `json:"file_priorities"`
Hash string `json:"hash"`
AutoManaged bool `json:"auto_managed"`
IsAutoManaged bool `json:"is_auto_managed"`
IsFinished bool `json:"is_finished"`
MaxConnections float64 `json:"max_connections"`
MaxDownloadSpeed float64 `json:"max_download_speed"`
MaxUploadSlots float64 `json:"max_upload_slots"`
MaxUploadSpeed float64 `json:"max_upload_speed"`
Message string `json:"message"`
MoveOnCompletedPath string `json:"move_on_completed_path"`
MoveOnCompleted bool `json:"move_on_completed"`
MoveCompletedPath string `json:"move_completed_path"`
MoveCompleted bool `json:"move_completed"`
NextAnnounce float64 `json:"next_announce"`
NumPeers int64 `json:"num_peers"`
NumSeeds int64 `json:"num_seeds"`
Owner string `json:"owner"`
Paused bool `json:"paused"`
PrioritizeFirstLast bool `json:"prioritize_first_last"`
PrioritizeFirstLastPieces bool `json:"prioritize_first_last_pieces"`
SequentialDownload bool `json:"sequential_download"`
Progress float64 `json:"progress"`
Shared bool `json:"shared"`
RemoveAtRatio bool `json:"remove_at_ratio"`
SavePath string `json:"save_path"`
DownloadLocation string `json:"download_location"`
SeedsPeersRatio float64 `json:"seeds_peers_ratio"`
SeedRank int `json:"seed_rank"`
State string `json:"state"`
StopAtRatio bool `json:"stop_at_ratio"`
StopRatio float64 `json:"stop_ratio"`
TimeAdded float64 `json:"time_added"`
TotalDone float64 `json:"total_done"`
TotalPayloadDownload float64 `json:"total_payload_download"`
TotalPayloadUpload float64 `json:"total_payload_upload"`
TotalPeers int64 `json:"total_peers"`
TotalSeeds float64 `json:"total_seeds"`
TotalUploaded float64 `json:"total_uploaded"`
TotalWanted float64 `json:"total_wanted"`
TotalRemaining float64 `json:"total_remaining"`
Tracker string `json:"tracker"`
TrackerHost string `json:"tracker_host"`
Trackers []struct {
URL string `json:"url"`
Trackerid string `json:"trackerid"`
Tier int `json:"tier"`
FailLimit int `json:"fail_limit"`
Source int `json:"source"`
Verified bool `json:"verified"`
Message string `json:"message"`
LastError struct {
Value int `json:"value"`
Category string `json:"category"`
} `json:"last_error"`
NextAnnounce interface{} `json:"next_announce"`
MinAnnounce interface{} `json:"min_announce"`
ScrapeIncomplete float64 `json:"scrape_incomplete"`
ScrapeComplete float64 `json:"scrape_complete"`
ScrapeDownloaded float64 `json:"scrape_downloaded"`
Fails int64 `json:"fails"`
Updating bool `json:"updating"`
StartSent bool `json:"start_sent"`
CompleteSent bool `json:"complete_sent"`
Endpoints []interface{} `json:"endpoints"`
SendStats bool `json:"send_stats"`
} `json:"trackers"`
TrackerStatus string `json:"tracker_status"`
UploadPayloadRate float64 `json:"upload_payload_rate"`
Comment string `json:"comment"`
Creator string `json:"creator"`
NumFiles float64 `json:"num_files"`
NumPieces float64 `json:"num_pieces"`
PieceLength float64 `json:"piece_length"`
Private bool `json:"private"`
TotalSize float64 `json:"total_size"`
Eta json.Number `json:"eta"`
FileProgress []float64 `json:"file_progress"`
Files []struct {
Index int64 `json:"index"`
Path string `json:"path"`
Size int64 `json:"size"`
Offset int64 `json:"offset"`
} `json:"files"`
OrigFiles []struct {
Index int64 `json:"index"`
Path string `json:"path"`
Size int64 `json:"size"`
Offset int64 `json:"offset"`
} `json:"orig_files"`
IsSeed bool `json:"is_seed"`
Peers []interface{} `json:"peers"`
Queue int `json:"queue"`
Ratio float64 `json:"ratio"`
CompletedTime float64 `json:"completed_time"`
LastSeenComplete float64 `json:"last_seen_complete"`
Name string `json:"name"`
Pieces interface{} `json:"pieces"`
SeedMode bool `json:"seed_mode"`
SuperSeeding bool `json:"super_seeding"`
TimeSinceDownload float64 `json:"time_since_download"`
TimeSinceUpload float64 `json:"time_since_upload"`
TimeSinceTransfer float64 `json:"time_since_transfer"`
}

// XferStatus is the Deluge 1.0 WebUI API layout for Active Transfers.
type XferStatus struct {
Comment string `json:"comment"`
ActiveTime int64 `json:"active_time"`
Expand Down Expand Up @@ -115,3 +251,118 @@ type XferStatus struct {
StopRatio float64 `json:"stop_ratio"`
IsFinished bool `json:"is_finished"`
}

// XferStatusCompat is a compatibile struct for Deluge 1 and 2 API data.
type XferStatusCompat struct {
ActiveTime float64 `json:"active_time"`
SeedingTime float64 `json:"seeding_time"`
FinishedTime float64 `json:"finished_time"`
AllTimeDownload float64 `json:"all_time_download"`
StorageMode string `json:"storage_mode"`
DistributedCopies float64 `json:"distributed_copies"`
DownloadPayloadRate float64 `json:"download_payload_rate"`
FilePriorities []int `json:"file_priorities"`
Hash string `json:"hash"`
AutoManaged bool `json:"auto_managed"`
IsAutoManaged bool `json:"is_auto_managed"`
IsFinished bool `json:"is_finished"`
MaxConnections float64 `json:"max_connections"`
MaxDownloadSpeed float64 `json:"max_download_speed"`
MaxUploadSlots float64 `json:"max_upload_slots"`
MaxUploadSpeed float64 `json:"max_upload_speed"`
Message string `json:"message"`
MoveOnCompletedPath string `json:"move_on_completed_path"`
MoveOnCompleted bool `json:"move_on_completed"`
MoveCompletedPath string `json:"move_completed_path"`
MoveCompleted bool `json:"move_completed"`
NextAnnounce float64 `json:"next_announce"`
NumPeers int64 `json:"num_peers"`
NumSeeds int64 `json:"num_seeds"`
Owner string `json:"owner"`
Paused bool `json:"paused"`
PrioritizeFirstLast bool `json:"prioritize_first_last"`
PrioritizeFirstLastPieces bool `json:"prioritize_first_last_pieces"`
SequentialDownload bool `json:"sequential_download"`
Progress float64 `json:"progress"`
Shared bool `json:"shared"`
RemoveAtRatio bool `json:"remove_at_ratio"`
SavePath string `json:"save_path"`
DownloadLocation string `json:"download_location"`
SeedsPeersRatio float64 `json:"seeds_peers_ratio"`
SeedRank int `json:"seed_rank"`
State string `json:"state"`
StopAtRatio bool `json:"stop_at_ratio"`
StopRatio float64 `json:"stop_ratio"`
TimeAdded float64 `json:"time_added"`
TotalDone float64 `json:"total_done"`
TotalPayloadDownload float64 `json:"total_payload_download"`
TotalPayloadUpload float64 `json:"total_payload_upload"`
TotalPeers int64 `json:"total_peers"`
TotalSeeds float64 `json:"total_seeds"`
TotalUploaded float64 `json:"total_uploaded"`
TotalWanted float64 `json:"total_wanted"`
TotalRemaining float64 `json:"total_remaining"`
Tracker string `json:"tracker"`
TrackerHost string `json:"tracker_host"`
TrackerStatus string `json:"tracker_status"`
UploadPayloadRate float64 `json:"upload_payload_rate"`
Comment string `json:"comment"`
Creator string `json:"creator"`
NumFiles float64 `json:"num_files"`
NumPieces float64 `json:"num_pieces"`
PieceLength float64 `json:"piece_length"`
Private bool `json:"private"`
TotalSize float64 `json:"total_size"`
Eta json.Number `json:"eta"`
FileProgress []float64 `json:"file_progress"`
Files []struct {
Index int64 `json:"index"`
Path string `json:"path"`
Size int64 `json:"size"`
Offset int64 `json:"offset"`
} `json:"files"`
OrigFiles []struct {
Index int64 `json:"index"`
Path string `json:"path"`
Size int64 `json:"size"`
Offset int64 `json:"offset"`
} `json:"orig_files"`
IsSeed bool `json:"is_seed"`
Peers []interface{} `json:"peers"`
Queue int64 `json:"queue"`
Ratio float64 `json:"ratio"`
CompletedTime float64 `json:"completed_time"`
LastSeenComplete float64 `json:"last_seen_complete"`
Name string `json:"name"`
Pieces interface{} `json:"pieces"`
SeedMode bool `json:"seed_mode"`
SuperSeeding bool `json:"super_seeding"`
TimeSinceDownload float64 `json:"time_since_download"`
TimeSinceUpload float64 `json:"time_since_upload"`
TimeSinceTransfer float64 `json:"time_since_transfer"`
Label string `json:"label"`
Trackers []struct {
SendStats bool `json:"send_stats"`
Source float64 `json:"source"`
StartSent bool `json:"start_sent"`
URL string `json:"url"`
Trackerid string `json:"trackerid"`
Tier float64 `json:"tier"`
FailLimit int64 `json:"fail_limit"`
Verified bool `json:"verified"`
Message string `json:"message"`
LastError struct {
Value int `json:"value"`
Category string `json:"category"`
} `json:"last_error"`
NextAnnounce interface{} `json:"next_announce"`
MinAnnounce interface{} `json:"min_announce"`
ScrapeIncomplete float64 `json:"scrape_incomplete"`
ScrapeComplete float64 `json:"scrape_complete"`
ScrapeDownloaded float64 `json:"scrape_downloaded"`
Fails int64 `json:"fails"`
Updating bool `json:"updating"`
CompleteSent bool `json:"complete_sent"`
Endpoints []interface{} `json:"endpoints"`
} `json:"trackers"`
}
Loading

0 comments on commit 8fba78e

Please sign in to comment.