00001 /* 00002 Copyright (C) 2008-2009 Tim Fechtner < urwald at users dot sourceforge dot net > 00003 00004 This program is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU General Public License as 00006 published by the Free Software Foundation; either version 2 of 00007 the License or (at your option) version 3 or any later version 00008 accepted by the membership of KDE e.V. (or its successor approved 00009 by the membership of KDE e.V.), which shall act as a proxy 00010 defined in Section 14 of version 3 of the license. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #include "icecast_internalthread.h" 00022 00023 #include <QFile> 00024 #include <KIO/NetAccess> 00025 00026 icecast_internalThread::icecast_internalThread() 00027 { 00028 } 00029 00030 icecast_internalThread::~icecast_internalThread() 00031 { 00032 wait(); 00033 } 00034 00035 void icecast_internalThread::run() 00036 { 00037 // variables 00038 QXmlStreamReader xml; 00039 QFile yp; 00040 QString tmpFile; 00041 00042 // code 00043 KIO::NetAccess::download(KUrl("http://dir.xiph.org/yp.xml"), tmpFile, 0); 00044 yp.setFileName(tmpFile); 00045 yp.open(QIODevice::ReadOnly); 00046 xml.setDevice(&yp); 00047 streamList.clear(); 00048 while (!xml.atEnd()) { 00049 xml.readNext(); 00050 if (xml.isStartElement() && (xml.name() == "entry")) { 00051 readStreamEntry(xml); 00052 }; 00053 }; 00054 KIO::NetAccess::removeTempFile(tmpFile); 00055 emit streamlist_ready(streamList); 00056 } 00057 00058 void icecast_internalThread::readStreamEntry(QXmlStreamReader & reader) 00059 { 00060 streamDirectoryEntry_stream *streamEntry = new streamDirectoryEntry_stream(); 00061 while (!((reader.isEndElement() && (reader.name() == "entry")) || reader.atEnd())) { 00062 reader.readNext(); 00063 if (reader.isStartElement()) { 00064 if (reader.name() == "server_name") { 00065 streamEntry->setName(reader.readElementText()); 00066 } else if (reader.name() == "listen_url") { 00067 streamEntry->setValue(reader.readElementText()); 00068 } else if (reader.name() == "server_type") { 00069 QString m_servertype = reader.readElementText(); 00070 if (m_servertype == "audio/aacp") { 00071 streamEntry->streamType = streamDirectoryEntry_stream::aac_plus; 00072 } else if (m_servertype == "audio/aac") { 00073 streamEntry->streamType = streamDirectoryEntry_stream::aac; 00074 } else if (m_servertype == "audio/mpeg") { 00075 streamEntry->streamType = streamDirectoryEntry_stream::mp3; 00076 } else if (m_servertype == "application/ogg") { 00077 streamEntry->streamType = streamDirectoryEntry_stream::ogg; 00078 } else if (m_servertype == "video/nsv") { 00079 streamEntry->streamType = streamDirectoryEntry_stream::nsv; 00080 } else { 00081 streamEntry->streamType = streamDirectoryEntry_stream::unknown; 00082 }; 00083 } else if (reader.name() == "bitrate") { 00084 streamEntry->bitrate = reader.readElementText().toULongLong(); 00085 if (streamEntry->bitrate >= 1024) { 00086 // sometimes, the bitrate is given in bit/s instead of kbit/s 00087 // Furthermore, it's unclear if SI prefixes or binary prefixes 00088 // are used. The calculation we do here is not necesarrily correct, 00089 // but seems to work quite well in practice. 00090 streamEntry->bitrate = streamEntry->bitrate / 1024; 00091 }; 00092 } else if (reader.name() == "current_song") { 00093 streamEntry->currentlyPlaying = !(reader.readElementText().trimmed().isEmpty()); 00094 }; 00095 // "channels" and "samplerate" are also elements that are present, but I don't know 00096 // exactly what they mean. Furthermore, they seem to be always 0. 00097 }; 00098 }; 00099 streamList.append(streamEntry); 00100 }