This commit is contained in:
nikk gitanes
2023-02-18 23:23:11 +03:00
parent ec4deb8afe
commit 7822157ff2
22 changed files with 62 additions and 69 deletions

View File

@@ -20,7 +20,6 @@ import (
)
func getRoot() (ret []interface{}) {
// Torrents Object
tObj := upnpav.Object{
ID: "%2FTR",
@@ -37,18 +36,16 @@ func getRoot() (ret []interface{}) {
ret = append(ret, cnt)
return
}
func getTorrents() (ret []interface{}) {
torrs := torr.ListTorrent()
// sort by title as in cds SortCaps
sort.Slice(torrs, func(i, j int) bool {
return torrs[i].Title < torrs[j].Title
})
var vol = 0
vol := 0
for _, t := range torrs {
vol++
obj := upnpav.Object{
@@ -251,7 +248,6 @@ func getLink(host, path string) string {
}
func getObjFromTorrent(path, parent, host string, torr *torr.Torrent, file *state.TorrentFileStat) (ret interface{}) {
mime, err := mt.MimeTypeByPath(file.Path)
if err != nil {
if settings.BTsets.EnableDebug {

View File

@@ -12,20 +12,24 @@ import (
"github.com/gin-gonic/gin"
)
var logPath = ""
var webLogPath = ""
var (
logPath = ""
webLogPath = ""
)
var webLog *log.Logger
var logFile *os.File
var webLogFile *os.File
var (
logFile *os.File
webLogFile *os.File
)
func Init(path, webpath string) {
webLogPath = webpath
logPath = path
if webpath != "" {
ff, err := os.OpenFile(webLogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
ff, err := os.OpenFile(webLogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666)
if err != nil {
TLogln("Error create web log file:", err)
} else {
@@ -40,7 +44,7 @@ func Init(path, webpath string) {
os.Remove(path)
}
}
ff, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
ff, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666)
if err != nil {
TLogln("Error create log file:", err)
return
@@ -87,7 +91,7 @@ func WebLogger() gin.HandlerFunc {
return
}
body := ""
//save body if not form or file
// save body if not form or file
if !strings.HasPrefix(c.Request.Header.Get("Content-Type"), "multipart/form-data") {
body, _ := ioutil.ReadAll(c.Request.Body)
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body))

View File

@@ -10,7 +10,6 @@ import (
)
func init() {
// Add a minimal number of mime types to augment go's built in types
// for environments which don't have access to a mime.types file (e.g.
// Termux on android)

View File

@@ -6,12 +6,13 @@ import (
"fmt"
"os"
"path/filepath"
"server/rutor/models"
"testing"
"server/rutor/models"
)
func TestParseChannel(t *testing.T) {
var channel = make(chan *models.TorrentDetails, 0)
channel := make(chan *models.TorrentDetails, 0)
var ftors []*models.TorrentDetails
go func() {
for torr := range channel {

View File

@@ -3,21 +3,23 @@ package rutor
import (
"compress/flate"
"encoding/json"
"github.com/agnivade/levenshtein"
"io"
"net/http"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"time"
"github.com/agnivade/levenshtein"
"server/log"
"server/rutor/models"
"server/rutor/torrsearch"
"server/rutor/utils"
"server/settings"
utils2 "server/torr/utils"
"sort"
"strconv"
"strings"
"time"
)
var (

View File

@@ -18,6 +18,6 @@ func analyze(text string) []string {
tokens := tokenize(text)
tokens = lowercaseFilter(tokens)
tokens = stopwordFilter(tokens)
//tokens = stemmerFilter(tokens)
// tokens = stemmerFilter(tokens)
return tokens
}

View File

@@ -53,9 +53,7 @@ func (v *BTSets) String() string {
return string(buf)
}
var (
BTsets *BTSets
)
var BTsets *BTSets
func SetBTSets(sets *BTSets) {
if ReadOnly {

View File

@@ -16,7 +16,7 @@ type TDB struct {
}
func NewTDB() *TDB {
db, err := bolt.Open(filepath.Join(Path, "config.db"), 0666, &bolt.Options{Timeout: 5 * time.Second})
db, err := bolt.Open(filepath.Join(Path, "config.db"), 0o666, &bolt.Options{Timeout: 5 * time.Second})
if err != nil {
log.TLogln(err)
return nil
@@ -60,7 +60,6 @@ func (v *TDB) Get(xpath, name string) []byte {
ret = buckt.Get([]byte(name))
return nil
})
if err != nil {
log.TLogln("Error get sets", xpath+"/"+name, ", error:", err)
}
@@ -95,12 +94,10 @@ func (v *TDB) Set(xpath, name string, value []byte) {
return buckt.Put([]byte(name), value)
})
if err != nil {
log.TLogln("Error put sets", xpath+"/"+name, ", error:", err)
log.TLogln("value:", value)
}
}
func (v *TDB) List(xpath string) []string {
@@ -134,7 +131,6 @@ func (v *TDB) List(xpath string) []string {
return nil
})
if err != nil {
log.TLogln("Error list sets", xpath, ", error:", err)
}
@@ -169,9 +165,7 @@ func (v *TDB) Rem(xpath, name string) {
return buckt.Delete([]byte(name))
})
if err != nil {
log.TLogln("Error rem sets", xpath+"/"+name, ", error:", err)
}
}

View File

@@ -11,9 +11,7 @@ import (
"server/web/api/utils"
)
var (
dbTorrentsName = []byte("Torrents")
)
var dbTorrentsName = []byte("Torrents")
type torrentOldDB struct {
Name string
@@ -29,7 +27,7 @@ func Migrate() {
return
}
db, err := bolt.Open(filepath.Join(Path, "torrserver.db"), 0666, nil)
db, err := bolt.Open(filepath.Join(Path, "torrserver.db"), 0o666, nil)
if err != nil {
return
}

View File

@@ -69,7 +69,7 @@ func ListViewed(hash string) []*Viewed {
err = json.Unmarshal(buf, &indeces)
if err == nil {
var ret []*Viewed
for i, _ := range indeces {
for i := range indeces {
ret = append(ret, &Viewed{hash, i})
}
return ret
@@ -85,7 +85,7 @@ func ListViewed(hash string) []*Viewed {
var indeces map[int]struct{}
err = json.Unmarshal(buf, &indeces)
if err == nil {
for i, _ := range indeces {
for i := range indeces {
ret = append(ret, &Viewed{key, i})
}
}

View File

@@ -15,9 +15,7 @@ import (
sets "server/settings"
)
var (
bts *BTServer
)
var bts *BTServer
func InitApiHelper(bt *BTServer) {
bts = bt

View File

@@ -2,9 +2,10 @@ package torr
import (
"encoding/json"
"server/torr/utils"
"time"
"server/torr/utils"
"server/settings"
"server/torr/state"

View File

@@ -64,7 +64,7 @@ func (c *Cache) Init(info *metainfo.Info, hash metainfo.Hash) {
if settings.BTsets.UseDisk {
name := filepath.Join(settings.BTsets.TorrentsSavePath, hash.HexString())
err := os.MkdirAll(name, 0777)
err := os.MkdirAll(name, 0o777)
if err != nil {
log.TLogln("Error create dir:", err)
}
@@ -235,7 +235,7 @@ func (c *Cache) getRemPieces() []*Piece {
}
} else {
// on preload clean
//TODO проверить
// TODO проверить
if p.Size > 0 && !c.isIdInFileBE(ranges, id) {
piecesRemove = append(piecesRemove, p)
}
@@ -288,7 +288,6 @@ func (c *Cache) getRemPieces() []*Piece {
}
func (c *Cache) isIdInFileBE(ranges []Range, id int) bool {
// keep 8/16 MB
FileRangeNotDelete := int64(c.pieceLength)
if FileRangeNotDelete < 8*1024*1024 {

View File

@@ -35,7 +35,7 @@ func (p *DiskPiece) WriteAt(b []byte, off int64) (n int, err error) {
p.mu.Lock()
defer p.mu.Unlock()
ff, err := os.OpenFile(p.name, os.O_RDWR|os.O_CREATE, 0666)
ff, err := os.OpenFile(p.name, os.O_RDWR|os.O_CREATE, 0o666)
if err != nil {
log.TLogln("Error open file:", err)
return 0, err
@@ -55,7 +55,7 @@ func (p *DiskPiece) ReadAt(b []byte, off int64) (n int, err error) {
p.mu.Lock()
defer p.mu.Unlock()
ff, err := os.OpenFile(p.name, os.O_RDONLY, 0666)
ff, err := os.OpenFile(p.name, os.O_RDONLY, 0o666)
if os.IsNotExist(err) {
return 0, io.EOF
}

View File

@@ -71,21 +71,21 @@ func (r *Reader) Read(p []byte) (n int, err error) {
r.readerOn()
n, err = r.Reader.Read(p)
//samsung tv fix xvid/divx
// samsung tv fix xvid/divx
if r.offset == 0 && len(p) >= 192 {
str := strings.ToLower(string(p[112:116]))
if str == "xvid" || str == "divx" {
p[112] = 0x4D //M
p[113] = 0x50 //P
p[114] = 0x34 //4
p[115] = 0x56 //V
p[112] = 0x4D // M
p[113] = 0x50 // P
p[114] = 0x34 // 4
p[115] = 0x56 // V
}
str = strings.ToLower(string(p[188:192]))
if str == "xvid" || str == "divx" {
p[188] = 0x4D //M
p[189] = 0x50 //P
p[190] = 0x34 //4
p[191] = 0x56 //V
p[188] = 0x4D // M
p[189] = 0x50 // P
p[190] = 0x34 // 4
p[191] = 0x56 // V
}
}

View File

@@ -5,6 +5,7 @@ import (
_ "image/jpeg"
_ "image/png"
"net/http"
"server/log"
)

View File

@@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"server/utils"
"github.com/gin-gonic/gin"

View File

@@ -100,10 +100,10 @@ func getM3uList(tor *state.TorrentStatus, host string, fromLast bool) string {
fn = f.Path
}
m3u += "#EXTINF:0," + fn + "\n"
fileNamesakes := findFileNamesakes(tor.FileStats, f) //find external media with same name (audio/subtiles tracks)
fileNamesakes := findFileNamesakes(tor.FileStats, f) // find external media with same name (audio/subtiles tracks)
if fileNamesakes != nil {
m3u += "#EXTVLCOPT:input-slave=" //include VLC option for external media
for _, namesake := range fileNamesakes { //include play-links to external media, with # splitter
m3u += "#EXTVLCOPT:input-slave=" // include VLC option for external media
for _, namesake := range fileNamesakes { // include play-links to external media, with # splitter
sname := filepath.Base(namesake.Path)
m3u += host + "/stream/" + url.PathEscape(sname) + "?link=" + tor.Hash + "&index=" + fmt.Sprint(namesake.Id) + "&play#"
}
@@ -118,12 +118,12 @@ func getM3uList(tor *state.TorrentStatus, host string, fromLast bool) string {
}
func findFileNamesakes(files []*state.TorrentFileStat, file *state.TorrentFileStat) []*state.TorrentFileStat {
//find files with the same name in torrent
// find files with the same name in torrent
name := filepath.Base(strings.TrimSuffix(file.Path, filepath.Ext(file.Path)))
var namesakes []*state.TorrentFileStat
for _, f := range files {
if strings.Contains(f.Path, name) { //external tracks always include name of videofile
if f != file { //exclude itself
if strings.Contains(f.Path, name) { // external tracks always include name of videofile
if f != file { // exclude itself
namesakes = append(namesakes, f)
}
}

View File

@@ -2,6 +2,7 @@ package api
import (
"net/http"
"server/rutor"
"github.com/gin-gonic/gin"

View File

@@ -211,5 +211,4 @@ func streamNoAuth(c *gin.Context) {
}
c.Header("WWW-Authenticate", "Basic realm=Authorization Required")
c.AbortWithStatus(http.StatusUnauthorized)
}

View File

@@ -68,7 +68,7 @@ func (ipl *IPList) Lookup(ip net.IP) (r Range, ok bool) {
// Return the range the given IP is in. Returns nil if no range is found.
func (ipl *IPList) lookup(ip net.IP) (Range, bool) {
var rng Range
var ok = false
ok := false
for _, r := range ipl.ranges {
ok = bytes.Compare(r.First, ip) <= 0 && bytes.Compare(ip, r.Last) <= 0
if ok {

View File

@@ -2,9 +2,10 @@ package web
import (
"net"
"server/rutor"
"sort"
"server/rutor"
"github.com/gin-contrib/cors"
"github.com/gin-contrib/location"
"github.com/gin-gonic/gin"
@@ -42,11 +43,11 @@ func Start(port string) {
gin.SetMode(gin.ReleaseMode)
//corsCfg := cors.DefaultConfig()
//corsCfg.AllowAllOrigins = true
//corsCfg.AllowHeaders = []string{"*"}
//corsCfg.AllowMethods = []string{"*"}
//corsCfg.AllowPrivateNetwork = true
// corsCfg := cors.DefaultConfig()
// corsCfg.AllowAllOrigins = true
// corsCfg.AllowHeaders = []string{"*"}
// corsCfg.AllowMethods = []string{"*"}
// corsCfg.AllowPrivateNetwork = true
corsCfg := cors.DefaultConfig()
corsCfg.AllowAllOrigins = true
corsCfg.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "X-Requested-With", "Accept", "Authorization"}