mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
refactor and update
This commit is contained in:
54
src/server/torr/dbwrapper.go
Normal file
54
src/server/torr/dbwrapper.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package torr
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"server/settings"
|
||||
"server/torr/state"
|
||||
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
)
|
||||
|
||||
func AddTorrentDB(torr *Torrent) {
|
||||
t := new(settings.TorrentDB)
|
||||
t.TorrentSpec = torr.TorrentSpec
|
||||
t.Name = torr.Name()
|
||||
t.Title = torr.Title
|
||||
t.Poster = torr.Poster
|
||||
t.Timestamp = time.Now().Unix()
|
||||
t.Files = torr.Status().FileStats
|
||||
settings.AddTorrent(t)
|
||||
}
|
||||
|
||||
func GetTorrentDB(hash metainfo.Hash) *Torrent {
|
||||
list := settings.ListTorrent()
|
||||
for _, db := range list {
|
||||
if hash == db.InfoHash {
|
||||
torr := new(Torrent)
|
||||
torr.TorrentSpec = db.TorrentSpec
|
||||
torr.Title = db.Title
|
||||
torr.Poster = db.Poster
|
||||
torr.Stat = state.TorrentInDB
|
||||
return torr
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func RemTorrentDB(hash metainfo.Hash) {
|
||||
settings.RemTorrent(hash)
|
||||
}
|
||||
|
||||
func ListTorrentsDB() map[metainfo.Hash]*Torrent {
|
||||
ret := make(map[metainfo.Hash]*Torrent)
|
||||
list := settings.ListTorrent()
|
||||
for _, db := range list {
|
||||
torr := new(Torrent)
|
||||
torr.TorrentSpec = db.TorrentSpec
|
||||
torr.Title = db.Title
|
||||
torr.Poster = db.Poster
|
||||
torr.Stat = state.TorrentInDB
|
||||
ret[torr.TorrentSpec.InfoHash] = torr
|
||||
}
|
||||
return ret
|
||||
}
|
||||
Reference in New Issue
Block a user