icefee / hls2mp4

a tool for download hls/m3u8 to mp4
7 stars 2 forks source link

Not working with `.aac` files #2

Open Sawtaytoes opened 1 year ago

Sawtaytoes commented 1 year ago

I have a file like this, and it keeps complaining there's no ts file.

But your code is setup to accept aac, so I don't see why it'd fail. Looks like it's happening here:

matchReg = new RegExp(keyTagMatchRegExp.source + '|' + createFileUrlRegExp('ts', 'gi').source, 'g');
matches = content.match(matchReg);

if (!matches) {
  throw new Error('Invalid m3u8 file, no ts file found');
}

This is my m3u8 file:

#EXTM3U
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-VERSION:4
#EXT-X-MEDIA:URI="ep-dvi-en-hls-16x9-1080p_83304.m3u8",TYPE=AUDIO,GROUP-ID="multiple_audio_tracks",LANGUAGE="eng",NAME="English",DEFAULT=YES,AUTOSELECT=YES
#EXT-X-MEDIA:URI="ep-dvi-en-hls-16x9-1080p_83305.m3u8",TYPE=AUDIO,GROUP-ID="multiple_audio_tracks",LANGUAGE="eng",NAME="English AD",DEFAULT=NO,AUTOSELECT=YES,CHARACTERISTICS="public.accessibility.describes-video"
#EXT-X-MEDIA:URI="8kypvarq_ep_m1080_en-captions.m3u8",TYPE=SUBTITLES,GROUP-ID="subs",LANGUAGE="en",NAME="English",DEFAULT=NO,AUTOSELECT=YES,FORCED=NO,CHARACTERISTICS="public.accessibility.describes-music-and-sound,public.accessibility.transcribes-spoken-dialog"
#EXT-X-STREAM-INF:BANDWIDTH=2600279,AVERAGE-BANDWIDTH=2249636,RESOLUTION=960x540,FRAME-RATE=29.97,CODECS="avc1.64001f,mp4a.40.2",AUDIO="multiple_audio_tracks",SUBTITLES="subs"
ep-dvi-en-hls-16x9-1080p-540p-2000k.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=7858019,AVERAGE-BANDWIDTH=6848537,RESOLUTION=1920x1080,FRAME-RATE=29.97,CODECS="avc1.640028,mp4a.40.2",AUDIO="multiple_audio_tracks",SUBTITLES="subs"
ep-dvi-en-hls-16x9-1080p-1080p-6500k.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=5509115,AVERAGE-BANDWIDTH=4804491,RESOLUTION=1280x720,FRAME-RATE=29.97,CODECS="avc1.64001f,mp4a.40.2",AUDIO="multiple_audio_tracks",SUBTITLES="subs"
ep-dvi-en-hls-16x9-1080p-720p-4500k.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=3748939,AVERAGE-BANDWIDTH=3271782,RESOLUTION=1280x720,FRAME-RATE=29.97,CODECS="avc1.64001f,mp4a.40.2",AUDIO="multiple_audio_tracks",SUBTITLES="subs"
ep-dvi-en-hls-16x9-1080p-720p-3000k.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1510217,AVERAGE-BANDWIDTH=1329594,RESOLUTION=768x432,FRAME-RATE=29.97,CODECS="avc1.64001e,mp4a.40.2",AUDIO="multiple_audio_tracks",SUBTITLES="subs"
ep-dvi-en-hls-16x9-1080p-432p-1100k.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1061471,AVERAGE-BANDWIDTH=951316,RESOLUTION=640x360,FRAME-RATE=29.97,CODECS="avc1.64001e,mp4a.40.2",AUDIO="multiple_audio_tracks",SUBTITLES="subs"
ep-dvi-en-hls-16x9-1080p-360p-730k.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=615230,AVERAGE-BANDWIDTH=563853,RESOLUTION=480x270,FRAME-RATE=14.985,CODECS="avc1.4d4015,mp4a.40.2",AUDIO="multiple_audio_tracks",SUBTITLES="subs"
ep-dvi-en-hls-16x9-1080p-270p-365k.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=358553,AVERAGE-BANDWIDTH=334200,RESOLUTION=416x234,FRAME-RATE=9.99,CODECS="avc1.4d400c,mp4a.40.2",AUDIO="multiple_audio_tracks",SUBTITLES="subs"
ep-dvi-en-hls-16x9-1080p-234p-145k.m3u8
#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=652835,AVERAGE-BANDWIDTH=362105,RESOLUTION=960x540,CODECS="avc1.64001f",URI="ep-dvi-en-hls-16x9-1080p-540p-2000k_I-Frame.m3u8"
#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=1538557,AVERAGE-BANDWIDTH=902070,RESOLUTION=1920x1080,CODECS="avc1.640028",URI="ep-dvi-en-hls-16x9-1080p-1080p-6500k_I-Frame.m3u8"
#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=1099828,AVERAGE-BANDWIDTH=639647,RESOLUTION=1280x720,CODECS="avc1.64001f",URI="ep-dvi-en-hls-16x9-1080p-720p-4500k_I-Frame.m3u8"
#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=909762,AVERAGE-BANDWIDTH=513856,RESOLUTION=1280x720,CODECS="avc1.64001f",URI="ep-dvi-en-hls-16x9-1080p-720p-3000k_I-Frame.m3u8"
#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=448495,AVERAGE-BANDWIDTH=239456,RESOLUTION=768x432,CODECS="avc1.64001e",URI="ep-dvi-en-hls-16x9-1080p-432p-1100k_I-Frame.m3u8"
#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=339188,AVERAGE-BANDWIDTH=172750,RESOLUTION=640x360,CODECS="avc1.64001e",URI="ep-dvi-en-hls-16x9-1080p-360p-730k_I-Frame.m3u8"
#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=202461,AVERAGE-BANDWIDTH=115055,RESOLUTION=480x270,CODECS="avc1.4d4015",URI="ep-dvi-en-hls-16x9-1080p-270p-365k_I-Frame.m3u8"
#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=98413,AVERAGE-BANDWIDTH=57923,RESOLUTION=416x234,CODECS="avc1.4d400c",URI="ep-dvi-en-hls-16x9-1080p-234p-145k_I-Frame.m3u8"

And your tool starts downloading the .aac files in which looks like this:

#EXTM3U
#EXT-X-ALLOW-CACHE:NO
#EXT-X-VERSION:4
#EXT-X-TARGETDURATION:7
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:6.059,
ep-dvi-en-hls-16x9-1080p_83304_00001.aac
#EXTINF:5.995,
ep-dvi-en-hls-16x9-1080p_83304_00002.aac
#EXTINF:6.016,
ep-dvi-en-hls-16x9-1080p_83304_00003.aac
#EXTINF:5.995,
ep-dvi-en-hls-16x9-1080p_83304_00004.aac

The .ts files are in a separate m3u8 file.

icefee commented 1 year ago

Thanks for your feedback, m3u8 file with multiple audio track not supported for now.