Dump and dumps functions do not show subtitles and audio fields added to stream_info
- Dominant language
- Python
- Stars
- 2.3k
- Forks
- 496
- PR merge metrics
- No merged PRs in 30d
Description
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:
```
#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
```
The modified file should look like this:
```
#EXTM3U
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-VERSION:5
#EXT-X-MEDIA:URI="audios/Nepali/master.m3u8",TYPE=AUDIO,GROUP-ID="Audio",LANGUAGE="np",NAME="Nepali",DEFAULT=YES,AUTOSELECT=YES
#EXT-X-MEDIA:URI="audios/German/master.m3u8",TYPE=AUDIO,GROUP-ID="Audio",LANGUAGE="de",NAME="German",DEFAULT=NO,AUTOSELECT=NO
#EXT-X-MEDIA:URI="subtitles/German/master.m3u8",TYPE=SUBTITLES,GROUP-ID="Subtitle",LANGUAGE="de",NAME="German",AUTOSELECT=NO,FORCED=NO
#EXT-X-MEDIA:URI="subtitles/Nepali/master.m3u8",TYPE=SUBTITLES,GROUP-ID="Subtitle",LANGUAGE="np",NAME="Nepali",AUTOSELECT=NO,FORCED=NO
#EXT-X-STREAM-INF:CLOSED-CAPTIONS=NONE,BANDWIDTH=2516370,AVERAGE-BANDWIDTH=2516370,RESOLUTION=1280x720,CODECS="mp4a.40.2,avc1.640020",AUDIO="Audio",SUBTITLES="Subtitle"
607588853682e1001241042c_720p.m3u8
#EXT-X-STREAM-INF:CLOSED-CAPTIONS=NONE,BANDWIDTH=1640580,AVERAGE-BANDWIDTH=1640580,RESOLUTION=960x540,CODECS="mp4a.40.2,avc1.640020",AUDIO="Audio",SUBTITLES="Subtitle"
607588853682e1001241042c_540p.m3u8
#EXT-X-STREAM-INF:CLOSED-CAPTIONS=NONE,BANDWIDTH=4755240,AVERAGE-BANDWIDTH=4755240,RESOLUTION=1920x1080,CODECS="mp4a.40.2,avc1.64002a",AUDIO="Audio",SUBTITLES="Subtitle"
607588853682e1001241042c_1080p.m3u8
#EXT-X-STREAM-INF:CLOSED-CAPTIONS=NONE,BANDWIDTH=994068,AVERAGE-BANDWIDTH=994068,RESOLUTION=640x360,CODECS="mp4a.40.2,avc1.64001f",AUDIO="Audio",SUBTITLES="Subtitle"
607588853682e1001241042c_360p.m3u8
#EXT-X-STREAM-INF:CLOSED-CAPTIONS=NONE,BANDWIDTH=697078,AVERAGE-BANDWIDTH=697078,RESOLUTION=480x270,CODECS="mp4a.40.2,avc1.64001e",AUDIO="Audio",SUBTITLES="Subtitle"
607588853682e1001241042c_270p.m3u8
```
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 the `dump` function.'
```
import m3u8
manifest file = './tmp/manifest.m3u8'
m3u8_obj = None
with open(manifest_file, 'r') as manifest:
content = manifest.read()
m3u8_obj = m3u8.loads(content)
# Add audios media
new_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(new_audio)
new_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(new_audio)
# Add subtitle media
new_subtitle = 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(new_subtitle)
new_subtitle = 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(new_subtitle)
# Trying to add audio and subtitles field in renditions
for playlist in m3u8_obj.playlists:
stream_info = playlist.stream_info
stream_info.audio = 'Audio'
stream_info.subtitles = 'Subtitle'
print( m3u8_obj.dumps())
```
I request you to fix the dump and the dumps function to add the above fields.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the stream_info objects in the reported loop and the m3u8_obj.dumps() entry point, then reproduce the manifest output shown in the issue. Trace how dump and dumps serialize #EXT-X-STREAM-INF attributes and verify that the audio and subtitles fields are emitted. Done means the generated rendition lines include AUDIO="Audio" and SUBTITLES="Subtitle" while the media entries remain present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100