Skip to content

Commit

Permalink
feat: Downloading Videos from TG despite yt-dlp download archive
Browse files Browse the repository at this point in the history
  • Loading branch information
nlif-m committed Oct 29, 2023
1 parent 894ec7f commit f720f83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions atomgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (atomgen *Atomgen) deleteOldFiles() error {
return nil
}

func (atomgen *Atomgen) DownloadURL(URL string, withoutTimeLimit bool) error {
func (atomgen *Atomgen) DownloadURL(URL string, withoutTimeLimit bool, usingDownloadArchive bool) error {
channelName, err := atomgen.ytdlp.GetChannelNameFromURL(URL)
if err != nil {
return err
Expand All @@ -162,12 +162,15 @@ func (atomgen *Atomgen) DownloadURL(URL string, withoutTimeLimit bool) error {
cmd = atomgen.ytdlp.NewCmdWithArgs(
"--playlist-items", fmt.Sprintf("0:%v", atomgen.cfg.VideosToDowload),
"-x",
"--download-archive", atomgen.cfg.YtdlpDownloadArchive,
"--match-filters", fmt.Sprintf("!is_live & duration>%d", atomgen.cfg.YtdlpDurationLowerLimit),
"-f", "ba/ba*",
"--audio-format", fmt.Sprintf("%s/best", atomgen.cfg.DownloadAudioFormat),
"-o", ytdlpOutputTemplate,
"--no-simulate")

if usingDownloadArchive {
cmd.Args = append(cmd.Args, "--download-archive", atomgen.cfg.YtdlpDownloadArchive)
}
if !withoutTimeLimit && !(atomgen.cfg.WeeksToDownload == 0) {
cmd.Args = append(cmd.Args, "--dateafter", fmt.Sprint("today-", atomgen.cfg.WeeksToDownload, "weeks"))
}
Expand Down Expand Up @@ -203,7 +206,7 @@ func (atomgen *Atomgen) DownloadVideos() error {
go func(URL string) {
defer wg.Done()
limitDownloadBuffer <- 1
atomgen.DownloadURL(URL, false)
atomgen.DownloadURL(URL, false, true)
<-limitDownloadBuffer
}(record)
}
Expand Down
2 changes: 1 addition & 1 deletion tg.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TgBot(ag Atomgen, atomfileUpdateChan chan bool) {
bot.Send(msg)

go func(ctx tgbotapi.Update) {
err := ag.DownloadURL(url, true)
err := ag.DownloadURL(url, true, false)
if err != nil {
msg := tgbotapi.NewMessage(ctx.Message.Chat.ID, fmt.Sprintf("Sorry but failed to download %q", url))
msg.ReplyToMessageID = ctx.Message.MessageID
Expand Down

0 comments on commit f720f83

Please sign in to comment.