Skip to content

Commit b25ac78

Browse files
Tanq16Tanq16
authored andcommitted
fix YT bug (blocking channel)
1 parent 1b7c91f commit b25ac78

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

downloaders/youtube/youtube.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func removeExtension(filePath string) string {
140140
return filePath[:len(filePath)-len(ext)]
141141
}
142142

143-
func DownloadYouTubeVideo(url, outputPathPre, format, dType string, progressCh chan<- int64, outputCh chan<- []string) error {
143+
func DownloadYouTubeVideo(url, outputPathPre, format, dType string, outputCh chan<- []string) error {
144144
outputPath := removeExtension(outputPathPre)
145145
ytdlpPath := isYtDlpAvailable()
146146
if ytdlpPath == "" {
@@ -225,16 +225,6 @@ func DownloadYouTubeVideo(url, outputPathPre, format, dType string, progressCh c
225225
return fmt.Errorf("error executing yt-dlp: %v", err)
226226
}
227227

228-
// Get file size after download is complete
229-
var totalSizeBytes int64
230-
fileInfo, err := os.Stat(outputPathPre) // won't always be the same because video can default to webm
231-
if err == nil {
232-
totalSizeBytes = fileInfo.Size()
233-
} else {
234-
totalSizeBytes = 1
235-
}
236-
progressCh <- totalSizeBytes
237-
238228
if musicId != "" {
239229
// outputPathPre works here because audio is always m4a, but user can mess it up
240230
_ = addMusicMetadata(outputPathPre, musicClient, musicId)

internal/downloader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ func BatchDownload(entries []utils.DownloadEntry, numLinks, connectionsPerLink i
164164
// YouTube download (with yt-dlp as dependency)
165165
// =================================================================================================================
166166
case "youtube":
167+
close(progressCh) // Note needed for youtube downloads
167168
processedURL, format, dType, output, err := danzoyoutube.ProcessURL(entry.URL)
168169
if err != nil {
169170
outputMgr.ReportError(entryFunctionId, fmt.Errorf("error processing YouTube URL %s: %v", entry.OutputPath, err))
@@ -199,9 +200,8 @@ func BatchDownload(entries []utils.DownloadEntry, numLinks, connectionsPerLink i
199200
}
200201
}(entry.OutputPath, streamCh)
201202

202-
err = danzoyoutube.DownloadYouTubeVideo(entry.URL, entry.OutputPath, format, dType, progressCh, streamCh)
203+
err = danzoyoutube.DownloadYouTubeVideo(entry.URL, entry.OutputPath, format, dType, streamCh)
203204
close(streamCh)
204-
close(progressCh) // temporary; TODO: remove progress for YT or print size
205205
if err != nil {
206206
outputMgr.ReportError(entryFunctionId, fmt.Errorf("error downloading %s: %v", entry.OutputPath, err))
207207
outputMgr.SetMessage(entryFunctionId, fmt.Sprintf("Error downloading %s", entry.OutputPath))

0 commit comments

Comments
 (0)