Open utkrist opened 1 year ago
Try this code:
import m3u8
m3u8_text = """
#EXTM3U
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-VERSION:5
#EXT-X-STREAM-INF:CLOSED-CAPTIONS=NONE,BANDWIDTH=2516370,AVERAGE-BANDWIDTH=2516370,RESOLUTION=1280x720,CODECS="mp4a.40.2,avc1.640020"
video_720p.m3u8
#EXT-X-STREAM-INF:CLOSED-CAPTIONS=NONE,BANDWIDTH=1640580,AVERAGE-BANDWIDTH=1640580,RESOLUTION=960x540,CODECS="mp4a.40.2,avc1.640020"
video_540p.m3u8
"""
m3u8_obj = m3u8.loads(m3u8_text)
nepali_audio = m3u8.Media(uri='audios/Nepali/master.m3u8', type='AUDIO', group_id='Audio', language='np', name='Nepali', default='YES', autoselect='YES')
m3u8_obj.add_media(nepali_audio)
german_audio = m3u8.Media(uri='audios/German/master.m3u8', type='AUDIO', group_id='Audio', language='de', name='German', default='NO', autoselect='NO')
m3u8_obj.add_media(german_audio)
nepali_subs = m3u8.Media(uri=f'subtitles/Nepali/master.m3u8', type='SUBTITLES', group_id='Subtitle', language='np', name='Nepali', forced='NO', autoselect='NO')
m3u8_obj.add_media(nepali_subs)
german_subs = m3u8.Media(uri=f'subtitles/German/master.m3u8', type='SUBTITLES', group_id='Subtitle', language='de', name='German', forced='NO', autoselect='NO')
m3u8_obj.add_media(german_subs)
for playlist in m3u8_obj.playlists:
playlist.media += [nepali_audio, german_audio, nepali_subs, german_subs]
print(m3u8_obj.dumps())
I don't think this will do the job. The issue is the missing of the TAGs: AUDIO="Audio",SUBTITLES="Subtitle" inside the EXT-X-STREAM-INF.
I want to inject audios and subtitles in m3u8 file. The first step is to add new audios and subtitles as media. The second step would be to add subtitle and audio field in the renditions list.
The initial file looked like this:
The modified file should look like this:
With the code below the medias get added successfully but the AUDIO and SUBTILES fields do not get added in the lines starting with
#EXT-X-STREAM-INF
. The problem lies in thedump
function.'I request you to fix the dump and the dumps function to add the above fields.