-
Notifications
You must be signed in to change notification settings - Fork 9
/
bt2qbt.go
68 lines (58 loc) · 1.98 KB
/
bt2qbt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"log"
"os"
"path"
"runtime"
"time"
"github.com/fatih/color"
"github.com/rumanzo/bt2qbt/internal/options"
"github.com/rumanzo/bt2qbt/internal/transfer"
"github.com/rumanzo/bt2qbt/pkg/helpers"
"github.com/rumanzo/bt2qbt/pkg/utorrentStructs"
"github.com/zeebo/bencode"
)
var version, commit, date, buildImage string
func main() {
opts := options.MakeOpts()
if opts.Version {
fmt.Printf("Version: %v\nCommit: %v\nGolang version: %v\nBuild image: %v\n", version, commit, runtime.Version(), buildImage)
os.Exit(0)
}
resumeFilePath := path.Join(opts.BitDir, "resume.dat")
if _, err := os.Stat(resumeFilePath); os.IsNotExist(err) {
log.Println("Can't find uTorrent\\Bittorrent resume file")
time.Sleep(30 * time.Second)
os.Exit(1)
}
resumeFile := map[string]interface{}{}
err := helpers.DecodeTorrentFile(resumeFilePath, resumeFile)
if err != nil {
log.Println("Can't decode uTorrent\\Bittorrent resume file")
time.Sleep(30 * time.Second)
os.Exit(1)
}
// hate utorrent for heterogeneous resume.dat scheme
delete(resumeFile, ".fileguard")
delete(resumeFile, "rec")
b, _ := bencode.EncodeBytes(resumeFile)
resumeItems := map[string]*utorrentStructs.ResumeItem{}
err = bencode.DecodeBytes(b, &resumeItems)
if err != nil {
log.Printf("Can't convert resume.dat. Err: %v\n", err)
time.Sleep(30 * time.Second)
os.Exit(1)
}
color.Green("It will be performed processing from directory %v to directory %v\n", opts.BitDir, opts.QBitDir)
color.HiRed("Check that the qBittorrent is turned off and the directory %v and %v is backed up.\n",
opts.QBitDir, opts.Categories)
color.HiRed("Check that you previously disable option \"Append .!ut/.!bt to incomplete files\" in preferences of uTorrent/Bittorrent \n")
color.HiRed("Close uTorrent/Bittorrent and qBittorrent previously\n\n")
fmt.Println("Press Enter to start")
fmt.Scanln()
log.Println("Started")
transfer.HandleResumeItems(opts, resumeItems)
fmt.Println("\nPress Enter to exit")
fmt.Scanln()
}