Skip to content
A lightweight python playlist parser
Python
Branch: master
Clone or download
Latest commit d7b383d Jul 22, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE Update issue templates Apr 4, 2019
modules
CODE_OF_CONDUCT.md
CONTRIBUTING.md Create CONTRIBUTING.md Apr 4, 2019
LICENSE Create LICENSE Apr 4, 2019
README.md
__init__.py Fixed: Files are not parsed if extension is written in uppercase Apr 16, 2019

README.md

python-tv-parser (PTP)

PTP is an lightweight Python library for parsing common Playlist File Types

Python Version Last Commit

Lightweight Parsing

The goal of this project is to make it lightweight as possible and take the best performance out of it.
That's why we only want to parse the following information from the files:

  • title/name
  • icon/logo
  • url/source
  • group (if possible)

Requirements

tested on Python 2.7.
All Python versions above 2.7 should work.
Versions under 2.7 are untested

Supported FileTypes

  • .M3U (ready for test)
  • .M3U8 (ready for test)

Additional Features

  • EPG Parsing (soon)

Public Functions

Function Description Args
ConvertDirectory Convert/Parse all files in an Directory pathToDir, badCharacter
ConvertFile Convert/Parse a single file pathToFile, badCharacter
ConvertContent Convert/Parse the given string (content) content, extension, badCharacter
_ResolveFileType Get file extension pathToFile
_ResolveFileName Get file name pathToFile

badCharacter is optional (These Characters wil be removed from the Group and Item Title)

Parsing

Parsing a single file or a whole directory

File

ConvertFile function: Convert a file (path to file - string) returns an Dict Object with all Elements
usage:

parsedFile = ConvertFile("C://..<PathToMyFile>")

example output:

{
  "myGroup1": {
    "MyCoolVideo": {
      "Url": "http..."
    }
    ...
  },
  "myGroup2": {
    "MyCoolMusic": {
      "Url": "http..."
    }
    ...
  }
  ...
}

File Content

ConvertContent function: Converts content (string) returns an Dict Object with all TvElements
usage:

parsedContent = ConvertContent("#EXTM3U ...", "m3u")

example output:

{
  "myGroup1": {
    "MyCoolVideo": {
      "Url": "http..."
    }
    ...
  },
  "myGroup2": {
    "MyCoolMusic": {
      "Url": "http..."
    }
    ...
  }
  ...
}

Directory

ConvertDirectory function: Convert a Directory (path to directory - string) returns an Dict Object which contains other Dicts which represent the files,
these Dicts contains the content of a singleFile
usage:

parsedDirectory = ConvertDirectory("C://..<PathToMyDirectory>")

example output:

{
  "MyFile1": {
    "myGroup1": {
      "MyCoolVideo": {
        "Url": "http..."
      }
      ...
    },
    "myGroup2": {
      "MyCoolMusic": {
        "Url": "http..."
      }
      ...
    }
    ...
  },
  "MyFile2": {
    "awesomeGroup1": {
      "MyCoolStream": {
        "Url": "http..."
      }
      ...
    },
    "awesomeGroup2": {
      "MyFunnyVideo": {
        "Url": "http..."
      }
      ...
    }
    ...
  }
}

Note: Each function has an badCharacter Parameter, here you can add Characters (as a string) which will be removed from Group/Entry Names

You can’t perform that action at this time.