Skip to main content

Python m3u8 parser

Project description

https://travis-ci.org/globocom/m3u8.svg https://coveralls.io/repos/globocom/m3u8/badge.png?branch=master https://gemnasium.com/leandromoreira/m3u8.svg https://badge.fury.io/py/m3u8.svg

m3u8

Python m3u8 parser.

Documentation

The basic usage is to create a playlist object from uri, file path or directly from a string:

import m3u8

m3u8_obj = m3u8.load('http://videoserver.com/playlist.m3u8')  # this could also be an absolute filename
print m3u8_obj.segments
print m3u8_obj.target_duration

# if you already have the content as string, use

m3u8_obj = m3u8.loads('#EXTM3U8 ... etc ... ')

Encryption key

The segments may be encrypted, in this case the key attribute will be an object with all the attributes from #EXT-X-KEY:

If no #EXT-X-KEY is found, the key attribute will be None.

Multiple keys are supported.

Variant playlists (variable bitrates)

A playlist can have a list to other playlist files, this is used to represent multiple bitrates videos, and it’s called variant streams. See an example here.

variant_m3u8 = m3u8.loads('#EXTM3U8 ... contains a variant stream ...')
variant_m3u8.is_variant    # in this case will be True

for playlist in variant_m3u8.playlists:
    playlist.uri
    playlist.stream_info.bandwidth

the playlist object used in the for loop above has a few attributes:

  • uri: the url to the stream

  • stream_info: a StreamInfo object (actually a namedtuple) with all the attributes available to #EXT-X-STREAM-INF

  • media: a list of related Media objects with all the attributes available to #EXT-X-MEDIA

  • playlist_type: the type of the playlist, which can be one of VOD (video on demand) or EVENT

NOTE: the following attributes are not implemented yet, follow issue 4 for updates

  • alternative_audios: its an empty list, unless it’s a playlist with Alternative audio, in this case it’s a list with Media objects with all the attributes available to #EXT-X-MEDIA

  • alternative_videos: same as alternative_audios

A variant playlist can also have links to I-frame playlists, which are used to specify where the I-frames are in a video. See Apple’s documentation on this for more information. These I-frame playlists can be accessed in a similar way to regular playlists.

variant_m3u8 = m3u8.loads('#EXTM3U ... contains a variant stream ...')

for iframe_playlist in variant_m3u8.iframe_playlists:
    iframe_playlist.uri
    iframe_playlist.iframe_stream_info.bandwidth

The iframe_playlist object used in the for loop above has a few attributes:

  • uri: the url to the I-frame playlist

  • base_uri: the base uri of the variant playlist (if given)

  • iframe_stream_info: a StreamInfo object (same as a regular playlist)

Running Tests

$ ./runtests

Contributing

All contribution is welcome, but we will merge a pull request if, and only if, it

  • has tests

  • follows the code conventions

If you plan to implement a new feature or something that will take more than a few minutes, please open an issue to make sure we don’t work on the same thing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

m3u8-0.2.11.tar.gz (12.0 kB view details)

Uploaded Source

File details

Details for the file m3u8-0.2.11.tar.gz.

File metadata

  • Download URL: m3u8-0.2.11.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for m3u8-0.2.11.tar.gz
Algorithm Hash digest
SHA256 25d2d4476f8e8d956cc14b67571ffd7cf85719dc1dace0a90e134401c82a3a8c
MD5 6cac75cb0e53d9e3c13fb744cdee9eea
BLAKE2b-256 45be017720e5a32bcd8e3b4d0ff1647e3bb866b24a6431dd1c137afb4548c946

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page