logging changes
This commit is contained in:
parent
be0cc403b9
commit
02c9f2af6b
14 changed files with 96 additions and 77 deletions
|
@ -11,7 +11,6 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -23,8 +22,9 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
//TODO logging
|
||||
|
||||
// TODO logging
|
||||
// TODO error handling
|
||||
// TODO rewrite
|
||||
func Download(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||
|
||||
log.Debug().Int64("chat", update.Message.Chat.ID).Int64("user", update.Message.From.ID).Msg("starting download")
|
||||
|
@ -92,8 +92,7 @@ func Download(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
botIO.EditMessage(message, bot)
|
||||
|
||||
serveMedia(update, bot, downloadTarget, files[0].Name())
|
||||
log2.Println("[download] Served URL " + update.Message.CommandArguments() + " for " + strconv.FormatInt(update.Message.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10))
|
||||
|
||||
log.Debug().Str("URL", update.Message.CommandArguments()).Int64("user", update.Message.From.ID).Int64("chat", update.Message.Chat.ID).Msg("Served Video")
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
log.Info().Msg("downloaded file")
|
||||
|
@ -148,8 +147,8 @@ func runYTDL(URL string, targetDir string) (success bool) {
|
|||
func matchURL(URL string) (matchedURL string) {
|
||||
parsedURL, err := url.Parse(URL)
|
||||
if err != nil {
|
||||
log2.Fatal(err)
|
||||
|
||||
log.Err(err).Msg("Failed to parse URL")
|
||||
return ""
|
||||
}
|
||||
|
||||
var domainRegex = regexp.MustCompile(`(youtube\.com$)|(youtu\.be$)`)
|
||||
|
@ -167,7 +166,8 @@ func matchURL(URL string) (matchedURL string) {
|
|||
func shortURL(URL string) (shorturl string) {
|
||||
resp, err := http.Get(config.BotConfig.Download.Yourls.APIPath + "?signature=" + config.BotConfig.Download.Yourls.Signature + "&action=shorturl&format=simple&url=" + URL)
|
||||
if err != nil {
|
||||
log2.Fatal(err)
|
||||
log.Err(err).Msg("Failed to get shortURL")
|
||||
return ""
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
@ -175,7 +175,8 @@ func shortURL(URL string) (shorturl string) {
|
|||
body, err := io.ReadAll(resp.Body)
|
||||
|
||||
if err != nil {
|
||||
log2.Fatal(err)
|
||||
log.Err(err).Msg("Failed to get shortURL")
|
||||
return ""
|
||||
}
|
||||
|
||||
return string(body)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue