summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2005-08-28 19:53:11 (UTC)
committer llornkcor <llornkcor>2005-08-28 19:53:11 (UTC)
commitf680479965bf13285a955873c48db47bd0c935d3 (patch) (side-by-side diff)
tree58945d235215685b316c00b62d951bd0b6d4df95
parent43217700cc9b23519776a27661fbf0c29a7d100d (diff)
downloadopie-f680479965bf13285a955873c48db47bd0c935d3.zip
opie-f680479965bf13285a955873c48db47bd0c935d3.tar.gz
opie-f680479965bf13285a955873c48db47bd0c935d3.tar.bz2
podcast! support.. 1st installment. needs improvements
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp332
-rw-r--r--core/multimedia/opieplayer/playlistwidget.h6
-rw-r--r--core/multimedia/opieplayer/rssparser.cpp201
-rw-r--r--core/multimedia/opieplayer/rssparser.h122
4 files changed, 559 insertions, 102 deletions
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp
index c0a0029..146dbb6 100644
--- a/core/multimedia/opieplayer/playlistwidget.cpp
+++ b/core/multimedia/opieplayer/playlistwidget.cpp
@@ -27,5 +27,10 @@
#include "audiowidget.h"
#include "videowidget.h"
+#include "rssparser.h"
+#include <qpe/process.h>
+
+#include <qvector.h>
+#include <qxml.h>
/* OPIE */
#include <qpe/qpeapplication.h>
@@ -491,5 +496,5 @@ void PlayListWidget::setDocument(const QString& fileref) {
void PlayListWidget::setDocumentEx(const QString& fileref) {
- odebug << "opieplayer receive "+fileref << oendl;
+ owarn << "opieplayer receive "+fileref << oendl;
clearList();
DocLnk lnk;
@@ -1064,4 +1069,10 @@ void PlayListWidget::openFile() {
filename = m3uFile;
}
+ if( filename.right(3) == "xml" ||
+ filename.find("rss" ) !=-1)
+ {
+ // readpodcast(filename );
+ downloadPodcast(filename);
+ } else {
lnk.setName( m3uFile ); //sets name
lnk.setFile( filename ); //sets file name
@@ -1070,4 +1081,5 @@ void PlayListWidget::openFile() {
writeCurrentM3u();
}
+ }
else if( filename.right( 3) == "m3u" ) {
readm3u( filename );
@@ -1075,4 +1087,8 @@ void PlayListWidget::openFile() {
} else if( filename.right(3) == "pls" ) {
readPls( filename );
+ } else if( filename.right(3) == "xml" ||
+ filename.find("rss" ) !=-1
+ ) {
+ readpodcast( filename );
} else {
lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name
@@ -1091,104 +1107,4 @@ void PlayListWidget::openFile() {
/*
-reads m3u and shows files/urls to playlist widget */
-void PlayListWidget::readm3u( const QString &filename ) {
- // odebug << "read m3u filename " + filename << oendl;
-
- Om3u *m3uList;
- QString s, name;
- m3uList = new Om3u( filename, IO_ReadOnly );
- m3uList->readM3u();
- DocLnk lnk;
- for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
- s = *it;
- // odebug << "reading "+ s << oendl;
- if(s.left(4)=="http") {
- lnk.setName( s ); //sets file name
- lnk.setIcon("opieplayer2/musicfile");
-
- // if(s.right(4) != '.' || s.right(5) != '.')
- if(s.right(4) != '.' || s.right(5) != '.' )
- if( s.right(1) != "/")
- lnk.setFile( s+"/"); //if url with no extension
- else
- lnk.setFile( s ); //sets file name
-
- } else {
- // if( QFileInfo( s ).exists() ) {
- lnk.setName( fullBaseName ( QFileInfo(s)));
- // if(s.right(4) == '.') {//if regular file
- if(s.left(1) != "/") {
- // odebug << "set link "+QFileInfo(filename).dirPath()+"/"+s << oendl;
- lnk.setFile( QFileInfo(filename).dirPath()+"/"+s);
- lnk.setIcon("SoundPlayer");
- } else {
- // odebug << "set link2 "+s << oendl;
- lnk.setFile( s);
- lnk.setIcon("SoundPlayer");
- }
- }
- d->selectedFiles->addToSelection( lnk );
- }
- Config config( "OpiePlayer" );
- config.setGroup( "PlayList" );
-
- config.writeEntry("CurrentPlaylist",filename);
- config.write();
- currentPlayList=filename;
-
-// m3uList->write();
- m3uList->close();
- if(m3uList) delete m3uList;
-
- d->selectedFiles->setSelectedItem( s);
- setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename)));
-
-}
-
-/*
-reads pls and adds files/urls to playlist */
-void PlayListWidget::readPls( const QString &filename ) {
-
- // odebug << "pls filename is " + filename << oendl;
- Om3u *m3uList;
- QString s, name;
- m3uList = new Om3u( filename, IO_ReadOnly );
- m3uList->readPls();
-
- for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
- s = *it;
- // s.replace( QRegExp( "%20" )," " );
- DocLnk lnk( s );
- QFileInfo f( s );
- QString name = fullBaseName ( f);
-
- if( name.left( 4 ) == "http" ) {
- name = s.right( s.length() - 7);
- } else {
- name = s;
- }
-
- name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
-
- lnk.setName( name );
- if( s.at( s.length() - 4) == '.') {// if this is probably a file
- lnk.setFile( s );
- } else { //if its a url
- if( name.right( 1 ).find( '/' ) == -1) {
- s += "/";
- }
- lnk.setFile( s );
- }
- lnk.setType( "audio/x-mpegurl" );
-
- lnk.writeLink();
- d->selectedFiles->addToSelection( lnk );
- }
-
- m3uList->close();
- if(m3uList) delete m3uList;
-}
-
-/*
writes current playlist to current m3u file */
void PlayListWidget::writeCurrentM3u() {
@@ -1463,2 +1379,216 @@ void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) {
}
}
+
+/*
+reads m3u and shows files/urls to playlist widget */
+void PlayListWidget::readm3u( const QString &filename ) {
+ // odebug << "read m3u filename " + filename << oendl;
+
+ Om3u *m3uList;
+ QString s, name;
+ m3uList = new Om3u( filename, IO_ReadOnly );
+ m3uList->readM3u();
+ DocLnk lnk;
+ for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
+ s = *it;
+ // odebug << "reading "+ s << oendl;
+ if(s.left(4)=="http") {
+ lnk.setName( s ); //sets file name
+ lnk.setIcon("opieplayer2/musicfile");
+
+ // if(s.right(4) != '.' || s.right(5) != '.')
+ if(s.right(4) != '.' || s.right(5) != '.' )
+ if( s.right(1) != "/")
+ lnk.setFile( s+"/"); //if url with no extension
+ else
+ lnk.setFile( s ); //sets file name
+
+ } else {
+ // if( QFileInfo( s ).exists() ) {
+ lnk.setName( fullBaseName ( QFileInfo(s)));
+ // if(s.right(4) == '.') {//if regular file
+ if(s.left(1) != "/") {
+ // odebug << "set link "+QFileInfo(filename).dirPath()+"/"+s << oendl;
+ lnk.setFile( QFileInfo(filename).dirPath()+"/"+s);
+ lnk.setIcon("SoundPlayer");
+ } else {
+ // odebug << "set link2 "+s << oendl;
+ lnk.setFile( s);
+ lnk.setIcon("SoundPlayer");
+ }
+ }
+ d->selectedFiles->addToSelection( lnk );
+ }
+ Config config( "OpiePlayer" );
+ config.setGroup( "PlayList" );
+
+ config.writeEntry("CurrentPlaylist",filename);
+ config.write();
+ currentPlayList=filename;
+
+// m3uList->write();
+ m3uList->close();
+ if(m3uList) delete m3uList;
+
+ d->selectedFiles->setSelectedItem( s);
+ setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename)));
+
+}
+
+/*
+reads pls and adds files/urls to playlist */
+void PlayListWidget::readPls( const QString &filename )
+{
+ // odebug << "pls filename is " + filename << oendl;
+ Om3u *m3uList;
+ QString s, name;
+ m3uList = new Om3u( filename, IO_ReadOnly );
+ m3uList->readPls();
+
+ for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
+ s = *it;
+ // s.replace( QRegExp( "%20" )," " );
+ DocLnk lnk( s );
+ QFileInfo f( s );
+ QString name = fullBaseName ( f);
+
+ if( name.left( 4 ) == "http" ) {
+ name = s.right( s.length() - 7);
+ } else {
+ name = s;
+ }
+
+ name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
+
+ lnk.setName( name );
+ if( s.at( s.length() - 4) == '.') {// if this is probably a file
+ lnk.setFile( s );
+ } else { //if its a url
+ if( name.right( 1 ).find( '/' ) == -1) {
+ s += "/";
+ }
+ lnk.setFile( s );
+ }
+ lnk.setType( "audio/x-mpegurl" );
+
+ lnk.writeLink();
+ d->selectedFiles->addToSelection( lnk );
+ }
+
+ m3uList->close();
+ if(m3uList) delete m3uList;
+}
+
+bool PlayListWidget::readpodcast( const QString &filename )
+{
+ QStringList latestPodCast;
+ //download url
+ qWarning("podcast "+filename);
+ QFileInfo info(filename);
+ if (info.size() > 0) {
+ bool result = false;
+ // qWarning("parseDoc " + feedFile.name() );
+ QFile file(filename);
+ QXmlInputSource source( file);
+ QXmlSimpleReader reader;
+ // reader.setFeature("http://xml.org/sax/features/namespaces", true);
+ // reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
+ // reader.setFeature("http://trolltech.com/xml/features/report-whitespace-only-CharData", false);
+
+ reader.setContentHandler( &rssHandler);
+ reader.setErrorHandler( &rssHandler);
+ result = reader.parse( source);
+ if (!result) {
+ QMessageBox::critical(0, "Error", tr("<p>Error unable to parse file.</p>"));
+// qWarning("Error unable to parse file\n%s", handler.errorMessage.local8Bit().data());
+ return false;
+ } else {
+ int size = rssHandler.getItems().size();
+ qWarning( rssHandler.getChannelInfo().join("\n"));
+
+ for(int i = 0; i < size; i++) {
+ QList<QStringList> attributesList = rssHandler.getItems().at(i)->attributes;
+ QStringList *sList;
+ QStringList attList;
+ for(sList = attributesList.first(); sList !=0; sList = attributesList.next()) {
+ for( QStringList::Iterator it = sList->begin(); it != sList->end(); ++it ) {
+ attList << (*it);
+ }
+ if(i == 0) { //this assumes that the latest is the first
+ latestPodCast << attList[2]; //this is our mp3 url
+ latestPodCast << rssHandler.getItems().at(i)->title;
+ latestPodCast << rssHandler.getItems().at(i)->description;
+ latestPodCast << rssHandler.getItems().at(i)->pubdate;
+ }
+ }
+ }
+ QString s = latestPodCast[0]; //this is our mp3 url
+
+// http://www.davesipaq.com/podcast.xml
+ DocLnk lnk( s );
+ QFileInfo f( s );
+ QString name = fullBaseName ( f);
+
+ if( name.left( 4 ) == "http" ) {
+ name = s.right( s.length() - 7);
+ } else {
+ name = s;
+ }
+
+ name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
+
+ lnk.setName( name );
+ if( s.at( s.length() - 4) == '.') {// if this is probably a file
+ lnk.setFile( s );
+ } else { //if its a url
+ if( name.right( 1 ).find( '/' ) == -1) {
+ s += "/";
+ }
+ lnk.setFile( s );
+ }
+ lnk.setType( "audio/x-mpegurl" );
+
+ lnk.writeLink();
+ d->selectedFiles->addToSelection( lnk );
+
+ }
+ } else {
+ QMessageBox::critical( 0, "Qtopia Rss", tr("<p>Sorry, could not find the requested document.</p>"));
+ return false;
+ }
+
+ qWarning( latestPodCast.join("\n"));
+
+ return true;
+}
+
+bool PlayListWidget::downloadPodcast(const QString &url)
+{
+ qWarning("download "+url);
+ QString localFile;
+ localFile = url;
+ localFile = localFile.mid(7, localFile.length()-7);
+
+ localFile = localFile.replace(QRegExp("/"), "_");
+ localFile = localFile.replace(QRegExp("&"), "_");
+ localFile = localFile.replace(QRegExp("="), "_");
+ localFile = localFile.replace(QRegExp("\\?"), "_");
+ localFile = localFile.replace(QRegExp("@"), "_");
+ localFile = QDir::homeDirPath()+"/Settings/"+localFile;
+
+#warning FIXME
+ QString cmd;
+ cmd = "wget ";
+ cmd +=" -O ";
+ cmd += localFile + " " + url;
+ qWarning(cmd);
+ system(cmd.latin1());
+// Process ipkg_status(QStringList()<< "wget" <<"-O" << localFile << url );
+ // QString out;
+// bool r = ipkg_status.exec("",out);
+// if(r)
+// qWarning(out);
+ readpodcast(localFile);
+ return true;
+}
+
diff --git a/core/multimedia/opieplayer/playlistwidget.h b/core/multimedia/opieplayer/playlistwidget.h
index 0c0e367..6e9acc0 100644
--- a/core/multimedia/opieplayer/playlistwidget.h
+++ b/core/multimedia/opieplayer/playlistwidget.h
@@ -30,4 +30,5 @@
#include "om3u.h"
+#include "rssparser.h"
/* #include <qtimer.h> */
@@ -78,4 +79,5 @@ void keyReleaseEvent( QKeyEvent *e);
void keyPressEvent( QKeyEvent *e);
private:
+ RssParser rssHandler;
int defaultSkinIndex;
bool audioScan, videoScan;
@@ -84,5 +86,5 @@ private:
void readm3u(const QString &);
void readPls(const QString &);
-
+ bool readpodcast(const QString&);
void initializeStates();
@@ -127,4 +129,6 @@ private slots:
void listDelete();
+ bool downloadPodcast(const QString &);
+
protected slots:
/* void cancelMenuTimer(); */
diff --git a/core/multimedia/opieplayer/rssparser.cpp b/core/multimedia/opieplayer/rssparser.cpp
new file mode 100644
index 0000000..ec81409
--- a/dev/null
+++ b/core/multimedia/opieplayer/rssparser.cpp
@@ -0,0 +1,201 @@
+/***************************************************************************
+ * Copyright (C) 2004 by ljp *
+ * lpotter@trolltech.com *
+ * *
+ * This program may be distributed under the terms of the Q Public *
+ * License as defined by Trolltech AS of Norway and appearing in the *
+ * file LICENSE.QPL included in the packaging of this file. *
+ * *
+ * 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. *
+ ***************************************************************************/
+#include "rssparser.h"
+
+#include <qstring.h>
+#include <qmessagebox.h>
+#include <qlist.h>
+
+RssParser::RssParser()
+{
+ isItem = false;
+}
+
+RssParser::~RssParser()
+{
+ int size = channel->rssItems.size();
+ for (int i = 0; i < size; i ++) {
+ delete channel->rssItems.at(i);
+ }
+ delete channel;
+}
+
+bool RssParser::startElement( const QString &, const QString & /*localName*/,const QString & qName, const QXmlAttributes &atts)
+{
+ if( qName == "rss") {
+ channel = new rssChannel();
+ channel->rssItems.resize( 0);
+ return true;
+ }
+// qWarning(qName + " %d",atts.length());
+ if(qName == "item") {
+ isItem = true;
+ tag = NewItemTag;
+ Item = new rssItem();
+ }
+
+ if(qName == "image") {
+ tag = NewItemTag;
+ image = new rssImage();
+ }
+
+ if(qName == "title") {
+ tag = TitleTag;
+ }
+
+ if (qName == "description") {
+ tag = DescriptionTag;
+ }
+
+ if( qName == "link") {
+ tag = LinkTag;
+ }
+
+ if( qName == "pubDate") {
+ tag = pubDateTag;
+ }
+
+// if( qName == "enclosure") {
+// tag = EnclosureTag;
+// }
+
+ if(atts.length() > 0/* && tag == EnclosureTag*/) {
+// qWarning(qName +" attributes %d", atts.length());
+// Item->attributes << qName;
+// for(int i=0; i < atts.length(); i++) {
+// Item->attributes << atts.qName(i) << atts.value(atts.qName(i));
+// }
+
+ QStringList *sList;
+ sList = new QStringList();
+ sList->append(qName);
+ for(int i=0; i < atts.length(); i++) {
+ sList->append( atts.qName(i));
+ sList->append( atts.value(atts.qName(i)));
+ }
+ if(isItem)
+ Item->attributes.append( sList);
+ else
+ channel->attributes.append( sList);
+ }
+
+ return true;
+}
+
+bool RssParser::endElement( const QString &, const QString &, const QString & qName )
+{
+ tag = NoneTag;
+ if(qName == "item") {
+ isItem = false;
+ int size = channel->rssItems.size();
+ channel->rssItems.resize( size + 1);
+ channel->rssItems.insert( channel->rssItems.size() - 1, Item);
+ }
+ if(qName == "channel") {
+// isItem = false;
+// int size = channel->rssItems.size();
+// channel->rssItems.resize( size + 1);
+// channel->rssItems.insert( channel->rssItems.size() - 1, Item);
+ }
+ return true;
+}
+
+bool RssParser::characters( const QString & ch )
+{
+ if(!ch.isEmpty()) {
+ if(isItem) {
+// qWarning("ch "+ch);
+ switch(tag) {
+ case NewItemTag:
+ break;
+ case TitleTag:
+ Item->title = ch;
+ break;
+ case DescriptionTag:
+ Item->description = ch;
+ break;
+ case LinkTag:
+ Item->link = ch;
+ break;
+ case pubDateTag:
+ Item->pubdate = ch;
+ break;
+ case NoneTag:
+ break;
+ };
+ } else { //channel
+ switch(tag) {
+ case TitleTag:
+ channel->title = ch;
+ break;
+ case DescriptionTag:
+ channel->description = ch;
+ break;
+ case LinkTag:
+ channel->link = ch;
+ break;
+ case pubDateTag:
+ channel->pubdate = ch;
+ break;
+ case NoneTag:
+ case NewItemTag:
+ break;
+ };
+ }
+ }
+ return true;
+}
+
+bool RssParser::warning(const QXmlParseException &e)
+{
+ errorMessage = e.message();
+// QMessageBox::message("Warning",tr("<p>Sorry, could not find the requested document.</p>"));
+ qWarning("Warning " + errorMessage);
+ return true;
+}
+
+bool RssParser::error(const QXmlParseException &e)
+{
+ errorMessage = e.message();
+// QMessageBox::message("Error", "<p>" + errorMessage + "</p>");
+ qWarning("Error: " + errorMessage);
+ return true;
+}
+
+bool RssParser::fatalError(const QXmlParseException &e)
+{
+ errorMessage = e.message();
+// errorMessage += " line: " + e.lineNumber();
+// errorMessage += " col: " + e.columnNumber();
+ qWarning("Fatal Error: "+ errorMessage);
+ qWarning("line %d, col %d\n", e.lineNumber(), e.columnNumber());
+// QMessageBox::message("Fatal Error", errorMessage );
+ return false;
+}
+
+QVector<rssItem> &RssParser::getItems()
+{
+ return channel->rssItems;
+}
+
+int RssParser::getSize()
+{
+ return channel->rssItems.size();
+}
+
+QStringList RssParser::getChannelInfo()
+{
+ QStringList ch;
+ ch << channel->title << channel->description << channel->link << channel->pubdate << channel->copyright << channel->language;
+ return ch;
+}
diff --git a/core/multimedia/opieplayer/rssparser.h b/core/multimedia/opieplayer/rssparser.h
new file mode 100644
index 0000000..669ece5
--- a/dev/null
+++ b/core/multimedia/opieplayer/rssparser.h
@@ -0,0 +1,122 @@
+/***************************************************************************
+ * Copyright (C) 2004 by ljp *
+ * lpotter@trolltech.com *
+ * *
+ * This program may be distributed under the terms of the Q Public *
+ * License as defined by Trolltech AS of Norway and appearing in the *
+ * file LICENSE.QPL included in the packaging of this file. *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+/* RSS required tags:
+ title,link,description
+*/
+/* RSS optional tags:
+ language,copyright,managingEditor,webMaster,pubDate,lastBuildDate,category,generator,docs,cloud,ttl,
+ image,rating,textInput,skipHours,skipDays
+*/
+/*
+ podcast tags
+ <rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd" version="2.0">
+ title,link,copyright,pubDate,enclosure,guid,itunes:author,itunes:block,itunes:category,itunes:duration,itunes:explicit,itunes:keywords,itunes:owner,itunes:subtitle,itunes:summary
+*/
+
+#ifndef RSSPARSER_H
+#define RSSPARSER_H
+
+#include <qxml.h>
+#include <qstringlist.h>
+#include <qvector.h>
+#include <qstringlist.h>
+#include <qlist.h>
+
+class QString;
+
+class rssImage {
+public:
+ QString url;
+ QString title;
+ int width;
+ int height;
+ QString description;
+};
+
+class rssItem {
+ public:
+ QString title;
+ QString description;
+ QString link;
+ QString pubdate;
+ QVector <rssImage> rssImageTags;
+ QList<QStringList> attributes; //tags with atttributes
+};
+
+class rssChannel {
+ public:
+ QString title;
+ QString description;
+ QString link;
+ QString pubdate;
+ QString copyright;
+ QString language;
+ QVector <rssImage> rssImageTags;
+ QVector <rssItem> rssItems;
+ QList<QStringList> attributes; //tags with atttributes
+};
+
+class RssParser : public QXmlDefaultHandler
+{
+public:
+ RssParser();
+ ~RssParser();
+ QString errorMessage;
+
+ QVector<rssItem> &getItems();
+ QStringList getChannelInfo();
+ int getSize();
+
+private:
+
+ enum Tag {
+ NoneTag = 0,
+ TitleTag = 1,
+ NewItemTag = 2,
+ DescriptionTag = 3,
+ LinkTag = 4,
+ pubDateTag = 5,
+/*
+ ImageTag = 6,
+ UrlTag = 7,
+ WidthTag = 8,
+ HeightTag = 9,
+ */
+ };
+ Tag tag;
+
+// QVector <rssItem> rssItems;
+ QStringList channelInfo;
+ rssItem *Item;
+ rssChannel *channel;
+ rssImage *image;
+
+ bool isItem;
+ QStringList tokenNames;
+ QString htmlString;
+
+protected:
+
+ bool startElement( const QString&, const QString&, const QString& ,const QXmlAttributes& );
+ bool endElement( const QString&, const QString&, const QString& );
+ bool characters( const QString &);
+
+ bool warning(const QXmlParseException &);
+ bool error(const QXmlParseException &);
+ bool fatalError(const QXmlParseException &);
+
+ QString itemTitle, itemLink, itemDescription;
+};
+
+#endif