mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
some fix
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
|||||||
"server/rutor/torrsearch"
|
"server/rutor/torrsearch"
|
||||||
"server/rutor/utils"
|
"server/rutor/utils"
|
||||||
"server/settings"
|
"server/settings"
|
||||||
|
utils2 "server/torr/utils"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -28,6 +29,7 @@ var (
|
|||||||
func Start() {
|
func Start() {
|
||||||
go func() {
|
go func() {
|
||||||
if settings.BTsets.EnableRutorSearch {
|
if settings.BTsets.EnableRutorSearch {
|
||||||
|
loadDB()
|
||||||
updateDB()
|
updateDB()
|
||||||
isStop = false
|
isStop = false
|
||||||
for !isStop {
|
for !isStop {
|
||||||
@@ -45,42 +47,55 @@ func Start() {
|
|||||||
|
|
||||||
func Stop() {
|
func Stop() {
|
||||||
isStop = true
|
isStop = true
|
||||||
|
torrs = nil
|
||||||
|
torrsearch.NewIndex(nil)
|
||||||
|
utils2.FreeOSMemGC()
|
||||||
time.Sleep(time.Millisecond * 1500)
|
time.Sleep(time.Millisecond * 1500)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/yourok-0001/releases/raw/master/torr/rutor.ls
|
// https://github.com/yourok-0001/releases/raw/master/torr/rutor.ls
|
||||||
func updateDB() {
|
func updateDB() {
|
||||||
log.TLogln("Update rutor db")
|
log.TLogln("Update rutor db")
|
||||||
filename := filepath.Join(settings.Path, "rutor.tmp")
|
fnTmp := filepath.Join(settings.Path, "rutor.tmp")
|
||||||
out, err := os.Create(filename)
|
out, err := os.Create(fnTmp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.TLogln("Error create file rutor.tmp:", err)
|
log.TLogln("Error create file rutor.tmp:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer out.Close()
|
|
||||||
resp, err := http.Get("https://github.com/yourok-0001/releases/raw/master/torr/rutor.ls")
|
resp, err := http.Get("https://github.com/yourok-0001/releases/raw/master/torr/rutor.ls")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.TLogln("Error connect to rutor db:", err)
|
log.TLogln("Error connect to rutor db:", err)
|
||||||
|
out.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
_, err = io.Copy(out, resp.Body)
|
_, err = io.Copy(out, resp.Body)
|
||||||
|
out.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.TLogln("Error download rutor db:", err)
|
log.TLogln("Error download rutor db:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Remove(filepath.Join(settings.Path, "rutor.ls"))
|
fnOrig := filepath.Join(settings.Path, "rutor.ls")
|
||||||
|
|
||||||
|
md5Tmp := utils.MD5File(fnTmp)
|
||||||
|
md5Orig := utils.MD5File(fnOrig)
|
||||||
|
if md5Tmp != md5Orig {
|
||||||
|
err = os.Remove(fnOrig)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
log.TLogln("Error remove old rutor db:", err)
|
log.TLogln("Error remove old rutor db:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = os.Rename(filename, filepath.Join(settings.Path, "rutor.ls"))
|
err = os.Rename(fnTmp, fnOrig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.TLogln("Error rename rutor db:", err)
|
log.TLogln("Error rename rutor db:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
loadDB()
|
loadDB()
|
||||||
|
} else {
|
||||||
|
os.Remove(fnTmp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadDB() {
|
func loadDB() {
|
||||||
@@ -100,9 +115,13 @@ func loadDB() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
utils2.FreeOSMemGC()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Search(query string) []*models.TorrentDetails {
|
func Search(query string) []*models.TorrentDetails {
|
||||||
|
if !settings.BTsets.EnableRutorSearch {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
matchedIDs := torrsearch.Search(query)
|
matchedIDs := torrsearch.Search(query)
|
||||||
if len(matchedIDs) == 0 {
|
if len(matchedIDs) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
func ClearStr(str string) string {
|
func ClearStr(str string) string {
|
||||||
ret := ""
|
ret := ""
|
||||||
@@ -12,3 +17,26 @@ func ClearStr(str string) string {
|
|||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MD5File(fname string) string {
|
||||||
|
f, err := os.Open(fname)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
buf := make([]byte, 1024*1024)
|
||||||
|
h := sha256.New()
|
||||||
|
|
||||||
|
for {
|
||||||
|
bytesRead, err := f.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
h.Write(buf[:bytesRead])
|
||||||
|
}
|
||||||
|
|
||||||
|
return hex.EncodeToString(h.Sum(nil))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user