@@ -14,7 +14,7 @@ const ytdl = require("ytdl-core");
14
14
15
15
const { triggerAction, triggerActionSync } = require ( "../utils" ) ;
16
16
const { ACTIONS , CHANNEL } = require ( "./actions.js" ) ;
17
- const { getFolder } = require ( "./utils" ) ;
17
+ const { getFolder, UrlToJPG } = require ( "./utils" ) ;
18
18
const { cleanupArtistName } = require ( "../../providers/song-info" ) ;
19
19
20
20
const { createFFmpeg } = FFmpeg ;
@@ -37,12 +37,14 @@ const downloadVideoToMP3 = async (
37
37
sendFeedback ( "Downloading…" ) ;
38
38
39
39
if ( metadata === null ) {
40
- const info = await ytdl . getInfo ( videoUrl ) ;
41
- const thumbnails = info . videoDetails ?. author ?. thumbnails ;
40
+ const { videoDetails } = await ytdl . getInfo ( videoUrl ) ;
41
+ const thumbnails = videoDetails ?. thumbnails ;
42
42
metadata = {
43
- artist : info . videoDetails ?. media ?. artist || cleanupArtistName ( info . videoDetails ?. author ?. name ) || "" ,
44
- title : info . videoDetails ?. media ?. song || info . videoDetails ?. title || "" ,
45
- imageSrc : thumbnails ? thumbnails [ thumbnails . length - 1 ] . url : ""
43
+ artist : videoDetails ?. media ?. artist || cleanupArtistName ( videoDetails ?. author ?. name ) || "" ,
44
+ title : videoDetails ?. media ?. song || videoDetails ?. title || "" ,
45
+ imageSrc : thumbnails ?
46
+ UrlToJPG ( thumbnails [ thumbnails . length - 1 ] . url , videoDetails ?. videoId )
47
+ : ""
46
48
}
47
49
}
48
50
@@ -65,9 +67,10 @@ const downloadVideoToMP3 = async (
65
67
. on ( "data" , ( chunk ) => {
66
68
chunks . push ( chunk ) ;
67
69
} )
68
- . on ( "progress" , ( chunkLength , downloaded , total ) => {
69
- const progress = Math . floor ( ( downloaded / total ) * 100 ) ;
70
- sendFeedback ( "Download: " + progress + "%" ) ;
70
+ . on ( "progress" , ( _chunkLength , downloaded , total ) => {
71
+ const ratio = downloaded / total ;
72
+ const progress = Math . floor ( ratio * 100 ) ;
73
+ sendFeedback ( "Download: " + progress + "%" , ratio ) ;
71
74
} )
72
75
. on ( "info" , ( info , format ) => {
73
76
videoName = info . videoDetails . title . replace ( "|" , "" ) . toString ( "ascii" ) ;
@@ -112,7 +115,7 @@ const toMP3 = async (
112
115
113
116
try {
114
117
if ( ! ffmpeg . isLoaded ( ) ) {
115
- sendFeedback ( "Loading…" ) ;
118
+ sendFeedback ( "Loading…" , 2 ) ; // indefinite progress bar after download
116
119
await ffmpeg . load ( ) ;
117
120
}
118
121
0 commit comments