2017-12-26 16:25:10 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-12-29 18:26:13 +01:00
|
|
|
"fmt"
|
2018-04-02 12:17:50 +02:00
|
|
|
"github.com/fatih/color"
|
2022-03-30 01:30:29 +02:00
|
|
|
"github.com/rumanzo/bt2qbt/internal/options"
|
|
|
|
"github.com/rumanzo/bt2qbt/internal/transfer"
|
|
|
|
"github.com/rumanzo/bt2qbt/pkg/helpers"
|
|
|
|
"github.com/rumanzo/bt2qbt/pkg/utorrentStructs"
|
2017-12-29 18:26:13 +01:00
|
|
|
"github.com/zeebo/bencode"
|
2017-12-26 21:56:32 +01:00
|
|
|
"log"
|
2017-12-29 18:26:13 +01:00
|
|
|
"os"
|
2022-03-30 01:30:29 +02:00
|
|
|
"path"
|
2018-09-19 23:27:48 +02:00
|
|
|
"runtime"
|
2018-05-11 13:35:20 +02:00
|
|
|
"time"
|
2017-12-26 16:25:10 +01:00
|
|
|
)
|
|
|
|
|
2022-03-30 01:30:29 +02:00
|
|
|
var version, commit, date, buildImage string
|
2017-12-26 16:25:10 +01:00
|
|
|
|
|
|
|
func main() {
|
2022-03-30 01:30:29 +02:00
|
|
|
opts := options.MakeOpts()
|
2020-02-16 12:58:26 +01:00
|
|
|
|
2022-03-30 01:30:29 +02:00
|
|
|
if opts.Version {
|
2022-04-01 01:42:46 +02:00
|
|
|
date = time.Now().Format("2006-01-02 15:04:05")
|
2022-03-30 01:30:29 +02:00
|
|
|
fmt.Printf("Version: %v\nCommit: %v\nGolang version: %v\nBuild image: %v\nBuild date: %v\n", version, commit, runtime.Version(), buildImage, date)
|
|
|
|
os.Exit(0)
|
2018-04-09 12:09:59 +02:00
|
|
|
}
|
|
|
|
|
2022-03-30 01:30:29 +02:00
|
|
|
resumeFilePath := path.Join(opts.BitDir, "resume.dat")
|
|
|
|
if _, err := os.Stat(resumeFilePath); os.IsNotExist(err) {
|
2018-04-02 12:17:50 +02:00
|
|
|
log.Println("Can't find uTorrent\\Bittorrent resume file")
|
|
|
|
time.Sleep(30 * time.Second)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2022-03-30 01:30:29 +02:00
|
|
|
resumeFile := map[string]interface{}{}
|
|
|
|
err := helpers.DecodeTorrentFile(resumeFilePath, resumeFile)
|
2018-04-02 12:17:50 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Println("Can't decode uTorrent\\Bittorrent resume file")
|
|
|
|
time.Sleep(30 * time.Second)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2022-03-30 01:30:29 +02:00
|
|
|
// 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 {
|
2022-04-08 23:09:33 +02:00
|
|
|
log.Printf("Can't convert resume.dat. Err: %v\n", err)
|
2022-03-30 01:30:29 +02:00
|
|
|
time.Sleep(30 * time.Second)
|
|
|
|
os.Exit(1)
|
2018-04-12 00:46:33 +02:00
|
|
|
}
|
2022-03-30 01:30:29 +02:00
|
|
|
|
|
|
|
color.Green("It will be performed processing from directory %v to directory %v\n", opts.BitDir, opts.QBitDir)
|
2022-04-03 18:18:10 +02:00
|
|
|
color.HiRed("Check that the qBittorrent is turned off and the directory %v and %v is backed up.\n",
|
|
|
|
opts.QBitDir, opts.Categories)
|
2021-05-07 14:53:47 +02:00
|
|
|
color.HiRed("Check that you previously disable option \"Append .!ut/.!bt to incomplete files\" in preferences of uTorrent/Bittorrent \n\n")
|
2018-04-02 12:17:50 +02:00
|
|
|
fmt.Println("Press Enter to start")
|
2018-04-18 14:26:29 +02:00
|
|
|
fmt.Scanln()
|
2018-05-10 22:09:40 +02:00
|
|
|
log.Println("Started")
|
2020-04-04 15:58:29 +02:00
|
|
|
|
2022-03-30 01:30:29 +02:00
|
|
|
transfer.HandleResumeItems(opts, resumeItems)
|
2020-04-04 15:58:29 +02:00
|
|
|
|
2022-03-30 01:30:29 +02:00
|
|
|
fmt.Println("\nPress Enter to exit")
|
|
|
|
fmt.Scanln()
|
2018-04-12 00:46:33 +02:00
|
|
|
|
2020-02-11 23:10:35 +01:00
|
|
|
}
|