Compare commits
6 Commits
4601a0fc60
...
nsq
Author | SHA1 | Date | |
---|---|---|---|
f867606a6f | |||
0002b08256 | |||
ccefc21f53 | |||
8f45686dfc | |||
92ea0b43d0 | |||
eb4f715ce3 |
@@ -1,75 +0,0 @@
|
||||
package main
|
||||
|
||||
// import (
|
||||
// "bytes"
|
||||
// "context"
|
||||
// "encoding/json"
|
||||
// "fmt"
|
||||
// "io"
|
||||
// "log"
|
||||
// "net/http"
|
||||
// )
|
||||
|
||||
// type APIError struct {
|
||||
// Code int `json:"code"`
|
||||
// Message string `json:"message"`
|
||||
// Data APIErrorData `json:"data"`
|
||||
// }
|
||||
|
||||
// type APIErrorData struct {
|
||||
// Link APIErrorLink `json:"link"`
|
||||
// }
|
||||
|
||||
// type APIErrorLink struct {
|
||||
// Code string `json:"code"`
|
||||
// Message string `json:"message"`
|
||||
// }
|
||||
|
||||
// func SetDownloaded(item PBEvent) (err error) {
|
||||
// req, err := http.NewRequestWithContext(context.Background(), "PATCH", FULL_URL+"/"+item.Record.Id, nil)
|
||||
// if err != nil {
|
||||
// log.Printf("Error creating PATCH request: %++v", err)
|
||||
// return err
|
||||
// }
|
||||
// req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// partialItem := new(PBEvent)
|
||||
// partialItem.Record = item.Record
|
||||
// partialItem.Record.Downloaded = true
|
||||
|
||||
// body, err := json.Marshal(partialItem.Record)
|
||||
// if err != nil {
|
||||
// log.Printf("Error marshalling subscription body: %++v", err)
|
||||
// return err
|
||||
// }
|
||||
// req.Body = io.NopCloser(bytes.NewReader(body))
|
||||
|
||||
// client := http.Client{}
|
||||
// res, err := client.Do(req)
|
||||
// if err != nil {
|
||||
// log.Printf("Error sending PATCH request: %++v", err)
|
||||
// return err
|
||||
// }
|
||||
// defer res.Body.Close()
|
||||
|
||||
// if res.StatusCode != http.StatusOK {
|
||||
// log.Printf("Non-OK HTTP status: %d", res.StatusCode)
|
||||
|
||||
// body, err = io.ReadAll(res.Body)
|
||||
// if err != nil {
|
||||
// log.Printf("Error reading response body: %++v", err)
|
||||
// return err
|
||||
// }
|
||||
// var data APIError
|
||||
// err = json.Unmarshal(body, &data)
|
||||
// if err != nil {
|
||||
// log.Printf("Error unmarshaling JSON: %++v", err)
|
||||
// return err
|
||||
// }
|
||||
|
||||
// log.Printf("API error: %++v", data)
|
||||
// return fmt.Errorf("Non-OK HTTP status, err: %++v", data)
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// }
|
@@ -1,51 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func NotifyDiscordErrorless(message string) {
|
||||
err := NotifyDiscord(message)
|
||||
if err != nil {
|
||||
log.Printf("Error notifying discord: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func NotifyDiscord(message string) error {
|
||||
webhookURL := os.Getenv("YTDL_DISCORD_WEBHOOK_URL")
|
||||
if webhookURL == "" {
|
||||
return fmt.Errorf("error notifying discord: webhook URL is not set in environment variables")
|
||||
}
|
||||
|
||||
jsonData := map[string]string{"content": message}
|
||||
jsonBytes, err := json.Marshal(jsonData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error notifying discord: error marshalling JSON: %v", err)
|
||||
}
|
||||
req, err := http.NewRequest("POST", webhookURL, bytes.NewBuffer(jsonBytes))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error notifying discord: error creating request: %v", err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error notifying discord: error sending request: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error notifying discord: error reading response body: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("Response from Discord: %s", string(body))
|
||||
return nil
|
||||
}
|
@@ -3,18 +3,23 @@ package downloaders
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/gen2brain/beeep"
|
||||
logger "git.site.quack-lab.dev/dave/cylogger"
|
||||
"github.com/lrstanley/go-ytdlp"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Ensure yt-dlp is installed/up-to-date for this environment.
|
||||
ytdlp.MustInstall(context.TODO(), nil)
|
||||
}
|
||||
|
||||
var dl = ytdlp.New().
|
||||
// FormatSort("bestvideo[ext=mp4]+bestaudio[ext=m4a]").
|
||||
FormatSort("res,ext:mp4:m4a").
|
||||
FormatSort("best,ext:mp4:m4a").
|
||||
Output("C:/Users/Administrator/ytdlpVideos/%(uploader)s/%(title)s.%(ext)s").
|
||||
LimitRate(fmt.Sprintf("%dM", 150/DOWNLOAD_WORKERS)).
|
||||
// HTTPChunkSize("20M").
|
||||
ExtractorArgs("youtube:player_client=tv").
|
||||
MarkWatched().
|
||||
SponsorblockMark("all").
|
||||
RecodeVideo("mp4").
|
||||
@@ -23,35 +28,36 @@ var dl = ytdlp.New().
|
||||
type YTDLPLibDownloader struct{}
|
||||
|
||||
func (d *YTDLPLibDownloader) Download(url string) error {
|
||||
downloadlogger := logger.Default.WithPrefix(fmt.Sprintf("url=%q", url))
|
||||
_, ongoing := ongoingDownloads[url]
|
||||
if ongoing {
|
||||
// return fmt.Errorf("Download %s is already ongoing", url)
|
||||
log.Printf("Download %s is already ongoing", url)
|
||||
downloadlogger.Info("Download is already ongoing")
|
||||
return nil
|
||||
}
|
||||
ongoingDownloadsMutex.Lock()
|
||||
ongoingDownloads[url] = struct{}{}
|
||||
ongoingDownloadsMutex.Unlock()
|
||||
|
||||
log.Printf("YTDLPLib downloading %s", url)
|
||||
downloadlogger.Info("YTDLPLib downloading")
|
||||
|
||||
go func() {
|
||||
err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration)
|
||||
if err != nil {
|
||||
log.Printf("Failed beeping with %+v", err)
|
||||
}
|
||||
err = beeep.Alert("Download Started", url, "assets/information.png")
|
||||
if err != nil {
|
||||
log.Printf("Failed alerting with %+v", err)
|
||||
}
|
||||
}()
|
||||
// go func() {
|
||||
// err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration)
|
||||
// if err != nil {
|
||||
// downloadlogger.Error("Failed beeping with %+v", err)
|
||||
// }
|
||||
// err = beeep.Alert("Download Started", url, "assets/information.png")
|
||||
// if err != nil {
|
||||
// downloadlogger.Error("Failed alerting with %+v", err)
|
||||
// }
|
||||
// }()
|
||||
|
||||
_, err := dl.Run(context.TODO(), url)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed downloading %s with %+v", url, err)
|
||||
}
|
||||
|
||||
log.Printf("Downloaded %s", url)
|
||||
downloadlogger.Info("Downloaded")
|
||||
ongoingDownloadsMutex.Lock()
|
||||
delete(ongoingDownloads, url)
|
||||
ongoingDownloadsMutex.Unlock()
|
||||
|
@@ -1,34 +1,46 @@
|
||||
module ytdl
|
||||
|
||||
go 1.22.4
|
||||
go 1.24.0
|
||||
|
||||
require (
|
||||
github.com/ProtonMail/go-crypto v1.1.3 // indirect
|
||||
git.sr.ht/~jackmordaunt/go-toast v1.1.2 // indirect
|
||||
github.com/ProtonMail/go-crypto v1.3.0 // indirect
|
||||
github.com/VividCortex/ewma v1.2.0 // indirect
|
||||
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
|
||||
github.com/bitly/go-simplejson v0.5.1 // indirect
|
||||
github.com/cloudflare/circl v1.5.0 // indirect
|
||||
github.com/dlclark/regexp2 v1.11.4 // indirect
|
||||
github.com/dop251/goja v0.0.0-20241024094426-79f3a7efcdbd // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.2.0 // indirect
|
||||
github.com/cloudflare/circl v1.6.1 // indirect
|
||||
github.com/dlclark/regexp2 v1.11.5 // indirect
|
||||
github.com/dop251/goja v0.0.0-20250630131328-58d95d85e994 // indirect
|
||||
github.com/esiqveland/notify v0.13.3 // indirect
|
||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
|
||||
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
|
||||
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/google/go-cmp v0.7.0 // indirect
|
||||
github.com/google/pprof v0.0.0-20251002213607-436353cc1ee6 // indirect
|
||||
github.com/hexops/valast v1.5.0 // indirect
|
||||
github.com/jackmordaunt/icns/v3 v3.0.1 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.19 // indirect
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
|
||||
github.com/sergeymakinen/go-bmp v1.0.0 // indirect
|
||||
github.com/sergeymakinen/go-ico v1.0.0-beta.0 // indirect
|
||||
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
|
||||
github.com/ulikunitz/xz v0.5.15 // indirect
|
||||
github.com/vbauerster/mpb/v5 v5.4.0 // indirect
|
||||
golang.org/x/crypto v0.31.0 // indirect
|
||||
golang.org/x/sys v0.28.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
golang.org/x/crypto v0.42.0 // indirect
|
||||
golang.org/x/mod v0.28.0 // indirect
|
||||
golang.org/x/sync v0.17.0 // indirect
|
||||
golang.org/x/sys v0.36.0 // indirect
|
||||
golang.org/x/text v0.29.0 // indirect
|
||||
golang.org/x/tools v0.37.0 // indirect
|
||||
mvdan.cc/gofumpt v0.9.1 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
github.com/kkdai/youtube/v2 v2.10.2
|
||||
github.com/lrstanley/go-ytdlp v0.0.0-20241221063727-6717edbb36dd
|
||||
git.site.quack-lab.dev/dave/cylogger v1.4.0
|
||||
github.com/gen2brain/beeep v0.11.1
|
||||
github.com/kkdai/youtube/v2 v2.10.4
|
||||
github.com/lrstanley/go-ytdlp v1.2.6
|
||||
github.com/nsqio/go-nsq v1.1.0
|
||||
)
|
||||
|
@@ -1,7 +1,11 @@
|
||||
git.site.quack-lab.dev/dave/cylogger v1.4.0 h1:3Ca7V5JWvruARJd5S8xDFwW9LnZ9QInqkYLRdrEFvuY=
|
||||
git.site.quack-lab.dev/dave/cylogger v1.4.0/go.mod h1:wctgZplMvroA4X6p8f4B/LaCKtiBcT1Pp+L14kcS8jk=
|
||||
git.sr.ht/~jackmordaunt/go-toast v1.1.2 h1:/yrfI55LRt1M7H1vkaw+NaH1+L1CDxrqDltwm5euVuE=
|
||||
git.sr.ht/~jackmordaunt/go-toast v1.1.2/go.mod h1:jA4OqHKTQ4AFBdwrSnwnskUIIS3HYzlJSgdzCKqfavo=
|
||||
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
|
||||
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
|
||||
github.com/ProtonMail/go-crypto v1.1.3 h1:nRBOetoydLeUb4nHajyO2bKqMLfWQ/ZPwkXqXxPxCFk=
|
||||
github.com/ProtonMail/go-crypto v1.1.3/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
|
||||
github.com/ProtonMail/go-crypto v1.3.0 h1:ILq8+Sf5If5DCpHQp4PbZdS1J7HDFRXz/+xKBiRGFrw=
|
||||
github.com/ProtonMail/go-crypto v1.3.0/go.mod h1:9whxjD8Rbs29b4XWbB8irEcE8KHMqaR2e7GWU1R+/PE=
|
||||
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
|
||||
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
|
||||
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
|
||||
@@ -9,62 +13,104 @@ github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpH
|
||||
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
|
||||
github.com/bitly/go-simplejson v0.5.1 h1:xgwPbetQScXt1gh9BmoJ6j9JMr3TElvuIyjR8pgdoow=
|
||||
github.com/bitly/go-simplejson v0.5.1/go.mod h1:YOPVLzCfwK14b4Sff3oP1AmGhI9T9Vsg84etUnlyp+Q=
|
||||
github.com/cloudflare/circl v1.5.0 h1:hxIWksrX6XN5a1L2TI/h53AGPhNHoUBo+TD1ms9+pys=
|
||||
github.com/cloudflare/circl v1.5.0/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
|
||||
github.com/clipperhouse/uax29/v2 v2.2.0 h1:ChwIKnQN3kcZteTXMgb1wztSgaU+ZemkgWdohwgs8tY=
|
||||
github.com/clipperhouse/uax29/v2 v2.2.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
|
||||
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
|
||||
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=
|
||||
github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/dop251/goja v0.0.0-20241024094426-79f3a7efcdbd h1:QMSNEh9uQkDjyPwu/J541GgSH+4hw+0skJDIj9HJ3mE=
|
||||
github.com/dop251/goja v0.0.0-20241024094426-79f3a7efcdbd/go.mod h1:MxLav0peU43GgvwVgNbLAj1s/bSGboKkhuULvq/7hx4=
|
||||
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4 h1:ygs9POGDQpQGLJPlq4+0LBUmMBNox1N4JSpw+OETcvI=
|
||||
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4=
|
||||
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
|
||||
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/dop251/goja v0.0.0-20250630131328-58d95d85e994 h1:aQYWswi+hRL2zJqGacdCZx32XjKYV8ApXFGntw79XAM=
|
||||
github.com/dop251/goja v0.0.0-20250630131328-58d95d85e994/go.mod h1:MxLav0peU43GgvwVgNbLAj1s/bSGboKkhuULvq/7hx4=
|
||||
github.com/esiqveland/notify v0.13.3 h1:QCMw6o1n+6rl+oLUfg8P1IIDSFsDEb2WlXvVvIJbI/o=
|
||||
github.com/esiqveland/notify v0.13.3/go.mod h1:hesw/IRYTO0x99u1JPweAl4+5mwXJibQVUcP0Iu5ORE=
|
||||
github.com/gen2brain/beeep v0.11.1 h1:EbSIhrQZFDj1K2fzlMpAYlFOzV8YuNe721A58XcCTYI=
|
||||
github.com/gen2brain/beeep v0.11.1/go.mod h1:jQVvuwnLuwOcdctHn/uyh8horSBNJ8uGb9Cn2W4tvoc=
|
||||
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
||||
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
||||
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
|
||||
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
|
||||
github.com/go-sourcemap/sourcemap v2.1.4+incompatible h1:a+iTbH5auLKxaNwQFg0B+TCYl6lbukKPc7b5x0n1s6Q=
|
||||
github.com/go-sourcemap/sourcemap v2.1.4+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
|
||||
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=
|
||||
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10=
|
||||
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
||||
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg=
|
||||
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
|
||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/kkdai/youtube/v2 v2.10.2 h1:e3JslUDiKEfjMzxFyrOh3O59C/aLfKNZyrcav00MZV0=
|
||||
github.com/kkdai/youtube/v2 v2.10.2/go.mod h1:4y1MIg7f1o5/kQfkr7nwXFtv8PGSoe4kChOB9/iMA88=
|
||||
github.com/lrstanley/go-ytdlp v0.0.0-20241221063727-6717edbb36dd h1:lLajTMgNTs/W4H05uQYnJDRIbIvHk6XXy7DQNFRbvzU=
|
||||
github.com/lrstanley/go-ytdlp v0.0.0-20241221063727-6717edbb36dd/go.mod h1:75ujbafjqiJugIGw4K6o52/p8C0m/kt+DrYwgClXYT4=
|
||||
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/pprof v0.0.0-20251002213607-436353cc1ee6 h1:/WHh/1k4thM/w+PAZEIiZK9NwCMFahw5tUzKUCnUtds=
|
||||
github.com/google/pprof v0.0.0-20251002213607-436353cc1ee6/go.mod h1:I6V7YzU0XDpsHqbsyrghnFZLO1gwK6NPTNvmetQIk9U=
|
||||
github.com/hexops/autogold v0.8.1 h1:wvyd/bAJ+Dy+DcE09BoLk6r4Fa5R5W+O+GUzmR985WM=
|
||||
github.com/hexops/autogold v0.8.1/go.mod h1:97HLDXyG23akzAoRYJh/2OBs3kd80eHyKPvZw0S5ZBY=
|
||||
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
|
||||
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
|
||||
github.com/hexops/valast v1.5.0 h1:FBTuvVi0wjTngtXJRZXMbkN/Dn6DgsUsBwch2DUJU8Y=
|
||||
github.com/hexops/valast v1.5.0/go.mod h1:Jcy1pNH7LNraVaAZDLyv21hHg2WBv9Nf9FL6fGxU7o4=
|
||||
github.com/jackmordaunt/icns/v3 v3.0.1 h1:xxot6aNuGrU+lNgxz5I5H0qSeCjNKp8uTXB1j8D4S3o=
|
||||
github.com/jackmordaunt/icns/v3 v3.0.1/go.mod h1:5sHL59nqTd2ynTnowxB/MDQFhKNqkK8X687uKNygaSQ=
|
||||
github.com/kkdai/youtube/v2 v2.10.4 h1:T3VAQ65EB4eHptwcQIigpFvUJlV9EcKRGJJdSVUy3aU=
|
||||
github.com/kkdai/youtube/v2 v2.10.4/go.mod h1:pm4RuJ2tRIIaOvz4YMIpCY8Ls4Fm7IVtnZQyule61MU=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/lrstanley/go-ytdlp v1.2.6 h1:LJ1I+uaP2KviRAfe3tUN0Sd4yI9XlCJBG37RCH+sfq8=
|
||||
github.com/lrstanley/go-ytdlp v1.2.6/go.mod h1:38IL64XM6gULrWtKTiR0+TTNCVbxesNSbTyaFG2CGTI=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
|
||||
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/nsqio/go-nsq v1.1.0 h1:PQg+xxiUjA7V+TLdXw7nVrJ5Jbl3sN86EhGCQj4+FYE=
|
||||
github.com/nsqio/go-nsq v1.1.0/go.mod h1:vKq36oyeVXgsS5Q8YEO7WghqidAVXQlcFxzQbQTuDEY=
|
||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
|
||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
||||
github.com/sergeymakinen/go-bmp v1.0.0 h1:SdGTzp9WvCV0A1V0mBeaS7kQAwNLdVJbmHlqNWq0R+M=
|
||||
github.com/sergeymakinen/go-bmp v1.0.0/go.mod h1:/mxlAQZRLxSvJFNIEGGLBE/m40f3ZnUifpgVDlcUIEY=
|
||||
github.com/sergeymakinen/go-ico v1.0.0-beta.0 h1:m5qKH7uPKLdrygMWxbamVn+tl2HfiA3K6MFJw4GfZvQ=
|
||||
github.com/sergeymakinen/go-ico v1.0.0-beta.0/go.mod h1:wQ47mTczswBO5F0NoDt7O0IXgnV4Xy3ojrroMQzyhUk=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
|
||||
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
|
||||
github.com/ulikunitz/xz v0.5.15 h1:9DNdB5s+SgV3bQ2ApL10xRc35ck0DuIX/isZvIk+ubY=
|
||||
github.com/ulikunitz/xz v0.5.15/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
||||
github.com/vbauerster/mpb/v5 v5.4.0 h1:n8JPunifvQvh6P1D1HAl2Ur9YcmKT1tpoUuiea5mlmg=
|
||||
github.com/vbauerster/mpb/v5 v5.4.0/go.mod h1:fi4wVo7BVQ22QcvFObm+VwliQXlV1eBT8JDaKXR4JGI=
|
||||
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
|
||||
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
||||
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
|
||||
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
|
||||
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
|
||||
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
|
||||
golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U=
|
||||
golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI=
|
||||
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
|
||||
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
|
||||
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
|
||||
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sys v0.0.0-20201218084310-7d0127a74742/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
|
||||
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
|
||||
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
|
||||
golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE=
|
||||
golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
mvdan.cc/gofumpt v0.9.1 h1:p5YT2NfFWsYyTieYgwcQ8aKV3xRvFH4uuN/zB2gBbMQ=
|
||||
mvdan.cc/gofumpt v0.9.1/go.mod h1:3xYtNemnKiXaTh6R4VtlqDATFwBbdXI8lJvH/4qk7mw=
|
||||
|
@@ -3,39 +3,18 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
"ytdl/downloaders"
|
||||
|
||||
logger "git.site.quack-lab.dev/dave/cylogger"
|
||||
"github.com/nsqio/go-nsq"
|
||||
)
|
||||
|
||||
var Error *log.Logger
|
||||
var Warning *log.Logger
|
||||
|
||||
func init() {
|
||||
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
|
||||
logFile, err := os.Create("ytdl.log")
|
||||
if err != nil {
|
||||
log.Printf("Error creating log file: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
logger := io.MultiWriter(os.Stdout, logFile)
|
||||
log.SetOutput(logger)
|
||||
|
||||
Error = log.New(io.MultiWriter(logFile, os.Stderr, os.Stdout),
|
||||
fmt.Sprintf("%sERROR:%s ", "\033[0;101m", "\033[0m"),
|
||||
log.Lmicroseconds|log.Lshortfile)
|
||||
Warning = log.New(io.MultiWriter(logFile, os.Stdout),
|
||||
fmt.Sprintf("%sWarning:%s ", "\033[0;93m", "\033[0m"),
|
||||
log.Lmicroseconds|log.Lshortfile)
|
||||
}
|
||||
|
||||
// var downloader downloaders.Downloader = &downloaders.YTDLPRawDownloader{}
|
||||
// var downloader downloaders.Downloader = &downloaders.KidaiDownloader{}
|
||||
var downloader downloaders.Downloader = &downloaders.YTDLPLibDownloader{}
|
||||
@@ -43,14 +22,13 @@ var downloader downloaders.Downloader = &downloaders.YTDLPLibDownloader{}
|
||||
type DLHandler struct{}
|
||||
|
||||
func (*DLHandler) HandleMessage(message *nsq.Message) error {
|
||||
log.Printf("Received message '%s' with %d attempts", message.Body, message.Attempts)
|
||||
NotifyDiscordErrorless(fmt.Sprintf("Received message '%s' with %d attempts", message.Body, message.Attempts))
|
||||
messagelog := logger.Default.WithPrefix(fmt.Sprintf("message=%q", message.Body)).WithPrefix(fmt.Sprintf("attempts=%d", message.Attempts))
|
||||
messagelog.Info("Received message")
|
||||
|
||||
data := DownloadRequest{}
|
||||
err := json.Unmarshal(message.Body, &data)
|
||||
if err != nil {
|
||||
Error.Printf("Error unmarshalling message: %v", err)
|
||||
NotifyDiscordErrorless(fmt.Sprintf("Error unmarshalling message: %v", err))
|
||||
messagelog.Error("Error unmarshalling message: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -58,12 +36,14 @@ func (*DLHandler) HandleMessage(message *nsq.Message) error {
|
||||
defer cancel()
|
||||
|
||||
go func() {
|
||||
messagelog.Debug("Starting touch ticker")
|
||||
ticker := time.NewTicker(1 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
messagelog.Debug("Touching message")
|
||||
message.Touch()
|
||||
case <-ctx.Done():
|
||||
return
|
||||
@@ -71,55 +51,63 @@ func (*DLHandler) HandleMessage(message *nsq.Message) error {
|
||||
}
|
||||
}()
|
||||
|
||||
messagelog.Debug("Downloading %q", data.Link)
|
||||
err = downloader.Download(data.Link)
|
||||
if err != nil {
|
||||
Error.Printf("Error downloading %s: %v", data.Link, err)
|
||||
NotifyDiscordErrorless(fmt.Sprintf("Error downloading %s: %v", data.Link, err))
|
||||
messagelog.Error("Error downloading %s: %v", data.Link, err)
|
||||
return err
|
||||
}
|
||||
|
||||
messagelog.Info("Downloaded %q", data.Link)
|
||||
message.Finish()
|
||||
NotifyDiscordErrorless(fmt.Sprintf("Downloaded %s", data.Link))
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
logger.InitFlag()
|
||||
// err := downloader.Download("https://www.youtube.com/watch?v=SiKjprtiPaw")
|
||||
// if err != nil {
|
||||
// Error.Printf("Error downloading: %v", err)
|
||||
// }
|
||||
// return
|
||||
|
||||
logger.Info("Starting downloader")
|
||||
|
||||
config := nsq.NewConfig()
|
||||
config.MaxAttempts = 5
|
||||
config.MaxInFlight = downloaders.DOWNLOAD_WORKERS
|
||||
config.MsgTimeout = 10 * time.Second
|
||||
|
||||
logger.Info("Creating consumer")
|
||||
consumer, err := nsq.NewConsumer("ytdqueue", "dl", config)
|
||||
if err != nil {
|
||||
Error.Printf("Error creating consumer: %v", err)
|
||||
logger.Error("Error creating consumer: %v", err)
|
||||
return
|
||||
}
|
||||
logger.Info("Creating handlers")
|
||||
for i := 0; i < downloaders.DOWNLOAD_WORKERS; i++ {
|
||||
consumer.AddHandler(&DLHandler{})
|
||||
}
|
||||
|
||||
url := "192.168.1.123:41505"
|
||||
log.Printf("Connecting to nsq at %s", url)
|
||||
logger.Info("Connecting to nsq at %s", url)
|
||||
err = consumer.ConnectToNSQD(url)
|
||||
if err != nil {
|
||||
Error.Printf("Error connecting to nsq: %v", err)
|
||||
logger.Error("Error connecting to nsq: %v", err)
|
||||
return
|
||||
}
|
||||
log.Printf("Connected to nsq at %s", url)
|
||||
logger.Info("Connected to nsq at %s", url)
|
||||
|
||||
sigChan := make(chan os.Signal, 1)
|
||||
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
logger.Info("Waiting for signal to terminate")
|
||||
<-sigChan
|
||||
log.Println("Received signal to terminate. Initiating graceful shutdown...")
|
||||
logger.Info("Received signal to terminate. Initiating graceful shutdown...")
|
||||
|
||||
consumer.Stop()
|
||||
<-consumer.StopChan
|
||||
|
||||
log.Println("Graceful shutdown completed.")
|
||||
logger.Info("Graceful shutdown completed.")
|
||||
}
|
||||
|
9
downloader/nssm.sh
Normal file
9
downloader/nssm.sh
Normal file
@@ -0,0 +1,9 @@
|
||||
nssm install YoutubeDownloader 'C:\Users\Administrator\Seafile\Projects-Go\GoProjects\youtube-downloader\downloader\ytdl.exe'
|
||||
nssm set YoutubeDownloader AppDirectory 'C:\Users\Administrator\Seafile\Projects-Go\GoProjects\youtube-downloader\downloader'
|
||||
nssm set YoutubeDownloader AppExit Default Restart
|
||||
nssm set YoutubeDownloader AppEnvironmentExtra :PATH='C:\Users\Administrator\scoop\shims'
|
||||
nssm set YoutubeDownloader AppEnvironmentExtra +YTDL_DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/1360983696366112980/NEYWb9mc_E5-x3uCKoRkNBX-G3pyXH3YcXIf7YOZibdsGP10C-u0N32LQKuf5Hfu-hi7
|
||||
nssm set YoutubeDownloader DisplayName YoutubeDownloader
|
||||
nssm set YoutubeDownloader ObjectName LocalSystem
|
||||
nssm set YoutubeDownloader Start SERVICE_AUTO_START
|
||||
nssm set YoutubeDownloader Type SERVICE_WIN32_OWN_PROCESS
|
@@ -1,89 +0,0 @@
|
||||
package main
|
||||
|
||||
// import (
|
||||
// "bytes"
|
||||
// "encoding/json"
|
||||
// "log"
|
||||
// "net/http"
|
||||
|
||||
// "github.com/r3labs/sse"
|
||||
// )
|
||||
|
||||
// type RealtimeListener struct {
|
||||
// Url string
|
||||
// Collections []string
|
||||
// Create chan PBEvent
|
||||
// Update chan PBEvent
|
||||
// Delete chan PBEvent
|
||||
// client *sse.Client
|
||||
// }
|
||||
|
||||
// type Subscription struct {
|
||||
// ClientId string `json:"clientId"`
|
||||
// Subscriptions []string `json:"subscriptions"`
|
||||
// }
|
||||
|
||||
// func (listener RealtimeListener) handlePbEvent(msg *sse.Event) {
|
||||
// pbEvent := new(PBEvent)
|
||||
// err := json.Unmarshal(msg.Data, &pbEvent)
|
||||
// if err != nil {
|
||||
// log.Printf("Error unmarshalling event: %v\n", err)
|
||||
// return
|
||||
// }
|
||||
// log.Printf("Received event: %++v", pbEvent)
|
||||
|
||||
// if pbEvent.ClientId != "" {
|
||||
// listener.doSubscribe(pbEvent.ClientId)
|
||||
// }
|
||||
|
||||
// if pbEvent.Action != "" {
|
||||
// go listener.shipEvent(*pbEvent)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func (listener RealtimeListener) shipEvent(event PBEvent) {
|
||||
// switch event.Action {
|
||||
// case "create":
|
||||
// listener.Create <- event
|
||||
// case "update":
|
||||
// listener.Update <- event
|
||||
// case "delete":
|
||||
// listener.Delete <- event
|
||||
// default:
|
||||
// log.Printf("Unknown action: %v\n", event.Action)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func (listener RealtimeListener) doSubscribe(clientId string) {
|
||||
// subscription := Subscription{
|
||||
// ClientId: clientId,
|
||||
// Subscriptions: listener.Collections,
|
||||
// }
|
||||
// log.Printf("Subscribing client: %v to %++v", clientId, subscription)
|
||||
|
||||
// body, err := json.Marshal(subscription)
|
||||
// if err != nil {
|
||||
// log.Printf("Error marshalling subscription body: %v\n", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// resp, err := http.Post(POCKETBASE_REALTIME, "application/json", bytes.NewBuffer(body))
|
||||
// if err != nil {
|
||||
// log.Printf("Error posting subscription: %v\n", err)
|
||||
// return
|
||||
// }
|
||||
// defer resp.Body.Close()
|
||||
|
||||
// if resp.StatusCode != http.StatusNoContent {
|
||||
// log.Printf("Subscription request failed with status: %v\n", resp.Status)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func (listener *RealtimeListener) initialize() {
|
||||
// listener.Update = make(chan PBEvent, 32)
|
||||
// listener.Create = make(chan PBEvent, 32)
|
||||
// listener.Delete = make(chan PBEvent, 32)
|
||||
// log.Print("Initialized")
|
||||
// listener.client = sse.NewClient(listener.Url)
|
||||
// go listener.client.Subscribe("", listener.handlePbEvent)
|
||||
// }
|
1
downloader/stop.sh
Normal file
1
downloader/stop.sh
Normal file
@@ -0,0 +1 @@
|
||||
nssm stop YoutubeDownloader
|
@@ -1,143 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
const TIMEOUT = 6
|
||||
const IDLE_TIMEOUT = TIMEOUT * time.Second
|
||||
const PING_INTERVAL = (TIMEOUT / 2) * time.Second
|
||||
|
||||
type WSConnection struct {
|
||||
alive bool
|
||||
url string
|
||||
conn *websocket.Conn
|
||||
errChan chan error
|
||||
writeLock sync.Mutex
|
||||
ReadChan chan string
|
||||
WriteChan chan string
|
||||
Dead chan error
|
||||
}
|
||||
|
||||
func (ws *WSConnection) messageReader() {
|
||||
log.Printf("Starting reader")
|
||||
for {
|
||||
if !ws.alive {
|
||||
break
|
||||
}
|
||||
|
||||
_, message, err := ws.conn.ReadMessage()
|
||||
ws.conn.SetReadDeadline(time.Now().Add(IDLE_TIMEOUT))
|
||||
if err != nil {
|
||||
ws.errChan <- err
|
||||
break
|
||||
}
|
||||
|
||||
log.Printf("Received: %s, %d in output channel", message, len(ws.ReadChan))
|
||||
ws.ReadChan <- string(message)
|
||||
}
|
||||
log.Printf("Reader done")
|
||||
}
|
||||
|
||||
func (ws *WSConnection) messageSender() {
|
||||
log.Printf("Starting sender")
|
||||
for {
|
||||
msg, ok := <-ws.WriteChan
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
ws.doSend(msg)
|
||||
}
|
||||
log.Printf("Sender done")
|
||||
}
|
||||
|
||||
func (ws *WSConnection) doSend(msg string) {
|
||||
ws.writeLock.Lock()
|
||||
defer ws.writeLock.Unlock()
|
||||
|
||||
ws.conn.SetWriteDeadline(time.Now().Add(IDLE_TIMEOUT))
|
||||
log.Printf("Sending: %s, %d in input channel", msg, len(ws.WriteChan))
|
||||
err := ws.conn.WriteMessage(websocket.TextMessage, []byte(msg))
|
||||
if err != nil {
|
||||
log.Printf("Error during message writing: %v", err)
|
||||
ws.errChan <- err
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (ws *WSConnection) pinger() {
|
||||
log.Printf("Starting pinger, sleeping for %v", PING_INTERVAL)
|
||||
for {
|
||||
if !ws.alive {
|
||||
break
|
||||
}
|
||||
ws.doPing()
|
||||
time.Sleep(PING_INTERVAL)
|
||||
}
|
||||
log.Printf("Pinger done")
|
||||
}
|
||||
|
||||
func (ws *WSConnection) doPing() {
|
||||
ws.writeLock.Lock()
|
||||
defer ws.writeLock.Unlock()
|
||||
|
||||
// log.Printf("Ping")
|
||||
err := ws.conn.WriteMessage(websocket.PingMessage, nil)
|
||||
if err != nil {
|
||||
log.Println("Error during ping:", err)
|
||||
ws.errChan <- err
|
||||
return
|
||||
}
|
||||
ws.conn.SetWriteDeadline(time.Now().Add(IDLE_TIMEOUT))
|
||||
// log.Printf("Ping OK")
|
||||
}
|
||||
|
||||
func (ws *WSConnection) handleError() {
|
||||
for {
|
||||
err := <-ws.errChan
|
||||
log.Printf("Client error: %+v", err)
|
||||
ws.alive = false
|
||||
ws.conn.Close()
|
||||
close(ws.ReadChan)
|
||||
close(ws.WriteChan)
|
||||
close(ws.errChan)
|
||||
ws.Dead <- err
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (ws *WSConnection) Open() {
|
||||
log.Printf("Connecting to %s", ws.url)
|
||||
ws.Dead = make(chan error, 1)
|
||||
|
||||
conn, _, err := websocket.DefaultDialer.Dial(ws.url, nil)
|
||||
if err != nil {
|
||||
log.Println("Error during connection:", err)
|
||||
ws.Dead <- err
|
||||
return
|
||||
}
|
||||
log.Printf("Connected")
|
||||
ws.conn = conn
|
||||
ws.alive = true
|
||||
|
||||
ws.errChan = make(chan error, 1)
|
||||
ws.ReadChan = make(chan string, 128)
|
||||
ws.WriteChan = make(chan string, 128)
|
||||
|
||||
ws.conn.SetReadDeadline(time.Now().Add(IDLE_TIMEOUT))
|
||||
ws.conn.SetWriteDeadline(time.Now().Add(IDLE_TIMEOUT))
|
||||
ws.conn.SetPongHandler(func(string) error {
|
||||
// log.Println("Pong")
|
||||
ws.conn.SetReadDeadline(time.Now().Add(IDLE_TIMEOUT))
|
||||
return nil
|
||||
})
|
||||
|
||||
go ws.handleError()
|
||||
go ws.messageReader()
|
||||
go ws.messageSender()
|
||||
go ws.pinger()
|
||||
}
|
Reference in New Issue
Block a user