Changelog 0.3.0

This commit is contained in:
Mukhtar Akere
2024-11-30 15:46:58 +01:00
parent df2aa4e361
commit a51364d150
53 changed files with 2019 additions and 679 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/anacrolix/torrent/metainfo"
"goBlack/common"
"goBlack/pkg/arr"
"log"
"path/filepath"
)
@@ -94,16 +95,17 @@ func getTorrentInfo(filePath string) (*Torrent, error) {
if err != nil {
return nil, err
}
infoLength := info.Length
magnet := &common.Magnet{
InfoHash: infoHash,
Name: info.Name,
Size: info.Length,
Size: infoLength,
Link: mi.Magnet(&hash, &info).String(),
}
torrent := &Torrent{
InfoHash: infoHash,
Name: info.Name,
Size: info.Length,
Size: infoLength,
Magnet: magnet,
Filename: filePath,
}
@@ -136,12 +138,12 @@ func GetLocalCache(infohashes []string, cache *common.Cache) ([]string, map[stri
return infohashes, result
}
func ProcessQBitTorrent(d *DebridService, magnet *common.Magnet, arr *Arr, isSymlink bool) (*Torrent, error) {
func ProcessTorrent(d *DebridService, magnet *common.Magnet, a *arr.Arr, isSymlink bool) (*Torrent, error) {
debridTorrent := &Torrent{
InfoHash: magnet.InfoHash,
Magnet: magnet,
Name: magnet.Name,
Arr: arr,
Arr: a,
Size: magnet.Size,
}
@@ -159,15 +161,16 @@ func ProcessQBitTorrent(d *DebridService, magnet *common.Magnet, arr *Arr, isSym
}
}
debridTorrent, err := db.SubmitMagnet(debridTorrent)
if err != nil || debridTorrent.Id == "" {
dbt, err := db.SubmitMagnet(debridTorrent)
if err != nil || dbt.Id == "" {
logger.Printf("Error submitting magnet: %s", err)
continue
}
logger.Printf("Torrent: %s submitted to %s", debridTorrent.Name, db.GetName())
logger.Printf("Torrent: %s submitted to %s", dbt.Name, db.GetName())
d.lastUsed = index
debridTorrent.Debrid = db
return db.CheckStatus(debridTorrent, isSymlink)
dbt.Debrid = db
dbt.Arr = a
return db.CheckStatus(dbt, isSymlink)
}
return nil, fmt.Errorf("failed to process torrent")
}

View File

@@ -107,8 +107,6 @@ func (r *DebridLink) GetTorrent(id string) (*Torrent, error) {
return torrent, fmt.Errorf("torrent not found")
}
dt := *res.Value
fmt.Printf("Length of dt: %d\n", len(dt))
fmt.Printf("Raw response: %+v\n", res)
if len(dt) == 0 {
return torrent, fmt.Errorf("torrent not found")
@@ -206,7 +204,7 @@ func (r *DebridLink) CheckStatus(torrent *Torrent, isSymlink bool) (*Torrent, er
break
} else if status == "downloading" {
if !r.DownloadUncached {
go r.DeleteTorrent(torrent)
go torrent.Delete()
return torrent, fmt.Errorf("torrent: %s not cached", torrent.Name)
}
// Break out of the loop if the torrent is downloading.

View File

@@ -40,13 +40,13 @@ func GetTorrentFiles(data structs.RealDebridTorrentInfo) []TorrentFile {
continue
}
fileId := f.ID
file := &TorrentFile{
file := TorrentFile{
Name: name,
Path: name,
Size: int64(f.Bytes),
Size: f.Bytes,
Id: strconv.Itoa(fileId),
}
files = append(files, *file)
files = append(files, file)
}
return files
}
@@ -185,7 +185,7 @@ func (r *RealDebrid) CheckStatus(torrent *Torrent, isSymlink bool) (*Torrent, er
files := GetTorrentFiles(data)
torrent.Files = files
if len(files) == 0 {
r.DeleteTorrent(torrent)
go torrent.Delete()
return torrent, fmt.Errorf("no video files found")
}
filesId := make([]string, 0)
@@ -214,7 +214,7 @@ func (r *RealDebrid) CheckStatus(torrent *Torrent, isSymlink bool) (*Torrent, er
break
} else if status == "downloading" {
if !r.DownloadUncached {
go r.DeleteTorrent(torrent)
go torrent.Delete()
return torrent, fmt.Errorf("torrent: %s not cached", torrent.Name)
}
// Break out of the loop if the torrent is downloading.

View File

@@ -36,8 +36,8 @@ type debridLinkTorrentInfo struct {
} `json:"trackers"`
Created int64 `json:"created"`
DownloadPercent float64 `json:"downloadPercent"`
DownloadSpeed int64 `json:"downloadSpeed"`
UploadSpeed int64 `json:"uploadSpeed"`
DownloadSpeed int `json:"downloadSpeed"`
UploadSpeed int `json:"uploadSpeed"`
}
type DebridLinkTorrentInfo DebridLinkAPIResponse[[]debridLinkTorrentInfo]

View File

@@ -75,7 +75,7 @@ type RealDebridTorrentInfo struct {
OriginalFilename string `json:"original_filename"`
Hash string `json:"hash"`
Bytes int64 `json:"bytes"`
OriginalBytes int `json:"original_bytes"`
OriginalBytes int64 `json:"original_bytes"`
Host string `json:"host"`
Split int `json:"split"`
Progress float64 `json:"progress"`
@@ -84,12 +84,12 @@ type RealDebridTorrentInfo struct {
Files []struct {
ID int `json:"id"`
Path string `json:"path"`
Bytes int `json:"bytes"`
Bytes int64 `json:"bytes"`
Selected int `json:"selected"`
} `json:"files"`
Links []string `json:"links"`
Ended string `json:"ended,omitempty"`
Speed int64 `json:"speed,omitempty"`
Speed int `json:"speed,omitempty"`
Seeders int `json:"seeders,omitempty"`
}
@@ -97,11 +97,11 @@ type RealDebridUnrestrictResponse struct {
Id string `json:"id"`
Filename string `json:"filename"`
MimeType string `json:"mimeType"`
Filesize int64 `json:"filesize"`
Filesize int `json:"filesize"`
Link string `json:"link"`
Host string `json:"host"`
Chunks int64 `json:"chunks"`
Crc int64 `json:"crc"`
Chunks int `json:"chunks"`
Crc int `json:"crc"`
Download string `json:"download"`
Streamable int `json:"streamable"`
}

View File

@@ -11,7 +11,7 @@ type TorboxAPIResponse[T any] struct {
type TorBoxAvailableResponse TorboxAPIResponse[map[string]struct {
Name string `json:"name"`
Size int64 `json:"size"`
Size int `json:"size"`
Hash string `json:"hash"`
}]
@@ -36,7 +36,7 @@ type torboxInfo struct {
Peers int `json:"peers"`
Ratio int `json:"ratio"`
Progress float64 `json:"progress"`
DownloadSpeed int64 `json:"download_speed"`
DownloadSpeed int `json:"download_speed"`
UploadSpeed int `json:"upload_speed"`
Eta int `json:"eta"`
TorrentFile bool `json:"torrent_file"`

View File

@@ -12,6 +12,7 @@ import (
gourl "net/url"
"os"
"path"
"path/filepath"
"slices"
"strconv"
"strings"
@@ -157,24 +158,36 @@ func (r *Torbox) GetTorrent(id string) (*Torrent, error) {
torrent.Name = name
torrent.Bytes = data.Size
torrent.Folder = name
torrent.Progress = data.Progress
torrent.Progress = data.Progress * 100
torrent.Status = getStatus(data.DownloadState, data.DownloadFinished)
torrent.Speed = data.DownloadSpeed
torrent.Seeders = data.Seeds
torrent.Filename = name
torrent.OriginalFilename = name
files := make([]TorrentFile, len(data.Files))
for i, f := range data.Files {
files[i] = TorrentFile{
Id: strconv.Itoa(f.Id),
Name: f.Name,
Size: f.Size,
files := make([]TorrentFile, 0)
if len(data.Files) == 0 {
return torrent, fmt.Errorf("no files found for torrent: %s", name)
}
for _, f := range data.Files {
fileName := filepath.Base(f.Name)
if (!common.RegexMatch(common.VIDEOMATCH, fileName) &&
!common.RegexMatch(common.SUBMATCH, fileName) &&
!common.RegexMatch(common.MUSICMATCH, fileName)) || common.RegexMatch(common.SAMPLEMATCH, fileName) {
continue
}
file := TorrentFile{
Id: strconv.Itoa(f.Id),
Name: fileName,
Size: f.Size,
Path: fileName,
}
files = append(files, file)
}
if len(files) > 0 && name == data.Hash {
cleanPath := path.Clean(files[0].Name)
torrent.OriginalFilename = strings.Split(strings.TrimPrefix(cleanPath, "/"), "/")[0]
if len(files) == 0 {
return torrent, fmt.Errorf("no video files found")
}
cleanPath := path.Clean(data.Files[0].Name)
torrent.OriginalFilename = strings.Split(cleanPath, "/")[0]
torrent.Files = files
torrent.Debrid = r
return torrent, nil
@@ -203,7 +216,7 @@ func (r *Torbox) CheckStatus(torrent *Torrent, isSymlink bool) (*Torrent, error)
break
} else if status == "downloading" {
if !r.DownloadUncached {
go r.DeleteTorrent(torrent)
go torrent.Delete()
return torrent, fmt.Errorf("torrent: %s not cached", torrent.Name)
}
// Break out of the loop if the torrent is downloading.

View File

@@ -2,13 +2,14 @@ package debrid
import (
"goBlack/common"
"goBlack/pkg/arr"
"os"
"path/filepath"
)
type Arr struct {
Name string `json:"name"`
Token string `json:"token"`
Token string `json:"-"`
Host string `json:"host"`
}
@@ -38,13 +39,13 @@ type Torrent struct {
Status string `json:"status"`
Added string `json:"added"`
Progress float64 `json:"progress"`
Speed int64 `json:"speed"`
Speed int `json:"speed"`
Seeders int `json:"seeders"`
Links []string `json:"links"`
DownloadLinks []TorrentDownloadLinks `json:"download_links"`
Debrid Service
Arr *Arr
Arr *arr.Arr
}
type TorrentDownloadLinks struct {
@@ -58,15 +59,22 @@ func (t *Torrent) GetSymlinkFolder(parent string) string {
}
func (t *Torrent) GetMountFolder(rClonePath string) string {
if common.FileReady(filepath.Join(rClonePath, t.OriginalFilename)) {
return t.OriginalFilename
} else if common.FileReady(filepath.Join(rClonePath, t.Filename)) {
return t.Filename
} else if pathWithNoExt := common.RemoveExtension(t.OriginalFilename); common.FileReady(filepath.Join(rClonePath, pathWithNoExt)) {
return pathWithNoExt
} else {
return ""
possiblePaths := []string{
t.OriginalFilename,
t.Filename,
common.RemoveExtension(t.OriginalFilename),
}
for _, path := range possiblePaths {
if path != "" && common.FileReady(filepath.Join(rClonePath, path)) {
return path
}
}
return ""
}
func (t *Torrent) Delete() {
t.Debrid.DeleteTorrent(t)
}
type TorrentFile struct {