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 146 147 148 149 150 151 152 153 154 155 156 157
|
/*******************************************************************************
* Goggles Audio Player Library *
********************************************************************************
* Copyright (C) 2010-2021 by Sander Jansen. All Rights Reserved *
* --- *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see http://www.gnu.org/licenses. *
********************************************************************************/
#include "ap_defs.h"
#include "ap_common.h"
#include "ap_xml_parser.h"
#include "ap_reader_plugin.h"
namespace ap {
class XSPFParser : public XmlParser{
public:
FXStringList files;
FXString title;
protected:
FXint elem;
protected:
FXint begin(const FXchar *,const FXchar**) override;
void data(const FXchar *,FXint len) override;
void end(const FXchar *) override;
public:
enum {
Elem_Playlist = Elem_Last,
Elem_Playlist_Title,
Elem_Playlist_TrackList,
Elem_Playlist_TrackList_Track,
Elem_Playlist_TrackList_Track_Location,
};
public:
XSPFParser();
~XSPFParser();
};
XSPFParser::XSPFParser() : elem(Elem_None) {
}
XSPFParser::~XSPFParser(){
}
FXint XSPFParser::begin(const FXchar * element,const FXchar **/* attributes*/){
switch(node()) {
case Elem_None:
{
if (FXString::compare(element,"playlist")==0)
return Elem_Playlist;
} break;
case Elem_Playlist:
{
if (FXString::compare(element,"title")==0)
return Elem_Playlist_Title;
else if (FXString::compare(element,"trackList")==0)
return Elem_Playlist_TrackList;
} break;
case Elem_Playlist_TrackList:
{
if (FXString::compare(element,"track")==0)
return Elem_Playlist_TrackList_Track;
} break;
case Elem_Playlist_TrackList_Track:
{
if (FXString::compare(element,"location")==0)
return Elem_Playlist_TrackList_Track_Location;
} break;
default: return 0; // skip
}
return 0;
}
void XSPFParser::data(const FXchar* str,FXint len){
switch(node()) {
case Elem_Playlist_Title: title.assign(str,len); break;
case Elem_Playlist_TrackList_Track_Location:
{
FXString url(str,len);
files.append(url);
} break;
}
}
void XSPFParser::end(const FXchar*) {
}
class XSPFReader : public TextReader {
protected:
FXStringList uri;
public:
XSPFReader(InputContext*);
ReadStatus process(Packet*) override;
FXbool init(InputPlugin*) override;
FXuchar format() const override { return Format::XSPF; };
FXbool redirect(FXStringList & u) override { u=uri; return true; }
virtual ~XSPFReader();
};
XSPFReader::XSPFReader(InputContext*ctx) : TextReader(ctx) {
}
XSPFReader::~XSPFReader(){
}
FXbool XSPFReader::init(InputPlugin*plugin) {
TextReader::init(plugin);
uri.clear();
return true;
}
ReadStatus XSPFReader::process(Packet*packet) {
if (TextReader::process(packet)==ReadDone) {
FXString title;
ap_parse_xspf(textbuffer,uri,title);
if (uri.no())
return ReadRedirect;
else
return ReadDone;
}
return ReadError;
}
ReaderPlugin * ap_xspf_reader(InputContext * ctx) {
return new XSPFReader(ctx);
}
void ap_parse_xspf(const FXString & data,FXStringList & mrl,FXString & title) {
XSPFParser xspf;
if (xspf.parse(data)) {
mrl=xspf.files;
title=xspf.title;
}
}
}
|