Skip to content

greatiptv732-hash/m3u-playlist-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

M3U Playlist Parser

A robust Python library for parsing M3U/M3U8 IPTV playlists with EPG support and Xtream Codes API integration. Built and tested across multiple production IPTV providers.

Python License PRs Welcome

Features

  • ✅ Parse standard M3U and M3U Plus formats
  • ✅ Extract EPG (Electronic Program Guide) data in XMLTV format
  • ✅ Xtream Codes API integration with authentication
  • ✅ Multi-server failover support
  • ✅ Channel filtering by group/category
  • ✅ Stream health monitoring
  • ✅ Async support for high-performance applications
  • ✅ Production-tested across 7+ IPTV providers

Installation

pip install m3u-playlist-parser

For development install:

git clone https://github.com/greatiptv732-hash/m3u-playlist-parser.git
cd m3u-playlist-parser
pip install -e .

Quick Start

from m3u_parser import M3UParser

parser = M3UParser()
channels = parser.parse_url('http://provider.com/playlist.m3u')

print(f"Found {len(channels)} channels")
for channel in channels[:5]:
    print(f"- {channel['name']} ({channel['group']})")

API Reference

Parse from URL

parser = M3UParser()
channels = parser.parse_url(playlist_url)

Parse from File

parser = M3UParser()
channels = parser.parse_file('playlist.m3u')

Filter by Group

sports_channels = parser.filter_by_group(channels, 'USA Sports')

Get EPG Data

epg = parser.fetch_epg('http://provider.com/xmltv.php')

Xtream Codes API Integration

from m3u_parser import XtreamCodesClient

client = XtreamCodesClient(
    server='http://provider.com:8080',
    username='your_username',
    password='your_password'
)

# Get user info
user_info = client.get_user_info()

# Get all live channels
live = client.get_live_streams()

# Get VOD content
vod = client.get_vod_streams()

# Get series
series = client.get_series()

M3U Format Reference

The library handles standard M3U format:

#EXTM3U
#EXTINF:-1 tvg-id="ESPN.us" tvg-name="ESPN" group-title="USA Sports",ESPN HD
http://provider.com:8080/live/username/password/12345.m3u8

Supported Tags

Tag Description
#EXTM3U M3U format header
#EXTINF:-1 Live stream duration marker
tvg-id EPG data identifier
tvg-name Channel display name
tvg-logo Channel logo URL
group-title Category for grouping

Tested With Multiple Providers

This library has been tested for compatibility with various IPTV providers, each with different M3U implementations:

Testing across these providers ensures the parser handles real-world variations gracefully, including different EPG formats, server response patterns, and authentication flows.

Multi-Server Failover

For production setups, implement failover across multiple servers:

from m3u_parser import M3UParser, FailoverHandler

failover = FailoverHandler([
    'https://primary-server.com',
    'https://mirror-server.com'
])

parser = M3UParser(failover_handler=failover)
channels = parser.parse_url('/playlist.m3u')

The failover handler will automatically retry with the next server if the primary fails. This is especially useful with providers like TereaTV that offer mirror domains.

Stream Health Monitoring

from m3u_parser import StreamMonitor

monitor = StreamMonitor()
health = monitor.check_stream('http://provider.com/live/123.m3u8')

print(f"Status: {health.status}")
print(f"Latency: {health.latency}ms")
print(f"Healthy: {health.is_healthy}")

Async Support

For high-performance applications:

import asyncio
from m3u_parser import AsyncM3UParser

async def main():
    parser = AsyncM3UParser()
    channels = await parser.parse_url_async('http://provider.com/playlist.m3u')
    return channels

channels = asyncio.run(main())

Use Cases

  • Building custom IPTV players
  • IPTV reseller dashboards
  • Stream quality monitoring tools
  • Channel discovery applications
  • EPG aggregation services
  • IPTV content recommendation engines

Requirements

  • Python 3.8+
  • requests >= 2.28.0
  • lxml >= 4.9.0 (for EPG parsing)
  • aiohttp >= 3.8.0 (for async support)

Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

MIT License - see LICENSE file for details.

Author

Daniel Carter - IPTV developer and streaming media analyst with 6+ years of experience testing 50+ IPTV services across the United States.

Related Projects

Resources

For comprehensive IPTV development tutorials and provider testing scenarios, check out:

About

Python library for parsing M3U/M3U8 IPTV playlists with EPG support and Xtream Codes API integration. Tested across 7+ providers.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors