1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
/*
* libSpiff - XSPF playlist handling library
*
* Copyright (C) 2006-2008, Sebastian Pipping / Xiph.Org Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* * 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.
*
* * Neither the name of the Xiph.Org Foundation nor the names of
* its contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "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.
*
* Sebastian Pipping, sping@xiph.org
*/
#include <spiff/Spiff.h>
#include <spiff/ProjectOpus/ProjectOpusPlaylistExtension.h>
#include <cstdio>
#include <cassert>
using namespace Spiff;
using namespace Spiff::Toolbox;
using namespace Spiff::ProjectOpus;
void
fillProps(SpiffProps & props) {
// NOTE: When writing please make URIs relative where it makes sense.
// Most importantly this applies to track locations, so the playlist
// files can be moved along with the files.
// SpiffToolbox::makeRelativeUri() can do that job for you.
// An example usage is shown below.
props.giveTitle(_PT("Now playing"), SpiffData::COPY);
props.giveAnnotation(_PT("Well, ..."), SpiffData::COPY);
props.giveCreator(_PT("libSpiff XSPF library"), SpiffData::COPY);
SpiffDateTime dateTime(2006, 8, 28, 11, 30, 11, 1, 0);
props.giveDate(&dateTime, SpiffData::COPY);
props.giveIdentifier(_PT("xspf:libSpiff:testId"), SpiffData::COPY);
props.giveImage(_PT("some/image.png"), SpiffData::COPY);
props.giveInfo(_PT("http://info/info"), SpiffData::COPY);
props.giveLicense(_PT("http://license/free/"), SpiffData::COPY);
props.giveLocation(_PT("http://playlist/home.xspf"), SpiffData::COPY);
props.setVersion(0);
props.giveAppendAttributionIdentifier(_PT("some:any/many"), SpiffData::COPY);
props.giveAppendAttributionLocation(_PT("test:pest/west"), SpiffData::COPY);
props.giveAppendLink(_PT("store:url"), SpiffData::COPY,
_PT("http://expensive/dot/com"), SpiffData::COPY);
props.giveAppendMeta(_PT("tag:meta:year"), SpiffData::COPY, _PT("2006"), SpiffData::COPY);
// Add a playlist extension
ProjectOpusPlaylistExtension playlistExtension;
playlistExtension.setNodeId(123);
playlistExtension.setType(TYPE_ALBUM);
props.giveAppendExtension(&playlistExtension, SpiffData::COPY);
}
void
fillTrack(SpiffTrack & track) {
// NOTE: When writing please make URIs relative where it makes sense.
// Most importantly this applies to track locations, so the playlist
// files can be moved along with the files.
// SpiffToolbox::makeRelativeUri() can do that job for you.
// An example usage is shown below.
track.giveAlbum(_PT("Phobia"), SpiffData::COPY);
track.giveCreator(_PT("Breaking Benjamin"), SpiffData::COPY);
track.giveTitle(_PT("Unknown Soldier"), SpiffData::COPY);
track.setTrackNum(10);
track.giveAppendIdentifier(_PT("id:bb:unknownSoldier"), SpiffData::COPY);
track.giveAppendLink(_PT("http://meta/key/uri/here"), SpiffData::COPY,
_PT("http://website"), SpiffData::COPY);
track.giveAppendLocation(
_PT("http://example.org/10_unknown_soldier.ogg"), SpiffData::COPY);
track.giveAppendMeta(_PT("tag:meta:year"), SpiffData::COPY, _PT("2006"), SpiffData::COPY);
track.giveAnnotation(_PT("Great song"), SpiffData::COPY);
track.setDuration(123000);
track.giveImage(
_PT("http://example.org/some/image.png"), SpiffData::COPY);
track.giveInfo(_PT("http://info/info"), SpiffData::COPY);
}
int
PORT_MAIN() {
XML_Char const * const baseUri = _PT("http://example.org/");
XML_Char const * const relativeFilename = _PT("TEST.xspf");
// Set up playlist props
SpiffProps props;
fillProps(props);
// Version 1, well-indented XML
SpiffIndentFormatter formatter;
SpiffWriter * const writer = SpiffWriter::makeWriter(
formatter, baseUri, SpiffWriter::EMBED_AS_XML_BASE);
assert(writer != NULL);
// Pre-register extension namespace so
// it can appear in <playlist> already
writer->registerNamespace(ProjectOpusPlaylistExtension
::namespaceKey, _PT("po"));
// Set up track
SpiffTrack track;
fillTrack(track);
// Add track two times
writer->addTrack(track);
writer->addTrack(track);
// Finish and write to file
int const res = writer->writeFile(relativeFilename);
delete writer;
if (res != SPIFF_WRITER_SUCCESS) {
PORT_PRINTF(_PT("Could not write to file.\n"));
return 1;
} else {
PORT_PRINTF(_PT("Everything fine.\n"));
return 0;
}
}
|