Skip to main content

A useful module for parsing m3u files or links

Project description

Welcome to m3u_parser

Version

A parser for m3u files. It parses the contents of m3u file to a list of streams information which can be saved as a JSON/CSV file.

Check go-m3u-parser also.

🏠 Homepage

Install

pip install m3u-parser

OR

pipenv install m3u-parser

Example

from m3u_parser import M3uParser
url = "/home/pawan/Downloads/ru.m3u"
useragent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36"
m3u_playlist = M3uParser(timeout=5, useragent=useragent)
m3u_playlist.parse_m3u(url)
m3u_playlist.remove_by_extension('mp4')
m3u_playlist.filter_by('status', 'GOOD')
print(len(m3u_playlist.get_list()))
m3u_playlist.to_file('pawan.json')

Usage

from m3u_parser import M3uParser
url = "/home/pawan/Downloads/ru.m3u"
useragent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36"
m3u_playlist = M3uParser(timeout=5, useragent=useragent)

Functions

def parse_m3u(self, path, check_live=True):
        """Parses the content of local file/URL.

        It downloads the file from the given url or use the local file path to get the content and parses line by line
        to a structured format of streams information.

        :param path: Path can be a url or local filepath
        :type path: str
        :param check_live: To check if the stream links are working or not
        :type check_live: bool
        :rtype: None
        """
	
def filter_by(self, key, filters, retrieve=True, nested_key=False):
        """Filter streams infomation.

        It retrieves/removes stream information from streams information list using filter/s on key.

        :param key: Key can be single or nested. eg. key='name', key='language-name'
        :type key: str
        :param filters: List of filter/s to perform the retrieve or remove operation.
        :type filters: str or list
        :param retrieve: True to retrieve and False for removing based on key.
        :type retrieve: bool
        :param nested_key: True/False for if the key is nested or not.
        :type nested_key: bool
        :rtype: None
        """
		
def reset_operations(self):
        """Reset the stream information list to initial state before various operations.

        :rtype: None
        """
		
def remove_by_extension(self, extension):
        """Remove stream information with certain extension/s.

        It removes stream information from streams information list based on extension/s provided.

        :param extension: Name of the extension like mp4, m3u8 etc. It can be a string or list of extension/s.
        :type extension: str or list
        :rtype: None
        """
		
def retrieve_by_extension(self, extension):
        """Select only streams information with a certain extension/s.

        It retrieves the stream information based on extension/s provided.

        :param extension: Name of the extension like mp4, m3u8 etc. It can be a string or list of extension/s.
        :type extension: str or list
        :rtype: None
        """
		
def remove_by_category(self, filter_word):
        """Removes streams information with category containing a certain filter word/s.

        It removes stream information based on category using filter word/s.

        :param filter_word: It can be a string or list of filter word/s.
        :type filter_word: str or list
        :rtype: None
        """
		
def retrieve_by_category(self, filter_word):
        """Retrieve only streams information that contains a certain filter word/s.

        It retrieves stream information based on category/categories.

        :param filter_word: It can be a string or list of filter word/s.
        :type filter_word: str or list
        :rtype: None
        """
		
def sort_by(self, key, asc=True, nested_key=False):
        """Sort streams information.

        It sorts streams information list sorting by key in asc/desc order.

        :param key: It can be single or nested key.
        :type key: str
        :param asc: Sort by asc or desc order
        :type asc: bool
        :param nested_key: True/False for if the key is nested or not.
        :type nested_key: bool
        :rtype: None
        """
		
def get_json(self, indent=4):
        """Get the streams information as json.

        :param indent: Int value for indentation.
        :type indent: int
        :return: json of the streams_info list
        :rtype: json
        """
		
def get_list(self):
        """Get the parsed streams information list.

        It returns the streams information list.

        :return: Streams information list
        :rtype: list
        """
		
def get_random_stream(self, random_shuffle=True):
        """Return a random stream information

        It returns a random stream information with shuffle if required.

        :param random_shuffle: To shuffle the streams information list before returning the random stream information.
        :type random_shuffle: bool
        :return: A random stream info
        :rtype: dict
        """
		
def to_file(self, filename, format="json"):
        """Save to file (CSV or JSON)

        It saves streams information as a CSV or JSON file with a given filename and format parameters.

        :param filename: Name of the file to save streams_info as.
        :type filename: str
        :param format: csv/json to save the streams_info.
        :type format: str
        :rtype: None
        """

Author

👤 Pawan Paudel

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

Copyright © 2020 Pawan Paudel.

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

m3u_parser-0.1.3.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

m3u_parser-0.1.3-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file m3u_parser-0.1.3.tar.gz.

File metadata

  • Download URL: m3u_parser-0.1.3.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for m3u_parser-0.1.3.tar.gz
Algorithm Hash digest
SHA256 72501820d4e5f040fc3dd62a5ef867c11a2b3bb528b40563031e74a13f7e367a
MD5 8dae59fd2ba55873dfb4ac2ccdcd57a6
BLAKE2b-256 25b9f1e3bc90b04c881f9e6881ca93c5fc367ad33a5a4eec0764421c8878731f

See more details on using hashes here.

File details

Details for the file m3u_parser-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: m3u_parser-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for m3u_parser-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ed2d173b1aca47f3a9c51d423a6b9caa71d4a114cba45cc2eb4c109c78476dd3
MD5 f72724431d3112053b2da439534d410a
BLAKE2b-256 adb341f0f0af77c8f447050ea48c401839839cb91ff3a04b916b8f7e67f6dbf0

See more details on using hashes here.

Supported by

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