Compare commits
	
		
			42 Commits
		
	
	
		
			master
			...
			0002b08256
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 0002b08256 | |||
| ccefc21f53 | |||
| 8f45686dfc | |||
| 92ea0b43d0 | |||
| eb4f715ce3 | |||
| 4601a0fc60 | |||
| d420f78ab8 | |||
| 014e99751e | |||
| 91106bd391 | |||
| 3a74d63963 | |||
| 586c49558e | |||
| 00ed4e9fc1 | |||
| c859499676 | |||
| 7adc1e2f8c | |||
| 0c1a643d93 | |||
| ad4aac1061 | |||
| 2c6dbc287c | |||
| 97d509248c | |||
| ccaa16a68f | |||
| a8cf8cbb8a | |||
| 20e5594f60 | |||
| 83f7676b2e | |||
| f639545e9b | |||
| 18d7177099 | |||
| 07c20f4582 | |||
| 9b38ea7068 | |||
| 8ab4b4c280 | |||
| 0ad8722bf9 | |||
| d8c4c343f4 | |||
| 52fdcc64ef | |||
| fa0f1cb48c | |||
| 63899ac4bd | |||
| f5c072360b | |||
| 7c02cbf0e4 | |||
| 9b41f9114c | |||
| 60dc43fd9b | |||
| 584084c1bc | |||
| ed8eaf67a2 | |||
| 268351f31e | |||
| 43efe20d8c | |||
| 8d55bcb5ee | |||
| 48179c3a67 | 
							
								
								
									
										9
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -3,3 +3,12 @@ main.exe
 | 
				
			|||||||
logs.log
 | 
					logs.log
 | 
				
			||||||
ws-server/deploy.tar
 | 
					ws-server/deploy.tar
 | 
				
			||||||
downloader/main.log
 | 
					downloader/main.log
 | 
				
			||||||
 | 
					downloader/vendor/golang.org
 | 
				
			||||||
 | 
					downloader/vendor/github.com/*
 | 
				
			||||||
 | 
					!downloader/vendor/github.com/kkdai
 | 
				
			||||||
 | 
					downloader/vendor/modules.txt
 | 
				
			||||||
 | 
					downloader/ytdl.exe
 | 
				
			||||||
 | 
					downloader/ytdl.log
 | 
				
			||||||
 | 
					*.log
 | 
				
			||||||
 | 
					*.xml
 | 
				
			||||||
 | 
					*.exe
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								dl/dl.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								dl/dl.go
									
									
									
									
									
								
							@@ -11,7 +11,7 @@ import (
 | 
				
			|||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const URL = `http://localhost:5000/download`
 | 
					const URL = `https://nsq.site.quack-lab.dev/pub?topic=ytdqueue`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Item struct {
 | 
					type Item struct {
 | 
				
			||||||
	Link string `json:"link"`
 | 
						Link string `json:"link"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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,3 +1,3 @@
 | 
				
			|||||||
nssm stop YoutubeDownloader && \
 | 
					nssm stop YoutubeDownloader && \
 | 
				
			||||||
go build main && \
 | 
					go build . && \
 | 
				
			||||||
nssm start YoutubeDownloader
 | 
					nssm start YoutubeDownloader
 | 
				
			||||||
@@ -1,71 +0,0 @@
 | 
				
			|||||||
package main
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"context"
 | 
					 | 
				
			||||||
	"log"
 | 
					 | 
				
			||||||
	"sync"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/gen2brain/beeep"
 | 
					 | 
				
			||||||
	"github.com/lrstanley/go-ytdlp"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const OUTPUT_DIR = "C:/Users/Administrator/ytdlpVideos"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type DownloadWorker struct {
 | 
					 | 
				
			||||||
	id int
 | 
					 | 
				
			||||||
	input chan *DownloadTask
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var ongoingDownloads = make(map[string]struct{})
 | 
					 | 
				
			||||||
var ongoingDownloadsMutex = &sync.Mutex{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var dl = ytdlp.New().
 | 
					 | 
				
			||||||
	// FormatSort("bestvideo[ext=mp4]+bestaudio[ext=m4a]").
 | 
					 | 
				
			||||||
	FormatSort("res,ext:mp4:m4a").
 | 
					 | 
				
			||||||
	Output("C:/Users/Administrator/ytdlpVideos/%(uploader)s/%(title)s.%(ext)s").
 | 
					 | 
				
			||||||
	LimitRate("10M").
 | 
					 | 
				
			||||||
	// HTTPChunkSize("20M").
 | 
					 | 
				
			||||||
	MarkWatched().
 | 
					 | 
				
			||||||
	SponsorblockMark("all").
 | 
					 | 
				
			||||||
	RecodeVideo("mp4").
 | 
					 | 
				
			||||||
	ConcurrentFragments(6)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (w *DownloadWorker) Run() {
 | 
					 | 
				
			||||||
	for {
 | 
					 | 
				
			||||||
		task, ok := <-w.input
 | 
					 | 
				
			||||||
		if !ok {
 | 
					 | 
				
			||||||
			log.Printf("DownloadWorker %d: input channel closed, exiting", w.id)
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		_, ongoing := ongoingDownloads[task.Url]
 | 
					 | 
				
			||||||
		if ongoing {
 | 
					 | 
				
			||||||
			log.Printf("DownloadWorker %d: Download %s is already ongoing", w.id, task.Url)
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		ongoingDownloadsMutex.Lock()
 | 
					 | 
				
			||||||
		ongoingDownloads[task.Url] = struct{}{}
 | 
					 | 
				
			||||||
		ongoingDownloadsMutex.Unlock()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		log.Printf("DownloadWorker %d: Downloading %s", w.id, task.Url)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			log.Printf("Failed beeping with %+v", err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		err = beeep.Alert("Download Started", task.Url, "assets/information.png")
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			log.Printf("Failed alerting with %+v", err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
		_, err = dl.Run(context.TODO(), task.Url)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			log.Printf("DownloadWorker %d: Failed downloading %s with %+v", w.id, task.Url, err)
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
		log.Printf("DownloadWorker %d: Downloaded %s", w.id, task.Url)
 | 
					 | 
				
			||||||
		ongoingDownloadsMutex.Lock()
 | 
					 | 
				
			||||||
		delete(ongoingDownloads, task.Url)
 | 
					 | 
				
			||||||
		ongoingDownloadsMutex.Unlock()
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										5
									
								
								downloader/downloaders/downloader.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								downloader/downloaders/downloader.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					package downloaders
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Downloader interface {
 | 
				
			||||||
 | 
						Download(url string) error
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										93
									
								
								downloader/downloaders/kidai.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								downloader/downloaders/kidai.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,93 @@
 | 
				
			|||||||
 | 
					package downloaders
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
 | 
						"regexp"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/gen2brain/beeep"
 | 
				
			||||||
 | 
						"github.com/kkdai/youtube/v2"
 | 
				
			||||||
 | 
						ytd "github.com/kkdai/youtube/v2/downloader"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type KidaiDownloader struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *KidaiDownloader) Download(url string) error {
 | 
				
			||||||
 | 
						_, ongoing := ongoingDownloads[url]
 | 
				
			||||||
 | 
						if ongoing {
 | 
				
			||||||
 | 
							// return fmt.Errorf("Download %s is already ongoing", url)
 | 
				
			||||||
 | 
							log.Printf("Download %s is already ongoing", url)
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ongoingDownloadsMutex.Lock()
 | 
				
			||||||
 | 
						ongoingDownloads[url] = struct{}{}
 | 
				
			||||||
 | 
						ongoingDownloadsMutex.Unlock()
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							ongoingDownloadsMutex.Lock()
 | 
				
			||||||
 | 
							delete(ongoingDownloads, url)
 | 
				
			||||||
 | 
							ongoingDownloadsMutex.Unlock()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Printf("Kidai downloading %s", url)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						client := youtube.Client{}
 | 
				
			||||||
 | 
						video, err := client.GetVideo(url)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("failed downloading %s with %+v", url, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// $ go run . download -m mp4 -q hd https://www.youtube.com/watch?v=D9trBXaXCgA
 | 
				
			||||||
 | 
						// This works fine, now I have to figure out how to plug -m and -q into this shit below
 | 
				
			||||||
 | 
						downloader := ytd.Downloader{
 | 
				
			||||||
 | 
							OutputDir: OUTPUT_DIR,
 | 
				
			||||||
 | 
							Client:    client,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						videoTitle := Sanitize(video.Title)
 | 
				
			||||||
 | 
						videoAuthor := Sanitize(video.Author)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						videoFileRoot := filepath.Join(OUTPUT_DIR, videoAuthor)
 | 
				
			||||||
 | 
						err = os.MkdirAll(videoFileRoot, 0755)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("failed creating directory %s with %+v", videoFileRoot, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fullVideoPath := filepath.Join(OUTPUT_DIR, videoAuthor, videoTitle+".mp4")
 | 
				
			||||||
 | 
						videoFileHandle, err := os.Open(fullVideoPath)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							videoFileHandle.Close()
 | 
				
			||||||
 | 
							log.Printf("File %s already exists, skipping download", fullVideoPath)
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						videoFile := filepath.Join(videoAuthor, videoTitle+".mp4")
 | 
				
			||||||
 | 
						err = downloader.DownloadComposite(context.Background(), videoFile, video, "hd", "mp4", "")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("failed downloading %s with %+v", url, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Printf("Downloaded %s", url)
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var re = regexp.MustCompile(`[#!$%&/()";:?;,|*]`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Sanitize(s string) string {
 | 
				
			||||||
 | 
						s = strings.ReplaceAll(s, "&", "and")
 | 
				
			||||||
 | 
						s = re.ReplaceAllString(s, "")
 | 
				
			||||||
 | 
						return s
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										11
									
								
								downloader/downloaders/utils.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								downloader/downloaders/utils.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					package downloaders
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "sync"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const OUTPUT_DIR = "C:/Users/Administrator/ytdlpVideos"
 | 
				
			||||||
 | 
					//const OUTPUT_DIR = "."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var ongoingDownloads = make(map[string]struct{})
 | 
				
			||||||
 | 
					var ongoingDownloadsMutex = &sync.Mutex{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const DOWNLOAD_WORKERS = 4
 | 
				
			||||||
							
								
								
									
										65
									
								
								downloader/downloaders/ytdlp-lib.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								downloader/downloaders/ytdlp-lib.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,65 @@
 | 
				
			|||||||
 | 
					package downloaders
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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").
 | 
				
			||||||
 | 
						Output("C:/Users/Administrator/ytdlpVideos/%(uploader)s/%(title)s.%(ext)s").
 | 
				
			||||||
 | 
						LimitRate(fmt.Sprintf("%dM", 150/DOWNLOAD_WORKERS)).
 | 
				
			||||||
 | 
						// HTTPChunkSize("20M").
 | 
				
			||||||
 | 
						ExtractorArgs("youtube:player_client=android").
 | 
				
			||||||
 | 
						MarkWatched().
 | 
				
			||||||
 | 
						SponsorblockMark("all").
 | 
				
			||||||
 | 
						RecodeVideo("mp4").
 | 
				
			||||||
 | 
						ConcurrentFragments(6)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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)
 | 
				
			||||||
 | 
							downloadlogger.Info("Download is already ongoing")
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ongoingDownloadsMutex.Lock()
 | 
				
			||||||
 | 
						ongoingDownloads[url] = struct{}{}
 | 
				
			||||||
 | 
						ongoingDownloadsMutex.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						downloadlogger.Info("YTDLPLib downloading")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 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)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						downloadlogger.Info("Downloaded")
 | 
				
			||||||
 | 
						ongoingDownloadsMutex.Lock()
 | 
				
			||||||
 | 
						delete(ongoingDownloads, url)
 | 
				
			||||||
 | 
						ongoingDownloadsMutex.Unlock()
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										51
									
								
								downloader/downloaders/ytdlp-raw.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								downloader/downloaders/ytdlp-raw.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
				
			|||||||
 | 
					package downloaders
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"os/exec"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/gen2brain/beeep"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type YTDLPRawDownloader struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *YTDLPRawDownloader) Download(url string) error {
 | 
				
			||||||
 | 
						_, ongoing := ongoingDownloads[url]
 | 
				
			||||||
 | 
						if ongoing {
 | 
				
			||||||
 | 
							// return fmt.Errorf("Download %s is already ongoing", url)
 | 
				
			||||||
 | 
							log.Printf("Download %s is already ongoing", url)
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ongoingDownloadsMutex.Lock()
 | 
				
			||||||
 | 
						ongoingDownloads[url] = struct{}{}
 | 
				
			||||||
 | 
						ongoingDownloadsMutex.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Printf("YTDLPRaw downloading %s", url)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cmd := exec.Command("yt-dlp", "-o", "C:/Users/Administrator/ytdlpVideos/%(title)s.%(ext)s", "-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]", "-N", "12", "--sponsorblock-mark", "all", url)
 | 
				
			||||||
 | 
						cmd.Stdout = os.Stdout
 | 
				
			||||||
 | 
						cmd.Stderr = os.Stderr
 | 
				
			||||||
 | 
						err := cmd.Run()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("failed downloading %s with %+v", url, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Printf("Downloaded %s", url)
 | 
				
			||||||
 | 
						ongoingDownloadsMutex.Lock()
 | 
				
			||||||
 | 
						delete(ongoingDownloads, url)
 | 
				
			||||||
 | 
						ongoingDownloadsMutex.Unlock()
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,20 +1,46 @@
 | 
				
			|||||||
module main
 | 
					module ytdl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
go 1.22.4
 | 
					go 1.24.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/ProtonMail/go-crypto v1.0.0 // indirect
 | 
						git.sr.ht/~jackmordaunt/go-toast v1.1.2 // indirect
 | 
				
			||||||
	github.com/cloudflare/circl v1.3.7 // indirect
 | 
						github.com/ProtonMail/go-crypto v1.3.0 // indirect
 | 
				
			||||||
	github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // 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/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/godbus/dbus/v5 v5.1.0 // indirect
 | 
						github.com/godbus/dbus/v5 v5.1.0 // indirect
 | 
				
			||||||
	github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // 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/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
 | 
				
			||||||
	golang.org/x/crypto v0.21.0 // indirect
 | 
						github.com/ulikunitz/xz v0.5.15 // indirect
 | 
				
			||||||
	golang.org/x/sys v0.18.0 // indirect
 | 
						github.com/vbauerster/mpb/v5 v5.4.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 (
 | 
					require (
 | 
				
			||||||
	github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4
 | 
						git.site.quack-lab.dev/dave/cylogger v1.4.0
 | 
				
			||||||
	github.com/gorilla/websocket v1.5.3
 | 
						github.com/gen2brain/beeep v0.11.1
 | 
				
			||||||
	github.com/lrstanley/go-ytdlp v0.0.0-20240616011628-f35a10876c99
 | 
						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,65 +1,116 @@
 | 
				
			|||||||
github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78=
 | 
					git.site.quack-lab.dev/dave/cylogger v1.4.0 h1:3Ca7V5JWvruARJd5S8xDFwW9LnZ9QInqkYLRdrEFvuY=
 | 
				
			||||||
github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
 | 
					git.site.quack-lab.dev/dave/cylogger v1.4.0/go.mod h1:wctgZplMvroA4X6p8f4B/LaCKtiBcT1Pp+L14kcS8jk=
 | 
				
			||||||
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
 | 
					git.sr.ht/~jackmordaunt/go-toast v1.1.2 h1:/yrfI55LRt1M7H1vkaw+NaH1+L1CDxrqDltwm5euVuE=
 | 
				
			||||||
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
 | 
					git.sr.ht/~jackmordaunt/go-toast v1.1.2/go.mod h1:jA4OqHKTQ4AFBdwrSnwnskUIIS3HYzlJSgdzCKqfavo=
 | 
				
			||||||
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
 | 
					github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
 | 
				
			||||||
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
 | 
					github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
 | 
				
			||||||
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4 h1:ygs9POGDQpQGLJPlq4+0LBUmMBNox1N4JSpw+OETcvI=
 | 
					github.com/ProtonMail/go-crypto v1.3.0 h1:ILq8+Sf5If5DCpHQp4PbZdS1J7HDFRXz/+xKBiRGFrw=
 | 
				
			||||||
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4=
 | 
					github.com/ProtonMail/go-crypto v1.3.0/go.mod h1:9whxjD8Rbs29b4XWbB8irEcE8KHMqaR2e7GWU1R+/PE=
 | 
				
			||||||
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=
 | 
					github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
 | 
				
			||||||
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10=
 | 
					github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
 | 
				
			||||||
 | 
					github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
 | 
				
			||||||
 | 
					github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
 | 
				
			||||||
 | 
					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/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.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/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
 | 
					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/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 | 
				
			||||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
 | 
					github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 | 
				
			||||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
 | 
					github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
 | 
				
			||||||
github.com/lrstanley/go-ytdlp v0.0.0-20240616011628-f35a10876c99 h1:ZAo7qJht9PqefOD7C0ZKQ8dEkpJeM955sYw0FtQnzvo=
 | 
					github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 | 
				
			||||||
github.com/lrstanley/go-ytdlp v0.0.0-20240616011628-f35a10876c99/go.mod h1:75ujbafjqiJugIGw4K6o52/p8C0m/kt+DrYwgClXYT4=
 | 
					github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
 | 
				
			||||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
 | 
					github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
 | 
				
			||||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
 | 
					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.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/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/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 h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
 | 
				
			||||||
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
 | 
					github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
 | 
				
			||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
 | 
					github.com/ulikunitz/xz v0.5.15 h1:9DNdB5s+SgV3bQ2ApL10xRc35ck0DuIX/isZvIk+ubY=
 | 
				
			||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 | 
					github.com/ulikunitz/xz v0.5.15/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
 | 
				
			||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 | 
					github.com/vbauerster/mpb/v5 v5.4.0 h1:n8JPunifvQvh6P1D1HAl2Ur9YcmKT1tpoUuiea5mlmg=
 | 
				
			||||||
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
 | 
					github.com/vbauerster/mpb/v5 v5.4.0/go.mod h1:fi4wVo7BVQ22QcvFObm+VwliQXlV1eBT8JDaKXR4JGI=
 | 
				
			||||||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
 | 
					golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
 | 
				
			||||||
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
 | 
					golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
 | 
				
			||||||
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
 | 
					golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U=
 | 
				
			||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
 | 
					golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI=
 | 
				
			||||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
 | 
					golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
 | 
				
			||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 | 
					golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
 | 
				
			||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
 | 
					golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
 | 
				
			||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
 | 
					golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
 | 
				
			||||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
 | 
					golang.org/x/sys v0.0.0-20201218084310-7d0127a74742/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
 | 
					golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
 | 
					golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
 | 
				
			||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
					golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
 | 
				
			||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
					golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
 | 
				
			||||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
					golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 | 
					golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
					golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
 | 
				
			||||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
				
			||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					mvdan.cc/gofumpt v0.9.1 h1:p5YT2NfFWsYyTieYgwcQ8aKV3xRvFH4uuN/zB2gBbMQ=
 | 
				
			||||||
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
 | 
					mvdan.cc/gofumpt v0.9.1/go.mod h1:3xYtNemnKiXaTh6R4VtlqDATFwBbdXI8lJvH/4qk7mw=
 | 
				
			||||||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
					 | 
				
			||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 | 
					 | 
				
			||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 | 
					 | 
				
			||||||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
 | 
					 | 
				
			||||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
 | 
					 | 
				
			||||||
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
 | 
					 | 
				
			||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 | 
					 | 
				
			||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 | 
					 | 
				
			||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
 | 
					 | 
				
			||||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
 | 
					 | 
				
			||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
 | 
					 | 
				
			||||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
 | 
					 | 
				
			||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 | 
					 | 
				
			||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 | 
					 | 
				
			||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
 | 
					 | 
				
			||||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
 | 
					 | 
				
			||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,70 +1,113 @@
 | 
				
			|||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"io"
 | 
						"flag"
 | 
				
			||||||
	"log"
 | 
						"fmt"
 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
 | 
						"os/signal"
 | 
				
			||||||
 | 
						"syscall"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
						"ytdl/downloaders"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						logger "git.site.quack-lab.dev/dave/cylogger"
 | 
				
			||||||
 | 
						"github.com/nsqio/go-nsq"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					// var downloader downloaders.Downloader = &downloaders.YTDLPRawDownloader{}
 | 
				
			||||||
	log.SetFlags(log.Lmicroseconds | log.Lshortfile)
 | 
					// var downloader downloaders.Downloader = &downloaders.KidaiDownloader{}
 | 
				
			||||||
	logFile, err := os.Create("main.log")
 | 
					var downloader downloaders.Downloader = &downloaders.YTDLPLibDownloader{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type DLHandler struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (*DLHandler) HandleMessage(message *nsq.Message) error {
 | 
				
			||||||
 | 
						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 {
 | 
						if err != nil {
 | 
				
			||||||
		log.Printf("Error creating log file: %v", err)
 | 
							messagelog.Error("Error unmarshalling message: %v", err)
 | 
				
			||||||
		os.Exit(1)
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	logger := io.MultiWriter(os.Stdout, logFile)
 | 
					 | 
				
			||||||
	log.SetOutput(logger)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
const DOWNLOAD_WORKERS = 10
 | 
						ctx, cancel := context.WithCancel(context.Background())
 | 
				
			||||||
 | 
						defer cancel()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var downloadQueue = make(chan *DownloadTask, 100)
 | 
						go func() {
 | 
				
			||||||
 | 
							messagelog.Debug("Starting touch ticker")
 | 
				
			||||||
 | 
							ticker := time.NewTicker(1 * time.Second)
 | 
				
			||||||
 | 
							defer ticker.Stop()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func enableCORS(next http.Handler) http.Handler {
 | 
							for {
 | 
				
			||||||
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 | 
								select {
 | 
				
			||||||
		w.Header().Set("Access-Control-Allow-Origin", "*")
 | 
								case <-ticker.C:
 | 
				
			||||||
		w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
 | 
									messagelog.Debug("Touching message")
 | 
				
			||||||
		w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
 | 
									message.Touch()
 | 
				
			||||||
 | 
								case <-ctx.Done():
 | 
				
			||||||
		if r.Method == http.MethodOptions {
 | 
									return
 | 
				
			||||||
			w.WriteHeader(http.StatusOK)
 | 
								}
 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		next.ServeHTTP(w, r)
 | 
						}()
 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
func handleDownload(w http.ResponseWriter, r *http.Request) {
 | 
						messagelog.Debug("Downloading %q", data.Link)
 | 
				
			||||||
	if r.Method != http.MethodPost {
 | 
						err = downloader.Download(data.Link)
 | 
				
			||||||
		http.Error(w, "Invalid request method", http.StatusMethodNotAllowed)
 | 
						if err != nil {
 | 
				
			||||||
		return
 | 
							messagelog.Error("Error downloading %s: %v", data.Link, err)
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var req DownloadRequest
 | 
						messagelog.Info("Downloaded %q", data.Link)
 | 
				
			||||||
	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
 | 
						message.Finish()
 | 
				
			||||||
		log.Printf("Error parsing JSON: %v", err)
 | 
						return nil
 | 
				
			||||||
		http.Error(w, "Error parsing JSON", http.StatusBadRequest)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	downloadQueue <- &DownloadTask{Url: req.Link}
 | 
					 | 
				
			||||||
	w.WriteHeader(http.StatusOK)
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
	for i := 0; i < DOWNLOAD_WORKERS; i++ {
 | 
						flag.Parse()
 | 
				
			||||||
		worker := &DownloadWorker{id: i, input: downloadQueue}
 | 
						logger.InitFlag()
 | 
				
			||||||
		go worker.Run()
 | 
						//	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 {
 | 
				
			||||||
 | 
							logger.Error("Error creating consumer: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						logger.Info("Creating handlers")
 | 
				
			||||||
 | 
						for i := 0; i < downloaders.DOWNLOAD_WORKERS; i++ {
 | 
				
			||||||
 | 
							consumer.AddHandler(&DLHandler{})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mux := http.NewServeMux()
 | 
						url := "192.168.1.123:41505"
 | 
				
			||||||
	mux.Handle("/download", enableCORS(http.HandlerFunc(handleDownload)))
 | 
						logger.Info("Connecting to nsq at %s", url)
 | 
				
			||||||
	log.Println("Server starting on :5000")
 | 
						err = consumer.ConnectToNSQD(url)
 | 
				
			||||||
	err := http.ListenAndServe(":5000", mux)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Println("Error starting server:", err)
 | 
							logger.Error("Error connecting to nsq: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						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
 | 
				
			||||||
 | 
						logger.Info("Received signal to terminate. Initiating graceful shutdown...")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						consumer.Stop()
 | 
				
			||||||
 | 
						<-consumer.StopChan
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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,8 +1,5 @@
 | 
				
			|||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type DownloadTask struct {
 | 
					 | 
				
			||||||
	Url string
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
type DownloadRequest struct {
 | 
					type DownloadRequest struct {
 | 
				
			||||||
	Link string `json:"link"`
 | 
						Link string `json:"link"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -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()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										16
									
								
								hotkey.js
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								hotkey.js
									
									
									
									
									
								
							@@ -1,20 +1,26 @@
 | 
				
			|||||||
nodes = document.querySelectorAll(":hover");
 | 
					nodes = document.querySelectorAll(":hover");
 | 
				
			||||||
i = 1;
 | 
					i = 1;
 | 
				
			||||||
console.log(nodes);
 | 
					console.log(nodes);
 | 
				
			||||||
titleNode = nodes[nodes.length - i];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
selector = "a#video-title-link";
 | 
					selectors = ["a#video-title-link", "a#video-title"];
 | 
				
			||||||
invidious = false;
 | 
					invidious = false;
 | 
				
			||||||
if (window.location.href.includes("invidious.site")) {
 | 
					if (window.location.href.includes("invidious.site")) {
 | 
				
			||||||
	selector = "a";
 | 
						selector = "a";
 | 
				
			||||||
	invidious = true;
 | 
						invidious = true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
while (titleNode && !titleNode.matches(selector)) {
 | 
					titleNode = nodes[nodes.length - i];
 | 
				
			||||||
 | 
					outer:
 | 
				
			||||||
 | 
					while (titleNode) {
 | 
				
			||||||
 | 
						for (let selector of selectors) {
 | 
				
			||||||
 | 
							if (titleNode.matches(selector)) {
 | 
				
			||||||
 | 
								break outer;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	titleNode = titleNode.parentElement;
 | 
						titleNode = titleNode.parentElement;
 | 
				
			||||||
	console.log(titleNode);
 | 
						console.log(titleNode);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
if (!(titleNode && titleNode.matches(selector))) {
 | 
					if (!titleNode) {
 | 
				
			||||||
	console.error("No video element found.");
 | 
						console.error("No video element found.");
 | 
				
			||||||
} else {
 | 
					} else {
 | 
				
			||||||
	link = titleNode.href;
 | 
						link = titleNode.href;
 | 
				
			||||||
@@ -22,7 +28,7 @@ if (!(titleNode && titleNode.matches(selector))) {
 | 
				
			|||||||
		link = window.location.origin + link;
 | 
							link = window.location.origin + link;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	console.log(link);
 | 
						console.log(link);
 | 
				
			||||||
	fetch("http://localhost:5000/download", {
 | 
						fetch("https://nsq.site.quack-lab.dev/pub?topic=ytdqueue", {
 | 
				
			||||||
		method: "POST",
 | 
							method: "POST",
 | 
				
			||||||
		headers: {
 | 
							headers: {
 | 
				
			||||||
			"Content-Type": "application/json",
 | 
								"Content-Type": "application/json",
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								youtubeWatcher/deploy.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								youtubeWatcher/deploy.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					nssm stop YoutubeWatcher && \
 | 
				
			||||||
 | 
					go build . && \
 | 
				
			||||||
 | 
					nssm start YoutubeWatcher
 | 
				
			||||||
							
								
								
									
										3
									
								
								youtubeWatcher/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								youtubeWatcher/go.mod
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					module ywatcher
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					go 1.24.2
 | 
				
			||||||
							
								
								
									
										156
									
								
								youtubeWatcher/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										156
									
								
								youtubeWatcher/main.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,156 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/xml"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"regexp"
 | 
				
			||||||
 | 
						"sync"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type DownloadRequest struct {
 | 
				
			||||||
 | 
						Link string `json:"link"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					type RssWatcher struct {
 | 
				
			||||||
 | 
						Feed *RssFeed
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var videoRegex = regexp.MustCompile(`yt:video:(?<videoid>[^ ]+) (?:[^ ]+ ){2}(?<videotitle>.+?)https(?:[^ ]+ ){2}(?<date>[^ ]+)`)
 | 
				
			||||||
 | 
					var feeds []*RssFeed = []*RssFeed{
 | 
				
			||||||
 | 
						{Url: "https://www.youtube.com/feeds/videos.xml?channel_id=UCMwJJL5FJFuTRT55ksbQ4GQ", Id: "@AsmongoldClips"},
 | 
				
			||||||
 | 
						{Url: "https://www.youtube.com/feeds/videos.xml?channel_id=UC8nZUXCwCTffxthKLtOp6ng", Id: "@Splattercatgaming"},
 | 
				
			||||||
 | 
						{Url: "https://www.youtube.com/feeds/videos.xml?channel_id=UC2THf0jmDDeBujMzG1sD2-Q", Id: "@thesingleplayersquad"},
 | 
				
			||||||
 | 
						{Url: "https://www.youtube.com/feeds/videos.xml?channel_id=UCmtyQOKKmrMVaKuRXz02jbQ", Id: "@SebastianLague"},
 | 
				
			||||||
 | 
						{Url: "https://www.youtube.com/feeds/videos.xml?channel_id=UCywBfpGBYhsczNuyyh6Cf6w", Id: "@WorthABuyreviews"},
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (w *RssWatcher) Watch(videoUrls chan string) error {
 | 
				
			||||||
 | 
						ticker := time.NewTicker(1 * time.Minute)
 | 
				
			||||||
 | 
						defer ticker.Stop()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Printf("[%s]: Watcher started, checking every minute.", w.Feed.Id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						w.CheckFeed(videoUrls)
 | 
				
			||||||
 | 
						for {
 | 
				
			||||||
 | 
							select {
 | 
				
			||||||
 | 
							case <-ticker.C:
 | 
				
			||||||
 | 
								log.Printf("[%s]: Checking feed", w.Feed.Id)
 | 
				
			||||||
 | 
								err := w.CheckFeed(videoUrls)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return fmt.Errorf("watcher %s failed to check feed: %w", w.Feed.Id, err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								log.Printf("[%s]: Successfully checked feed", w.Feed.Id)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (w *RssWatcher) CheckFeed(videoUrls chan string) error {
 | 
				
			||||||
 | 
						log.Printf("Checking feed URL: %s", w.Feed.Url)
 | 
				
			||||||
 | 
						resp, err := http.Get(w.Feed.Url)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("[%s]: failed to create request: %w", w.Feed.Id, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer resp.Body.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Printf("Received response with status code: %d", resp.StatusCode)
 | 
				
			||||||
 | 
						body, err := io.ReadAll(resp.Body)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("[%s]: failed to read response body: %w", w.Feed.Id, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// os.WriteFile("cache.xml", body, 0644)
 | 
				
			||||||
 | 
						// body, err := os.ReadFile("cache.xml")
 | 
				
			||||||
 | 
						// if err != nil {
 | 
				
			||||||
 | 
						// 	return fmt.Errorf("[%s]: failed to read cache file: %w", w.Feed.Id, err)
 | 
				
			||||||
 | 
						// }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var feed Feed
 | 
				
			||||||
 | 
						err = xml.Unmarshal(body, &feed)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("[%s]: failed to unmarshal feed: %w", w.Feed.Id, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, entry := range feed.Entry {
 | 
				
			||||||
 | 
							uploaded, err := time.Parse(time.RFC3339, entry.Published)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return fmt.Errorf("[%s]: failed to parse published date: %w", w.Feed.Id, err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if uploaded.Before(w.Feed.LastSeen) {
 | 
				
			||||||
 | 
								log.Printf("[%s]: Skipping video titled %q because it was uploaded before %s", w.Feed.Id, entry.Title, w.Feed.LastSeen.Format(time.RFC3339))
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							log.Printf("[%s]: Found new video titled %q with url %q", w.Feed.Id, entry.Title, entry.Link.Href)
 | 
				
			||||||
 | 
							videoUrls <- entry.Link.Href
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						err = w.Feed.WriteLastSeen(time.Now())
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("[%s]: failed to write last seen: %w", w.Feed.Id, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						w.Feed.LastSeen = time.Now()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var Error *log.Logger
 | 
				
			||||||
 | 
					var Warning *log.Logger
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
						log.SetFlags(log.Lmicroseconds | log.Lshortfile)
 | 
				
			||||||
 | 
						logFile, err := os.Create("ywatcher.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)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func main() {
 | 
				
			||||||
 | 
						videoUrls := make(chan string, 12)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						wg := &sync.WaitGroup{}
 | 
				
			||||||
 | 
						for _, feed := range feeds {
 | 
				
			||||||
 | 
							wg.Add(1)
 | 
				
			||||||
 | 
							go func(feed *RssFeed) {
 | 
				
			||||||
 | 
								err := feed.UpdateLastSeen()
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									Error.Printf("failed to update lastseen for feed %s: %v", feed.Id, err)
 | 
				
			||||||
 | 
									panic(err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								defer wg.Done()
 | 
				
			||||||
 | 
								watcher := RssWatcher{
 | 
				
			||||||
 | 
									Feed: feed,
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								err = watcher.Watch(videoUrls)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									Error.Printf("watcher %s failed to watch feed: %v", feed.Id, err)
 | 
				
			||||||
 | 
									panic(err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}(feed)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						go func() {
 | 
				
			||||||
 | 
							for videoUrl := range videoUrls {
 | 
				
			||||||
 | 
								log.Printf("Got new video with url %q", videoUrl)
 | 
				
			||||||
 | 
								err := Download(videoUrl)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									Error.Printf("failed to download video: %v", err)
 | 
				
			||||||
 | 
									panic(err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						wg.Wait()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										50
									
								
								youtubeWatcher/nsqWriter.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								youtubeWatcher/nsqWriter.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,50 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const URL = `https://nsq.site.quack-lab.dev/pub?topic=ytdqueue`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Item struct {
 | 
				
			||||||
 | 
						Link string `json:"link"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Download(url string) error {
 | 
				
			||||||
 | 
						log.Printf("Starting download for URL: %s", url)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						req, err := http.NewRequestWithContext(context.Background(), "POST", URL, nil)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("error creating POST request: %++v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						req.Header.Set("Content-Type", "application/json")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						item := new(Item)
 | 
				
			||||||
 | 
						item.Link = url
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						body, err := json.Marshal(item)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("error marshalling subscription body: %++v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						req.Body = io.NopCloser(bytes.NewReader(body))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						client := http.Client{}
 | 
				
			||||||
 | 
						log.Printf("Sending POST request to %s", URL)
 | 
				
			||||||
 | 
						res, err := client.Do(req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("error sending POST request: %++v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer res.Body.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if res.StatusCode != http.StatusOK {
 | 
				
			||||||
 | 
							return fmt.Errorf("non-OK HTTP status: %d", res.StatusCode)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						log.Printf("Successfully enqueued %s", url)
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										97
									
								
								youtubeWatcher/rssfeed.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								youtubeWatcher/rssfeed.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,97 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"sync"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type RssFeed struct {
 | 
				
			||||||
 | 
						Url       string
 | 
				
			||||||
 | 
						Id        string
 | 
				
			||||||
 | 
						LastSeen  time.Time
 | 
				
			||||||
 | 
						fileMutex sync.Mutex
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (f *RssFeed) UpdateLastSeen() error {
 | 
				
			||||||
 | 
						log.Printf("[%s]: Updating last seen time", f.Id)
 | 
				
			||||||
 | 
						lastSeen, err := f.ReadLastSeen()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("failed to read lastseen file for feed %s: %w", f.Id, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						f.LastSeen = lastSeen
 | 
				
			||||||
 | 
						log.Printf("[%s]: Last seen time updated to: %s", f.Id, f.LastSeen)
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					func (f *RssFeed) ReadLastSeen() (time.Time, error) {
 | 
				
			||||||
 | 
						f.fileMutex.Lock()
 | 
				
			||||||
 | 
						defer f.fileMutex.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						lastSeen := time.Now()
 | 
				
			||||||
 | 
						log.Printf("[%s]: Attempting to open lastseen file...", f.Id)
 | 
				
			||||||
 | 
						lastSeenFile, err := os.Open("lastseen" + f.Id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							if os.IsNotExist(err) {
 | 
				
			||||||
 | 
								log.Printf("[%s]: lastseen file does not exist, creating a new one...", f.Id)
 | 
				
			||||||
 | 
								lastSeenFile, err = os.Create("lastseen" + f.Id)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return lastSeen, fmt.Errorf("failed to create lastseen file: %w", err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								log.Printf("[%s]: Writing current time to lastseen file...", f.Id)
 | 
				
			||||||
 | 
								lastSeenFile.Write([]byte(lastSeen.Format(time.RFC3339)))
 | 
				
			||||||
 | 
								lastSeenFile.Sync()
 | 
				
			||||||
 | 
								log.Printf("[%s]: Successfully created lastseen file with current time.", f.Id)
 | 
				
			||||||
 | 
								return lastSeen, nil
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								log.Printf("[%s]: Error opening lastseen file: %v", f.Id, err)
 | 
				
			||||||
 | 
								return lastSeen, fmt.Errorf("failed to read lastseen file: %w", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						log.Printf("[%s]: Reading contents of lastseen file...", f.Id)
 | 
				
			||||||
 | 
						lastSeenBytes, err := io.ReadAll(lastSeenFile)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Printf("[%s]: Error reading lastseen file: %v", f.Id, err)
 | 
				
			||||||
 | 
							return lastSeen, fmt.Errorf("failed to read lastseen file: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						log.Printf("[%s]: Parsing lastseen time...", f.Id)
 | 
				
			||||||
 | 
						lastSeen, err = time.Parse(time.RFC3339, string(lastSeenBytes))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Printf("[%s]: Error parsing lastseen file: %v", f.Id, err)
 | 
				
			||||||
 | 
							return lastSeen, fmt.Errorf("failed to parse lastseen file: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						lastSeenFile.Close()
 | 
				
			||||||
 | 
						log.Printf("[%s]: Last seen time read: %s", f.Id, lastSeen)
 | 
				
			||||||
 | 
						return lastSeen, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (f *RssFeed) WriteLastSeen(when time.Time) error {
 | 
				
			||||||
 | 
						f.fileMutex.Lock()
 | 
				
			||||||
 | 
						defer f.fileMutex.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Printf("[%s]: Attempting to create lastseen file...", f.Id)
 | 
				
			||||||
 | 
						lastSeenFile, err := os.Create("lastseen" + f.Id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Printf("[%s]: Error creating lastseen file: %v", f.Id, err)
 | 
				
			||||||
 | 
							return fmt.Errorf("failed to create lastseen file: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						log.Printf("[%s]: Successfully created lastseen file: lastseen%s", f.Id, f.Id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Printf("[%s]: Writing last seen time to file: %s", f.Id, when.Format(time.RFC3339))
 | 
				
			||||||
 | 
						_, err = lastSeenFile.Write([]byte(when.Format(time.RFC3339)))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Printf("[%s]: Error writing to lastseen file: %v", f.Id, err)
 | 
				
			||||||
 | 
							return fmt.Errorf("failed to write to lastseen file: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						log.Printf("[%s]: Successfully wrote last seen time to file.", f.Id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = lastSeenFile.Close()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Printf("[%s]: Error closing lastseen file: %v", f.Id, err)
 | 
				
			||||||
 | 
							return fmt.Errorf("failed to close lastseen file: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						log.Printf("[%s]: Lastseen file closed successfully.", f.Id)
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										86
									
								
								youtubeWatcher/rssfeedResType.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										86
									
								
								youtubeWatcher/rssfeedResType.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,86 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "encoding/xml"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Feed struct {
 | 
				
			||||||
 | 
						XMLName   xml.Name `xml:"feed"`
 | 
				
			||||||
 | 
						Text      string   `xml:",chardata"`
 | 
				
			||||||
 | 
						Yt        string   `xml:"yt,attr"`
 | 
				
			||||||
 | 
						Media     string   `xml:"media,attr"`
 | 
				
			||||||
 | 
						Xmlns     string   `xml:"xmlns,attr"`
 | 
				
			||||||
 | 
						Link      []Link   `xml:"link"`
 | 
				
			||||||
 | 
						ID        string   `xml:"id"`
 | 
				
			||||||
 | 
						ChannelId string   `xml:"channelId"`
 | 
				
			||||||
 | 
						Title     string   `xml:"title"`
 | 
				
			||||||
 | 
						Author    Author   `xml:"author"`
 | 
				
			||||||
 | 
						Published string   `xml:"published"`
 | 
				
			||||||
 | 
						Entry     []Entry  `xml:"entry"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Link struct {
 | 
				
			||||||
 | 
						Text string `xml:",chardata"`
 | 
				
			||||||
 | 
						Rel  string `xml:"rel,attr"`
 | 
				
			||||||
 | 
						Href string `xml:"href,attr"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Author struct {
 | 
				
			||||||
 | 
						Text string `xml:",chardata"`
 | 
				
			||||||
 | 
						Name string `xml:"name"`
 | 
				
			||||||
 | 
						URI  string `xml:"uri"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Entry struct {
 | 
				
			||||||
 | 
						Text      string `xml:",chardata"`
 | 
				
			||||||
 | 
						ID        string `xml:"id"`
 | 
				
			||||||
 | 
						VideoId   string `xml:"videoId"`
 | 
				
			||||||
 | 
						ChannelId string `xml:"channelId"`
 | 
				
			||||||
 | 
						Title     string `xml:"title"`
 | 
				
			||||||
 | 
						Link      Link   `xml:"link"`
 | 
				
			||||||
 | 
						Author    Author `xml:"author"`
 | 
				
			||||||
 | 
						Published string `xml:"published"`
 | 
				
			||||||
 | 
						Updated   string `xml:"updated"`
 | 
				
			||||||
 | 
						Group     Group  `xml:"group"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Group struct {
 | 
				
			||||||
 | 
						Text        string    `xml:",chardata"`
 | 
				
			||||||
 | 
						Title       string    `xml:"title"`
 | 
				
			||||||
 | 
						Content     Content   `xml:"content"`
 | 
				
			||||||
 | 
						Thumbnail   Thumbnail `xml:"thumbnail"`
 | 
				
			||||||
 | 
						Description string    `xml:"description"`
 | 
				
			||||||
 | 
						Community   Community `xml:"community"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Content struct {
 | 
				
			||||||
 | 
						Text   string `xml:",chardata"`
 | 
				
			||||||
 | 
						URL    string `xml:"url,attr"`
 | 
				
			||||||
 | 
						Type   string `xml:"type,attr"`
 | 
				
			||||||
 | 
						Width  string `xml:"width,attr"`
 | 
				
			||||||
 | 
						Height string `xml:"height,attr"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Thumbnail struct {
 | 
				
			||||||
 | 
						Text   string `xml:",chardata"`
 | 
				
			||||||
 | 
						URL    string `xml:"url,attr"`
 | 
				
			||||||
 | 
						Width  string `xml:"width,attr"`
 | 
				
			||||||
 | 
						Height string `xml:"height,attr"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Community struct {
 | 
				
			||||||
 | 
						Text       string     `xml:",chardata"`
 | 
				
			||||||
 | 
						StarRating StarRating `xml:"starRating"`
 | 
				
			||||||
 | 
						Statistics Statistics `xml:"statistics"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type StarRating struct {
 | 
				
			||||||
 | 
						Text    string `xml:",chardata"`
 | 
				
			||||||
 | 
						Count   string `xml:"count,attr"`
 | 
				
			||||||
 | 
						Average string `xml:"average,attr"`
 | 
				
			||||||
 | 
						Min     string `xml:"min,attr"`
 | 
				
			||||||
 | 
						Max     string `xml:"max,attr"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Statistics struct {
 | 
				
			||||||
 | 
						Text  string `xml:",chardata"`
 | 
				
			||||||
 | 
						Views string `xml:"views,attr"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user