mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
fix add torr file from dir
This commit is contained in:
@@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/anacrolix/torrent"
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -18,7 +20,6 @@ import (
|
||||
"server/settings"
|
||||
"server/torr"
|
||||
"server/version"
|
||||
"server/web/api/utils"
|
||||
)
|
||||
|
||||
type args struct {
|
||||
@@ -131,7 +132,7 @@ func watchTDir(dir string) {
|
||||
for _, file := range files {
|
||||
filename := filepath.Join(path, file.Name())
|
||||
if strings.ToLower(filepath.Ext(file.Name())) == ".torrent" {
|
||||
sp, err := utils.ParseLink("file://" + filename)
|
||||
sp, err := openFile(filename)
|
||||
if err == nil {
|
||||
tor, err := torr.AddTorrent(sp, "", "", "")
|
||||
if err == nil {
|
||||
@@ -160,3 +161,23 @@ func watchTDir(dir string) {
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
}
|
||||
|
||||
func openFile(path string) (*torrent.TorrentSpec, error) {
|
||||
minfo, err := metainfo.LoadFromFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
info, err := minfo.UnmarshalInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mag := minfo.Magnet(info.Name, minfo.HashInfoBytes())
|
||||
// mag := minfo.Magnet(nil, &info)
|
||||
return &torrent.TorrentSpec{
|
||||
InfoBytes: minfo.InfoBytes,
|
||||
Trackers: [][]string{mag.Trackers},
|
||||
DisplayName: info.Name,
|
||||
InfoHash: minfo.HashInfoBytes(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user