mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-20 22:16:09 +05:00
add tgbot
This commit is contained in:
58
server/tgbot/tshelper.go
Normal file
58
server/tgbot/tshelper.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package tgbot
|
||||
|
||||
import (
|
||||
tele "gopkg.in/telebot.v4"
|
||||
"server/log"
|
||||
set "server/settings"
|
||||
"server/torr"
|
||||
"server/web/api/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func addTorrent(c tele.Context, link string) error {
|
||||
log.TLogln("tg add torrent", link)
|
||||
link = strings.ReplaceAll(link, "&", "&")
|
||||
torrSpec, err := utils.ParseLink(link)
|
||||
|
||||
if err != nil {
|
||||
log.TLogln("tg error parse link:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
tor, err := torr.AddTorrent(torrSpec, "", "", "", "")
|
||||
|
||||
if tor.Data != "" && set.BTsets.EnableDebug {
|
||||
log.TLogln("torrent data:", tor.Data)
|
||||
}
|
||||
if tor.Category != "" && set.BTsets.EnableDebug {
|
||||
log.TLogln("torrent category:", tor.Category)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.TLogln("tg error add torrent:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
go func() {
|
||||
if !tor.GotInfo() {
|
||||
log.TLogln("tg error add torrent: timeout connection get torrent info")
|
||||
c.Send("Ошибка при добаваления торрента: timeout connection get torrent info")
|
||||
return
|
||||
}
|
||||
|
||||
if tor.Title == "" {
|
||||
tor.Title = torrSpec.DisplayName // prefer dn over name
|
||||
tor.Title = strings.ReplaceAll(tor.Title, "rutor.info", "")
|
||||
tor.Title = strings.ReplaceAll(tor.Title, "_", " ")
|
||||
tor.Title = strings.Trim(tor.Title, " ")
|
||||
if tor.Title == "" {
|
||||
tor.Title = tor.Name()
|
||||
}
|
||||
}
|
||||
|
||||
torr.SaveTorrentToDB(tor)
|
||||
c.Send("Торрент добавлен: <code>" + link + "</code>")
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user