[vlmc-devel] commit: YouTube XML feed parser. Currently used for parsing VideoID from the XML data which is returned when a valid video file is uploaded . (Rohit Yadav )
git at videolan.org
git at videolan.org
Tue Aug 24 11:11:20 CEST 2010
vlmc | branch: master | Rohit Yadav <rohityadav89 at gmail.com> | Mon Aug 23 22:17:30 2010 +0530| [98c9bb7acf27c5d4ed8223e2634ef55caf17711a] | committer: Hugo Beauzée-Luyssen
YouTube XML feed parser. Currently used for parsing VideoID from the XML data which is returned when a valid video file is uploaded.
Signed-off-by: Hugo Beauzée-Luyssen <beauze.h at gmail.com>
> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=98c9bb7acf27c5d4ed8223e2634ef55caf17711a
---
src/Services/YouTube/YouTubeFeedParser.cpp | 123 ++++++++++++++++++++++++++++
src/Services/YouTube/YouTubeFeedParser.h | 44 ++++++++++
2 files changed, 167 insertions(+), 0 deletions(-)
diff --git a/src/Services/YouTube/YouTubeFeedParser.cpp b/src/Services/YouTube/YouTubeFeedParser.cpp
new file mode 100644
index 0000000..349b934
--- /dev/null
+++ b/src/Services/YouTube/YouTubeFeedParser.cpp
@@ -0,0 +1,123 @@
+/*****************************************************************************
+ * YouTubeFeedParser.cpp: YouTube XML feed parser
+ *****************************************************************************
+ * Copyright (C) 2010 VideoLAN
+ *
+ * Authors: Rohit Yadav <rohityadav89 AT gmail.com>
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "YouTubeFeedParser.h"
+#include <QString>
+#include <QStringList>
+
+#include <QDebug>
+
+YouTubeFeedParser::YouTubeFeedParser( const QString& xml )
+ : QXmlStreamReader( xml )
+{
+ m_videoId = "";
+}
+
+bool
+YouTubeFeedParser::read()
+{
+ while( !atEnd() )
+ {
+ readNext();
+ if( isStartElement() )
+ {
+ if( name() == "entry")
+ readFeed();
+ else
+ raiseError( QObject::tr( "The XMLStream is not a valid YouTube Feed" ) );
+ }
+ }
+
+ return !error();
+}
+
+void
+YouTubeFeedParser::readUnknownElement()
+{
+ Q_ASSERT( isStartElement() );
+
+ while( !atEnd() )
+ {
+ readNext();
+
+ if( isEndElement() )
+ break;
+
+ if( isStartElement() )
+ readUnknownElement();
+ }
+}
+
+void
+YouTubeFeedParser::readFeed()
+{
+ Q_ASSERT( isStartElement() && name() == "entry" );
+
+ while( !atEnd() )
+ {
+ readNext();
+
+ if( isEndElement() )
+ break;
+
+ if( isStartElement() )
+ {
+ if( name() == "link" )
+ readLinks();
+ else
+ readUnknownElement();
+ }
+ }
+}
+
+void
+YouTubeFeedParser::readLinks()
+{
+ Q_ASSERT( isStartElement() && name() == "link" );
+
+ while( !atEnd() )
+ {
+ if( isEndElement() )
+ break;
+
+ if( isStartElement() && name() == "link" )
+ {
+ QXmlStreamAttributes attrs = attributes();
+ QStringRef rel = attrs.value("rel");
+ QStringRef type = attrs.value("type");
+ QStringRef href = attrs.value("href");
+
+ if( rel.toString() == "self" )
+ {
+ m_videoId = href.toString();
+ m_videoId = m_videoId.split("uploads/").at(1);
+ }
+ }
+ readNext();
+ }
+}
+
+const QString&
+YouTubeFeedParser::getVideoId()
+{
+ return m_videoId;
+}
diff --git a/src/Services/YouTube/YouTubeFeedParser.h b/src/Services/YouTube/YouTubeFeedParser.h
new file mode 100644
index 0000000..730beb2
--- /dev/null
+++ b/src/Services/YouTube/YouTubeFeedParser.h
@@ -0,0 +1,44 @@
+/******************************************************************************
+ * YouTubeFeedParser.h: YouTube XML feed parser
+ ******************************************************************************
+ * Copyright (C) 2010 VideoLAN
+ *
+ * Authors: Rohit Yadav <rohityadav89 AT gmail.com>
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef YOUTUBEFEEDPARSER_H
+#define YOUTUBEFEEDPARSER_H
+
+#include <QXmlStreamReader>
+
+class YouTubeFeedParser : public QXmlStreamReader
+{
+ public:
+ YouTubeFeedParser( const QString &xml );
+
+ bool read();
+ const QString& getVideoId();
+
+ private:
+ void readFeed();
+ void readLinks();
+ void readUnknownElement();
+
+ QString m_videoId;
+};
+
+#endif // YOUTUBEFEEDPARSER_H
More information about the Vlmc-devel
mailing list