Skip to main content

A Python Module for Reading and Writing XMLTV Files

Project description

python-xmltvalt
============

Introduction
------------
python-xmltvalt is a Python module that provides access to XMLTV data. XMLTV is
an XML format for storing TV listings.

More information on XMLTV can be found at http://wiki.xmltv.org.

This is a fork of the original 'pythong-xmltv' project
(https://pypi.org/project/python-xmltv/) and has some slight modifications
to resolve issues I found when trying to implement solutions for another
(forthcoming) open source project.

Many thanks to the original author, and the individual who cloned the
original code (https://github.com/mforkel/python-xmltv).

Requirements
------------
There are no requirements for Python 3.12 and up.


Usage
-----
Usage of the module is generally straight-forward::

import xmltv_alt
from pprint import pprint

# If you need to change the locale:
# xmltv_alt.locale = 'Latin-1'

# If you need to change the date format used in the XMLTV file:
# xmltv_alt.date_format = '%Y%m%d%H%M%S %Z'

filename = '/path/to/xmltv/file'

# Print info for XMLTV file (source, etc.)
pprint(xmltv_alt.read_data(open(filename, 'r')))

# Print channels
pprint(xmltv_alt.read_channels(open(filename, 'r')))

# Print programmes
pprint(xmltv_alt.read_programmes(open(filename, 'r')))

There are currently three functions for reading that should be used:

**read_data** ``(file_object) -> dict``
Get the source and other info from an XMLTV file.

Returns a dictionary of <tv> attributes, eg::

{'date': u'20030702230041 -0300',
'generator-info-name': u'tv_grab_na V3.20030629',
'generator-info-url': u'http://sourceforge.net/projects/xmltv',
'source-info-name': u'Zap2It',
'source-info-url': u'http://www.zap2it.com'}

**read_channels** ``(file_object) -> list``
Get all of the channels.

Returns a list of hashes, each representing a channel, eg::

[{'display-name': [(u'Channel 10 ELTV', u'')],
'id': u'C10eltv.zap2it.com'},
{'display-name': [(u'Channel 11 CBHT', u'')],
'icon': [{'desc': '','src': u'http://tvlistings2.zap2it.com/tms_network_logos/cbc.gif'}],
'id': u'C11cbht.zap2it.com'}]

**read_programmes** ``(file_object) -> list``
Get all of the programmes.

Returns a list of hashes, each representing a programme, eg::

[{'audio': [{'stereo': [u'stereo']}],
'category': [(u'Biz', u''), (u'Fin', u'')],
'channel': u'C23robtv.zap2it.com',
'start': u'20030702000000 ADT',
'stop': u'20030702003000 ADT',
'title': [(u'This Week in Business', u'')]},
{'audio': [{'stereo': [u'stereo']}],
'channel': u'C36wuhf.zap2it.com',
'desc': [(u'In an effort to grow up, George proposes marriage to former girlfriend Susan.',
u'')],
'rating': [{'system': u'VCHIP', 'value': u'PG'}],
'start': u'20030702000000 ADT',
'stop': u'20030702003000 ADT',
'sub-title': [(u'The Engagement', u'')],
'subtitles': [{'type': u'teletext'}],
'title': [(u'Seinfeld', u'')]}]

There is also a Writer class. It should always write proper XMLTV data. All
strings, except for dictionary keys, should be in Unicode.

It contains the following methods:

**__init__** ``(fp, encoding="iso-8859-1", date=None, source_info_url=None, source_info_name=None, generator_info_url=None, generator_info_name=None)`` -> ``Writer``
Returns a Writer object.

Arguments:

``fp``
A File object to write XMLTV data to

``encoding``
The text encoding that will be used. *Defaults to
``iso-8859-1``*

``date``
The date this data was generated. *Optional*

``source_info_url``
A URL for information about the source of the data. *Optional*

``source_info_name``
A human readable description of ``source_info_url``.
*Optional*

``generator_info_url``
A URL for information about the program that is generating the
XMLTV document. *Optional*

``generator_info_name``
A human readable description of ``generator_info_url``.
*Optional*

**write_channel** ``(channel)``
Write a channel dictionary

Here's an example channel dictionary::

{'display-name': [(u'Channel 11 CBHT', u'en')],
'icon': [{'src': u'http://tvlistings2.zap2it.com/tms_network_logos/cbc.gif'}],
'id': u'C11cbht.zap2it.com',
'url': u:'http://www.cbc.com'}

**write_programme** ``(programme)``
Write a programme dictionary

Here's an example programme dictionary::

{'audio': [{'stereo': u'stereo'}],
'category': [(u'Comedy', u'')],
'channel': u'C36wuhf.zap2it.com',
'country': [(u'USA', u'')],
'credits': [{'producer': [u'Larry David'], 'actor': [u'Jerry Seinfeld']}],
'date': [u'1995'],
'desc': [(u'In an effort to grow up, George proposes marriage to former girlfriend Susan.',
u'')],
'episode-num': [(u'7 . 1 . 1/1', u'xmltv_ns')],
'language': [(u'English', u'')],
'last-chance': [(u'Hah!', u'')],
'length': [{'units': u'minutes', 'length': 22}],
'new': [1],
'orig-language': [(u'English', u'')],
'premiere': [(u'Not really. Just testing', u'en')],
'previously-shown': [{'channel': u'C12whdh.zap2it.com',
'start': u'19950921103000 ADT'}],
'rating': [{'icon': [{'height': u'64',
'src': u'http://some.ratings/PGicon.png',
'width': u'64'}],
'system': u'VCHIP',
'value': u'PG'}],
'star-rating': [{'icon': [{'height': u'32',
'src': u'http://some.star/icon.png',
'width': u'32'}],
'value': u'4/5'}],
'start': u'20030702000000 ADT',
'stop': u'20030702003000 ADT',
'sub-title': [(u'The Engagement', u'')],
'subtitles': [{'type': u'teletext', 'language': (u'English', u'')}],
'title': [(u'Seinfeld', u'')],
'video': [{'colour': 1, 'aspect': u'4:3', 'present': 1}]}

**end** ``()``
Write end tag

Call this before closing a file.

Reporting Bugs
--------------
Please send all bugs, comments, and questions to the github repo
https://github.com/justinhorner/python-xmltv-alt


Changelog
=========

Version 1.5.0
-------------
* changes specifically for free-iptv
* renamed project to 'xmltv_alt' to easily differentiate between existing project

Version 1.4.4
-------------
* cleanup & changed from github fork

Version 1.4.3
* Add pretty_print option to Writer.write()

Version 1.4.2
-------------
* Text encoding fixes. (Patch from Jan Sušnik)

Version 1.4.1
-------------
* Updated MANIFEST.in to include all doc files

Version 1.4
-----------
* Updated to reflect current XMLTV DTD (patch from Igor Sobolev)
* Clean up for pypi release

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

python-xmltvalt-1.5.0.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

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

python_xmltvalt-1.5.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file python-xmltvalt-1.5.0.tar.gz.

File metadata

  • Download URL: python-xmltvalt-1.5.0.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for python-xmltvalt-1.5.0.tar.gz
Algorithm Hash digest
SHA256 ec804561e6a355b979526f0d71a1f88674dcd8fee92adf4e2183c33be2079c6f
MD5 58a56516443678a06ef42b1bf883d997
BLAKE2b-256 d6190899b6fd7a8d3d3fe904fc8d1438929036d44032da7194699474daccd734

See more details on using hashes here.

File details

Details for the file python_xmltvalt-1.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_xmltvalt-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a029145c1b45aa4e8bf200861764ea6cc36e3135e0f4a742a0668b814a7fd426
MD5 c76543d81c627e86fe992317023904f5
BLAKE2b-256 d2f0a70aea492bf7b972d1e508d8da0482535db7a5b0625bc316655b760ad6cd

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