bt2qbt/bt2qbt.go

69 lines
2.0 KiB
Go
Raw Normal View History

2017-12-26 16:25:10 +01:00
package main
import (
"fmt"
2024-04-06 19:43:55 +02:00
"log"
"os"
"path"
"runtime"
"time"
2018-04-02 12:17:50 +02:00
"github.com/fatih/color"
Full refactor. Introduce tests (#35) * start refactor * default golang loyaout separate qbittorrent and torrent structures * stage * move flags handle to module and cover it with tests change handle sep with path.join * ugly remove unneeded fields from resume.dat * use path joing prepare for resume structs * Introduce subtests * fix behavior * Move to structures instead of using interfaces * Make main cmd clean, decomposite functions * Make main cmd clean, decomposite functions * Detect torrents functions and tests * Fixes * Fixes * New tests for content layout and file paths reformat code for project change libtorrent version append torrent v2 schema in torrent structs * filepath helper module fix some tests * fileHelpers new functions and tests * new function with cut last part with tests * function description and small fix * rename some variables and structures * beautiful tests handle for savePaths starting refactor savepaths * Refactor HandleSavePath func. Cover with tests Move replace field creation to handle and assign pointer, instead of generate each time with handle resumeItem. Moved opts to transferStructure. * fix some tests * HandleSavePaths covered with tests and little bit fixed * Another one additional test for fully function cover * check for tests * Remove PiecePriority * Refactored HandlePieces functions Removed unused functions * Rename variables. Introduced new tests * Append tests * Rename test funcs * New tests * New tests * move modules * introduce Makefile * Adapt fileHelpers for both windows and linux. Linux tests passed Use slashed paths for search torrents * remove test template * test fileset * Makefile. Version introduce * Fix darwin i386 version build * Bug fix with mappedfiles Need more tests and append new functionality. * tests for HandleSavePaths with absoulte paths in mapped files * additional tests with fileshare * all tests OK * Fix torrent state. Added tests * fixes after code inspection * Magnet link support. Tests * README.md update Co-authored-by: Alexey Kostin <a.kostin@corp.mail.ru>
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"
"github.com/zeebo/bencode"
2017-12-26 16:25:10 +01:00
)
Full refactor. Introduce tests (#35) * start refactor * default golang loyaout separate qbittorrent and torrent structures * stage * move flags handle to module and cover it with tests change handle sep with path.join * ugly remove unneeded fields from resume.dat * use path joing prepare for resume structs * Introduce subtests * fix behavior * Move to structures instead of using interfaces * Make main cmd clean, decomposite functions * Make main cmd clean, decomposite functions * Detect torrents functions and tests * Fixes * Fixes * New tests for content layout and file paths reformat code for project change libtorrent version append torrent v2 schema in torrent structs * filepath helper module fix some tests * fileHelpers new functions and tests * new function with cut last part with tests * function description and small fix * rename some variables and structures * beautiful tests handle for savePaths starting refactor savepaths * Refactor HandleSavePath func. Cover with tests Move replace field creation to handle and assign pointer, instead of generate each time with handle resumeItem. Moved opts to transferStructure. * fix some tests * HandleSavePaths covered with tests and little bit fixed * Another one additional test for fully function cover * check for tests * Remove PiecePriority * Refactored HandlePieces functions Removed unused functions * Rename variables. Introduced new tests * Append tests * Rename test funcs * New tests * New tests * move modules * introduce Makefile * Adapt fileHelpers for both windows and linux. Linux tests passed Use slashed paths for search torrents * remove test template * test fileset * Makefile. Version introduce * Fix darwin i386 version build * Bug fix with mappedfiles Need more tests and append new functionality. * tests for HandleSavePaths with absoulte paths in mapped files * additional tests with fileshare * all tests OK * Fix torrent state. Added tests * fixes after code inspection * Magnet link support. Tests * README.md update Co-authored-by: Alexey Kostin <a.kostin@corp.mail.ru>
2022-03-30 01:30:29 +02:00
var version, commit, date, buildImage string
2017-12-26 16:25:10 +01:00
func main() {
Full refactor. Introduce tests (#35) * start refactor * default golang loyaout separate qbittorrent and torrent structures * stage * move flags handle to module and cover it with tests change handle sep with path.join * ugly remove unneeded fields from resume.dat * use path joing prepare for resume structs * Introduce subtests * fix behavior * Move to structures instead of using interfaces * Make main cmd clean, decomposite functions * Make main cmd clean, decomposite functions * Detect torrents functions and tests * Fixes * Fixes * New tests for content layout and file paths reformat code for project change libtorrent version append torrent v2 schema in torrent structs * filepath helper module fix some tests * fileHelpers new functions and tests * new function with cut last part with tests * function description and small fix * rename some variables and structures * beautiful tests handle for savePaths starting refactor savepaths * Refactor HandleSavePath func. Cover with tests Move replace field creation to handle and assign pointer, instead of generate each time with handle resumeItem. Moved opts to transferStructure. * fix some tests * HandleSavePaths covered with tests and little bit fixed * Another one additional test for fully function cover * check for tests * Remove PiecePriority * Refactored HandlePieces functions Removed unused functions * Rename variables. Introduced new tests * Append tests * Rename test funcs * New tests * New tests * move modules * introduce Makefile * Adapt fileHelpers for both windows and linux. Linux tests passed Use slashed paths for search torrents * remove test template * test fileset * Makefile. Version introduce * Fix darwin i386 version build * Bug fix with mappedfiles Need more tests and append new functionality. * tests for HandleSavePaths with absoulte paths in mapped files * additional tests with fileshare * all tests OK * Fix torrent state. Added tests * fixes after code inspection * Magnet link support. Tests * README.md update Co-authored-by: Alexey Kostin <a.kostin@corp.mail.ru>
2022-03-30 01:30:29 +02:00
opts := options.MakeOpts()
2020-02-16 12:58:26 +01:00
Full refactor. Introduce tests (#35) * start refactor * default golang loyaout separate qbittorrent and torrent structures * stage * move flags handle to module and cover it with tests change handle sep with path.join * ugly remove unneeded fields from resume.dat * use path joing prepare for resume structs * Introduce subtests * fix behavior * Move to structures instead of using interfaces * Make main cmd clean, decomposite functions * Make main cmd clean, decomposite functions * Detect torrents functions and tests * Fixes * Fixes * New tests for content layout and file paths reformat code for project change libtorrent version append torrent v2 schema in torrent structs * filepath helper module fix some tests * fileHelpers new functions and tests * new function with cut last part with tests * function description and small fix * rename some variables and structures * beautiful tests handle for savePaths starting refactor savepaths * Refactor HandleSavePath func. Cover with tests Move replace field creation to handle and assign pointer, instead of generate each time with handle resumeItem. Moved opts to transferStructure. * fix some tests * HandleSavePaths covered with tests and little bit fixed * Another one additional test for fully function cover * check for tests * Remove PiecePriority * Refactored HandlePieces functions Removed unused functions * Rename variables. Introduced new tests * Append tests * Rename test funcs * New tests * New tests * move modules * introduce Makefile * Adapt fileHelpers for both windows and linux. Linux tests passed Use slashed paths for search torrents * remove test template * test fileset * Makefile. Version introduce * Fix darwin i386 version build * Bug fix with mappedfiles Need more tests and append new functionality. * tests for HandleSavePaths with absoulte paths in mapped files * additional tests with fileshare * all tests OK * Fix torrent state. Added tests * fixes after code inspection * Magnet link support. Tests * README.md update Co-authored-by: Alexey Kostin <a.kostin@corp.mail.ru>
2022-03-30 01:30:29 +02:00
if opts.Version {
2024-04-06 19:43:55 +02:00
fmt.Printf("Version: %v\nCommit: %v\nGolang version: %v\nBuild image: %v\n", version, commit, runtime.Version(), buildImage)
Full refactor. Introduce tests (#35) * start refactor * default golang loyaout separate qbittorrent and torrent structures * stage * move flags handle to module and cover it with tests change handle sep with path.join * ugly remove unneeded fields from resume.dat * use path joing prepare for resume structs * Introduce subtests * fix behavior * Move to structures instead of using interfaces * Make main cmd clean, decomposite functions * Make main cmd clean, decomposite functions * Detect torrents functions and tests * Fixes * Fixes * New tests for content layout and file paths reformat code for project change libtorrent version append torrent v2 schema in torrent structs * filepath helper module fix some tests * fileHelpers new functions and tests * new function with cut last part with tests * function description and small fix * rename some variables and structures * beautiful tests handle for savePaths starting refactor savepaths * Refactor HandleSavePath func. Cover with tests Move replace field creation to handle and assign pointer, instead of generate each time with handle resumeItem. Moved opts to transferStructure. * fix some tests * HandleSavePaths covered with tests and little bit fixed * Another one additional test for fully function cover * check for tests * Remove PiecePriority * Refactored HandlePieces functions Removed unused functions * Rename variables. Introduced new tests * Append tests * Rename test funcs * New tests * New tests * move modules * introduce Makefile * Adapt fileHelpers for both windows and linux. Linux tests passed Use slashed paths for search torrents * remove test template * test fileset * Makefile. Version introduce * Fix darwin i386 version build * Bug fix with mappedfiles Need more tests and append new functionality. * tests for HandleSavePaths with absoulte paths in mapped files * additional tests with fileshare * all tests OK * Fix torrent state. Added tests * fixes after code inspection * Magnet link support. Tests * README.md update Co-authored-by: Alexey Kostin <a.kostin@corp.mail.ru>
2022-03-30 01:30:29 +02:00
os.Exit(0)
2018-04-09 12:09:59 +02:00
}
Full refactor. Introduce tests (#35) * start refactor * default golang loyaout separate qbittorrent and torrent structures * stage * move flags handle to module and cover it with tests change handle sep with path.join * ugly remove unneeded fields from resume.dat * use path joing prepare for resume structs * Introduce subtests * fix behavior * Move to structures instead of using interfaces * Make main cmd clean, decomposite functions * Make main cmd clean, decomposite functions * Detect torrents functions and tests * Fixes * Fixes * New tests for content layout and file paths reformat code for project change libtorrent version append torrent v2 schema in torrent structs * filepath helper module fix some tests * fileHelpers new functions and tests * new function with cut last part with tests * function description and small fix * rename some variables and structures * beautiful tests handle for savePaths starting refactor savepaths * Refactor HandleSavePath func. Cover with tests Move replace field creation to handle and assign pointer, instead of generate each time with handle resumeItem. Moved opts to transferStructure. * fix some tests * HandleSavePaths covered with tests and little bit fixed * Another one additional test for fully function cover * check for tests * Remove PiecePriority * Refactored HandlePieces functions Removed unused functions * Rename variables. Introduced new tests * Append tests * Rename test funcs * New tests * New tests * move modules * introduce Makefile * Adapt fileHelpers for both windows and linux. Linux tests passed Use slashed paths for search torrents * remove test template * test fileset * Makefile. Version introduce * Fix darwin i386 version build * Bug fix with mappedfiles Need more tests and append new functionality. * tests for HandleSavePaths with absoulte paths in mapped files * additional tests with fileshare * all tests OK * Fix torrent state. Added tests * fixes after code inspection * Magnet link support. Tests * README.md update Co-authored-by: Alexey Kostin <a.kostin@corp.mail.ru>
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)
}
Full refactor. Introduce tests (#35) * start refactor * default golang loyaout separate qbittorrent and torrent structures * stage * move flags handle to module and cover it with tests change handle sep with path.join * ugly remove unneeded fields from resume.dat * use path joing prepare for resume structs * Introduce subtests * fix behavior * Move to structures instead of using interfaces * Make main cmd clean, decomposite functions * Make main cmd clean, decomposite functions * Detect torrents functions and tests * Fixes * Fixes * New tests for content layout and file paths reformat code for project change libtorrent version append torrent v2 schema in torrent structs * filepath helper module fix some tests * fileHelpers new functions and tests * new function with cut last part with tests * function description and small fix * rename some variables and structures * beautiful tests handle for savePaths starting refactor savepaths * Refactor HandleSavePath func. Cover with tests Move replace field creation to handle and assign pointer, instead of generate each time with handle resumeItem. Moved opts to transferStructure. * fix some tests * HandleSavePaths covered with tests and little bit fixed * Another one additional test for fully function cover * check for tests * Remove PiecePriority * Refactored HandlePieces functions Removed unused functions * Rename variables. Introduced new tests * Append tests * Rename test funcs * New tests * New tests * move modules * introduce Makefile * Adapt fileHelpers for both windows and linux. Linux tests passed Use slashed paths for search torrents * remove test template * test fileset * Makefile. Version introduce * Fix darwin i386 version build * Bug fix with mappedfiles Need more tests and append new functionality. * tests for HandleSavePaths with absoulte paths in mapped files * additional tests with fileshare * all tests OK * Fix torrent state. Added tests * fixes after code inspection * Magnet link support. Tests * README.md update Co-authored-by: Alexey Kostin <a.kostin@corp.mail.ru>
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)
}
Full refactor. Introduce tests (#35) * start refactor * default golang loyaout separate qbittorrent and torrent structures * stage * move flags handle to module and cover it with tests change handle sep with path.join * ugly remove unneeded fields from resume.dat * use path joing prepare for resume structs * Introduce subtests * fix behavior * Move to structures instead of using interfaces * Make main cmd clean, decomposite functions * Make main cmd clean, decomposite functions * Detect torrents functions and tests * Fixes * Fixes * New tests for content layout and file paths reformat code for project change libtorrent version append torrent v2 schema in torrent structs * filepath helper module fix some tests * fileHelpers new functions and tests * new function with cut last part with tests * function description and small fix * rename some variables and structures * beautiful tests handle for savePaths starting refactor savepaths * Refactor HandleSavePath func. Cover with tests Move replace field creation to handle and assign pointer, instead of generate each time with handle resumeItem. Moved opts to transferStructure. * fix some tests * HandleSavePaths covered with tests and little bit fixed * Another one additional test for fully function cover * check for tests * Remove PiecePriority * Refactored HandlePieces functions Removed unused functions * Rename variables. Introduced new tests * Append tests * Rename test funcs * New tests * New tests * move modules * introduce Makefile * Adapt fileHelpers for both windows and linux. Linux tests passed Use slashed paths for search torrents * remove test template * test fileset * Makefile. Version introduce * Fix darwin i386 version build * Bug fix with mappedfiles Need more tests and append new functionality. * tests for HandleSavePaths with absoulte paths in mapped files * additional tests with fileshare * all tests OK * Fix torrent state. Added tests * fixes after code inspection * Magnet link support. Tests * README.md update Co-authored-by: Alexey Kostin <a.kostin@corp.mail.ru>
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 {
log.Printf("Can't convert resume.dat. Err: %v\n", err)
Full refactor. Introduce tests (#35) * start refactor * default golang loyaout separate qbittorrent and torrent structures * stage * move flags handle to module and cover it with tests change handle sep with path.join * ugly remove unneeded fields from resume.dat * use path joing prepare for resume structs * Introduce subtests * fix behavior * Move to structures instead of using interfaces * Make main cmd clean, decomposite functions * Make main cmd clean, decomposite functions * Detect torrents functions and tests * Fixes * Fixes * New tests for content layout and file paths reformat code for project change libtorrent version append torrent v2 schema in torrent structs * filepath helper module fix some tests * fileHelpers new functions and tests * new function with cut last part with tests * function description and small fix * rename some variables and structures * beautiful tests handle for savePaths starting refactor savepaths * Refactor HandleSavePath func. Cover with tests Move replace field creation to handle and assign pointer, instead of generate each time with handle resumeItem. Moved opts to transferStructure. * fix some tests * HandleSavePaths covered with tests and little bit fixed * Another one additional test for fully function cover * check for tests * Remove PiecePriority * Refactored HandlePieces functions Removed unused functions * Rename variables. Introduced new tests * Append tests * Rename test funcs * New tests * New tests * move modules * introduce Makefile * Adapt fileHelpers for both windows and linux. Linux tests passed Use slashed paths for search torrents * remove test template * test fileset * Makefile. Version introduce * Fix darwin i386 version build * Bug fix with mappedfiles Need more tests and append new functionality. * tests for HandleSavePaths with absoulte paths in mapped files * additional tests with fileshare * all tests OK * Fix torrent state. Added tests * fixes after code inspection * Magnet link support. Tests * README.md update Co-authored-by: Alexey Kostin <a.kostin@corp.mail.ru>
2022-03-30 01:30:29 +02:00
time.Sleep(30 * time.Second)
os.Exit(1)
2018-04-12 00:46:33 +02:00
}
Full refactor. Introduce tests (#35) * start refactor * default golang loyaout separate qbittorrent and torrent structures * stage * move flags handle to module and cover it with tests change handle sep with path.join * ugly remove unneeded fields from resume.dat * use path joing prepare for resume structs * Introduce subtests * fix behavior * Move to structures instead of using interfaces * Make main cmd clean, decomposite functions * Make main cmd clean, decomposite functions * Detect torrents functions and tests * Fixes * Fixes * New tests for content layout and file paths reformat code for project change libtorrent version append torrent v2 schema in torrent structs * filepath helper module fix some tests * fileHelpers new functions and tests * new function with cut last part with tests * function description and small fix * rename some variables and structures * beautiful tests handle for savePaths starting refactor savepaths * Refactor HandleSavePath func. Cover with tests Move replace field creation to handle and assign pointer, instead of generate each time with handle resumeItem. Moved opts to transferStructure. * fix some tests * HandleSavePaths covered with tests and little bit fixed * Another one additional test for fully function cover * check for tests * Remove PiecePriority * Refactored HandlePieces functions Removed unused functions * Rename variables. Introduced new tests * Append tests * Rename test funcs * New tests * New tests * move modules * introduce Makefile * Adapt fileHelpers for both windows and linux. Linux tests passed Use slashed paths for search torrents * remove test template * test fileset * Makefile. Version introduce * Fix darwin i386 version build * Bug fix with mappedfiles Need more tests and append new functionality. * tests for HandleSavePaths with absoulte paths in mapped files * additional tests with fileshare * all tests OK * Fix torrent state. Added tests * fixes after code inspection * Magnet link support. Tests * README.md update Co-authored-by: Alexey Kostin <a.kostin@corp.mail.ru>
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)
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")
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")
Full refactor. Introduce tests (#35) * start refactor * default golang loyaout separate qbittorrent and torrent structures * stage * move flags handle to module and cover it with tests change handle sep with path.join * ugly remove unneeded fields from resume.dat * use path joing prepare for resume structs * Introduce subtests * fix behavior * Move to structures instead of using interfaces * Make main cmd clean, decomposite functions * Make main cmd clean, decomposite functions * Detect torrents functions and tests * Fixes * Fixes * New tests for content layout and file paths reformat code for project change libtorrent version append torrent v2 schema in torrent structs * filepath helper module fix some tests * fileHelpers new functions and tests * new function with cut last part with tests * function description and small fix * rename some variables and structures * beautiful tests handle for savePaths starting refactor savepaths * Refactor HandleSavePath func. Cover with tests Move replace field creation to handle and assign pointer, instead of generate each time with handle resumeItem. Moved opts to transferStructure. * fix some tests * HandleSavePaths covered with tests and little bit fixed * Another one additional test for fully function cover * check for tests * Remove PiecePriority * Refactored HandlePieces functions Removed unused functions * Rename variables. Introduced new tests * Append tests * Rename test funcs * New tests * New tests * move modules * introduce Makefile * Adapt fileHelpers for both windows and linux. Linux tests passed Use slashed paths for search torrents * remove test template * test fileset * Makefile. Version introduce * Fix darwin i386 version build * Bug fix with mappedfiles Need more tests and append new functionality. * tests for HandleSavePaths with absoulte paths in mapped files * additional tests with fileshare * all tests OK * Fix torrent state. Added tests * fixes after code inspection * Magnet link support. Tests * README.md update Co-authored-by: Alexey Kostin <a.kostin@corp.mail.ru>
2022-03-30 01:30:29 +02:00
transfer.HandleResumeItems(opts, resumeItems)
Full refactor. Introduce tests (#35) * start refactor * default golang loyaout separate qbittorrent and torrent structures * stage * move flags handle to module and cover it with tests change handle sep with path.join * ugly remove unneeded fields from resume.dat * use path joing prepare for resume structs * Introduce subtests * fix behavior * Move to structures instead of using interfaces * Make main cmd clean, decomposite functions * Make main cmd clean, decomposite functions * Detect torrents functions and tests * Fixes * Fixes * New tests for content layout and file paths reformat code for project change libtorrent version append torrent v2 schema in torrent structs * filepath helper module fix some tests * fileHelpers new functions and tests * new function with cut last part with tests * function description and small fix * rename some variables and structures * beautiful tests handle for savePaths starting refactor savepaths * Refactor HandleSavePath func. Cover with tests Move replace field creation to handle and assign pointer, instead of generate each time with handle resumeItem. Moved opts to transferStructure. * fix some tests * HandleSavePaths covered with tests and little bit fixed * Another one additional test for fully function cover * check for tests * Remove PiecePriority * Refactored HandlePieces functions Removed unused functions * Rename variables. Introduced new tests * Append tests * Rename test funcs * New tests * New tests * move modules * introduce Makefile * Adapt fileHelpers for both windows and linux. Linux tests passed Use slashed paths for search torrents * remove test template * test fileset * Makefile. Version introduce * Fix darwin i386 version build * Bug fix with mappedfiles Need more tests and append new functionality. * tests for HandleSavePaths with absoulte paths in mapped files * additional tests with fileshare * all tests OK * Fix torrent state. Added tests * fixes after code inspection * Magnet link support. Tests * README.md update Co-authored-by: Alexey Kostin <a.kostin@corp.mail.ru>
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
}