Skip to main content

Python 3 library to import from and export to SongBeamer format.

Project description

icemac.songbeamer

https://travis-ci.com/icemac/icemac.songbeamer.svg?branch=master https://coveralls.io/repos/github/icemac/icemac.songbeamer/badge.svg?branch=master

Library to read and write SongBeamer files.

This package is licensed under the MIT License, see LICENSE.TXT inside the package.

Supported SongBeamer versions

Currently Songbeamer versions 2 to 4 are supported. (Internal version number in .sng files: #Version=3.)

Supported Python version

Runs only on Python 3.7. Older Python versions are not supported.

Running Tests

To run the tests call:

$ tox

(You maybe have to install tox beforehand using: pip install tox.)

Hacking

Fork me on: https://github.com:/icemac/icemac.songbeamer

Changes

1.0 (2018-11-02)

Backwards incompatible changes

  • The icemac.songbeamer.SNG instances no longer store the data on the data attribute but it now behaves like a dict thus allowing direct dict access to the data.

  • It is no longer possible to use attributes on icemac.songbeamer.SNG instances to read and store encoded bytes data. Either read/write text data from/to the icemac.songbeamer.SNG instance using the dict API or use the parse function (see next item) to import resp. use .SNG.export() to export the data encoded.

  • Add a function icemac.songbeamer.parse() converting a byte stream into a icemac.songbeamer.SNG instance. It replaces the class method on the SNG instance. It returns None if the data cannot be parsed and it logs an error message.

  • Drop support for Python 3.5, 3.6 and PyPy3, thus only supporting Python 3.7 now.

Features

  • Add a function icemac.songbeamer.open() to open a file given by a path and get a icemac.songbeamer.SNG instance.

  • Make .SNG.export() robust against missing text in songs.

  • Add a command line script songbeamer-xls-export exporting titles and song book numbers from folder containing SongBeamer files to an XLS file. To be able to use it icemac.songbeamer has to be installed with the xls extra like this:

    $ pip install "icemac.songbeamer[xls]"
  • Support UTF-8 encoded SongBeamer files starting with the UTF-8 BOM.

  • Change license from ZPL to MIT.

0.3 (2018-10-07)

  • Add support for Python 3.5 to 3.7 and PyPy3.

  • Drop support for Python 3.2 and 3.3.

0.2.0 (2012-10-31)

  • Add ability to parse bytes objects.

  • Sorting keys in export file to be compatible across Python 3.2 and 3.3.

0.1.0 (2012-05-05)

  • Initial public release.

To do

Implementations

  • import/export of .col files (schedules)

Open Questions

  • Are Transpose and Speed actually int values?

Usage

Importing a .sng file

To import a .sng file use the open function in the module icemac.songbeamer. It expects a filename and path and returns a SNG instance:

>>> import icemac.songbeamer
>>> import pkg_resources
>>> filename = pkg_resources.resource_filename(
...     'icemac.songbeamer.tests', 'example.sng')
>>> sng = icemac.songbeamer.open(filename)
>>> sng.__class__
<class 'icemac.songbeamer.sng.SNG'>

Alternatively there is a function parse in the same module which parses bytes (e. g. read from a binary file) into an SNG instance:

>>> with open(filename, 'rb') as file:
...     sng = icemac.songbeamer.parse(file.read())
>>> sng.__class__
<class 'icemac.songbeamer.sng.SNG'>

Accessing a file’s data

The SNG instance extends dict so the date is accessible via the usual python dict API:

>>> from pprint import pprint
>>> pprint(sng)
{'Author': 'me',
 'Text': ['La la la', '---', 'Lei lei lei'],
 'Version': 3}
>>> sng['Title'] = 'Mÿ šôñg'

The values are stored as numbers resp. strings (text):

>>> sng['Version']
3
>>> sng['Author']
'me'

Exporting a .sng file

>>> from tempfile import TemporaryFile

To export to a .sng file use the export method. It expects a byte stream (io.BytesIO or open binary file) as argument to write into:

>>> with TemporaryFile() as file:
...     sng.export(file)
...     _ = file.seek(0)
...     pprint(file.readlines())
[b'#Author=me\r\n',
 b'#Title=M\xff \x9a\xf4\xf1g\r\n',
 b'#Version=3\r\n',
 b'---\r\n',
 b'La la la\r\n',
 b'---\r\n',
 b'Lei lei lei']

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

icemac.songbeamer-1.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

icemac.songbeamer-1.0-py2.py3-none-any.whl (15.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file icemac.songbeamer-1.0.tar.gz.

File metadata

  • Download URL: icemac.songbeamer-1.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.10.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.7 CPython/2.7.15

File hashes

Hashes for icemac.songbeamer-1.0.tar.gz
Algorithm Hash digest
SHA256 1ddb798612043e4cfae806a1a2914dd485c14ec56034195873a0786702373167
MD5 a4ee67a235fc69356ad81b393bd1d4c8
BLAKE2b-256 bf15fd6db50d69c547e1fd558303c5c224b087a08b071221708bfaeae24d7e01

See more details on using hashes here.

File details

Details for the file icemac.songbeamer-1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: icemac.songbeamer-1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.10.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.7 CPython/2.7.15

File hashes

Hashes for icemac.songbeamer-1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5371e7c61fc4ccdbd767283d1d6f6013e0541cd88e8d990b75736a7df7a675c7
MD5 cb75cfc4c2758bb44fa5f4173ccaaf2f
BLAKE2b-256 04a22c657a0c3ba76b02d2b8797c07763399a969b5452117a34089ea2d9b9b71

See more details on using hashes here.

Supported by

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