GithubHelp home page GithubHelp logo

xspf's Introduction

XSPF

A simple xspf generator for python.

To install, either run python setup.py install or copy xspf.py into your project.

Use

import xspf
x = xspf.Xspf()

x.title = "my playlist"
x.info = "http://example.org"
# You can set these attributes:
# title, creator, annotation, info, location, identifier, image, date, license

# add a link or meta tag
x.add_meta("http://example.org/key", "value")
x.add_link("http://foaf.example.org/namespace/version1",
           "http://socialnetwork.example.org/foaf/mary.rdfs")
# and delete them again if you want
x.del_meta("http://example.org/key")

# Add attributes at creation:
y = xspf.Xspf(title="playlist", creator="alastair")
# Or, with a dictionary
z = xspf.Xspf({"title": "playlist", "creator": "alastair"})

# Add tracks by creating a Track object
tr1 = xspf.Track()
tr1.title = ""
tr1.creator = ""
tr2 = xspf.Track(title="", creator="")
tr3 = xspf.Track({"title": "", "creator": ""})
# Tracks can have meta and link tags too
tr1.add_meta("duration", 1000)
x.add_track(tr1)
x.add_tracks([tr2, tr3])

# Or by passing the track information directly into add_track:
x.add_track(title="", creator="")
x.add_track({"title": "", "creator": ""})

# Finally, get the XML contents
print x.toXml()

If you don't like typing Xspf, we've helpfully aliased 'Spiff' to the same thing:

from xspf import Spiff
x = Spiff()
... etc

Reading xspf?

You might want to use xspfparser

You can load a playlist parsed with xspfparser, modify it, then write it out again.

result = xspfparser.parse(url)
x = Xspf(result['playlist'])
# we also support if you forget to deference playlist:
y = Xspf(result)
x.title = "New title"

print x.toXml()

Compatibility

xspf.py is targeted to python 2.7, 3.3, and 3.4. Other versions may work but their output is not guaranteed. For example, python 2.6 works but all tags are output with a fixed namespace prefix, ns0:. This is valid XSPF, but some applications don't like it (e.g. VLC).

License

Copyright 2011 Alastair Porter. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

xspf's People

Contributors

alastair avatar a-out-10-2 avatar malept avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.