- ipytv: A python3 library to parse IPTV playlists in the M3U Plus format.
- iptv2json: A command line utility to convert an IPTV playlist into json format.
- json2iptv: A command line utility to convert a json file
(like the one produced by
iptv2json
) into an IPTV (m3u_plus) playlist.
The M3U Plus format is a de facto standard for distributing IPTV playlists on the Internet.
The terms IPTV playlist and M3U Plus playlist are generally used interchangeably, but in this repository M3U Plus refers to the data format, while IPTV Playlist refers to playlists in the M3U Plus format.
M3U Plus stems from the
extended M3U8
format, of
which it supports only 2 tags (#EXTM3U
and #EXTINF
).
The syntax of the #EXTM3U
and #EXTINF
tags has been modified to include
extra attributes (e.g., logo, group, language). Unfortunately this has broken
the backward compatibility with the original M3U8 standard (as explained in
detail here).
This library has been created from scratch to parse and handle the M3U Plus format only. It does not fully support regular M3U8 playlists (only basic channel attributes are parsed).
Only #EXTM3U
, #EXTINF
and plain url rows are supported (i.e. they are parsed
and their value is made available as properties of an IPTVChannel
object).
All tags that are found between an #EXTINF
row and its related url row are
added as extras
to a channel, but without performing any parsing (i.e. they're
treated like plain strings).
In the example below, the #EXTVLCOPT
row is not parsed, but copied as-is:
#EXTINF:-1 tvg-id="" tvg-name="hello" tvg-country="IT" tvg-url="" group-title="Greetings",Hello!
#EXTVLCOPT:http-user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0
https://my-website.com/vod/hello.ts
This library requires Python 3 (and the related pip
installer).
PLEASE NOTE: the library makes use of the multiprocessing.Pool
class that
requires some care when working with the
IDLE environment.
To install the library system-wide, run:
pip install m3u-ipytv
To install it within a virtual environment, run:
python -m venv .venv
source .venv/bin/activate
pip install m3u-ipytv
The library comprises several modules, each with a specific area of competence:
- channel
- Everything related to the handling of channels in a playlist.
- doctor
- A collection of functions to fix common errors found in M3U files.
- exceptions
- All the exceptions thrown by the library.
- m3u
- Constants and functions related to M3U files.
- playlist
- Everything related to the loading and handling of M3U playlists.
- utils
- Commodity functions that work on playlist or channel objects.
Use the playlist.loadf(file)
function:
from ipytv import playlist
file = "~/Documents/my_playlist.m3u"
pl = playlist.loadf(file)
print(pl.length())
Use the playlist.loadu(url)
function:
from ipytv import playlist
url = "https://iptv-org.github.io/iptv/categories/classic.m3u"
pl = playlist.loadu(url)
print(pl.length())
Use the playlist.loads(string)
function:
from ipytv import playlist
string = """#EXTM3U
#EXTINF:-1 tvg-id="Rai 1" tvg-name="Rai 1" group-title="RAI",Rai 1
http://myown.link:80/luke/210274/78482"""
pl = playlist.loads(string)
print(pl.length())