]> git.sesse.net Git - kdenlive/commitdiff
Preliminary support for importing clips from archive.org (not working yet)
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 3 Jan 2012 20:37:27 +0000 (21:37 +0100)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 3 Jan 2012 20:37:27 +0000 (21:37 +0100)
src/utils/CMakeLists.txt
src/utils/abstractservice.h
src/utils/archiveorg.cpp [new file with mode: 0644]
src/utils/archiveorg.h [new file with mode: 0644]
src/utils/resourcewidget.cpp

index 8c80687ee07b6e29599c53a858f8237d5ffedd96..18ce9f920ae4f2ed8e022c8f458ad0a1c77a83ec 100644 (file)
@@ -3,6 +3,7 @@ set(kdenlive_SRCS
   utils/abstractservice.cpp
   utils/freesound.cpp
   utils/openclipart.cpp
+  utils/archiveorg.cpp
   utils/resourcewidget.cpp
   PARENT_SCOPE
 )
index 52c3026ae6df656a7712fbd135702285008b3a3a..5b03c6404c243fd010ad570e239d173b251e3dd8 100644 (file)
@@ -38,7 +38,7 @@ const int idRole = Qt::UserRole + 9;
 const int licenseRole = Qt::UserRole + 10;
 const int descriptionRole = Qt::UserRole + 11;
 
-enum SERVICETYPE { NOSERVICE = 0, FREESOUND = 1, OPENCLIPART = 2 };
+enum SERVICETYPE { NOSERVICE = 0, FREESOUND = 1, OPENCLIPART = 2, ARCHIVEORG = 3 };
 
 struct OnlineItemInfo {
     QString imagePreview;
diff --git a/src/utils/archiveorg.cpp b/src/utils/archiveorg.cpp
new file mode 100644 (file)
index 0000000..af4a977
--- /dev/null
@@ -0,0 +1,204 @@
+/***************************************************************************
+ *   Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *                                                                         *
+ *   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 "archiveorg.h"
+
+#include <QPushButton>
+#include <QSpinBox>
+#include <QListWidget>
+#include <QDomDocument>
+
+#include <KDebug>
+#include "kdenlivesettings.h"
+#include <kio/job.h>
+#include <KLocale>
+
+#ifdef USE_QJSON
+#include <qjson/parser.h>
+#endif
+
+ArchiveOrg::ArchiveOrg(QListWidget *listWidget, QObject *parent) :
+        AbstractService(listWidget, parent),
+        m_previewProcess(new QProcess)
+{
+    serviceType = ARCHIVEORG;
+    hasPreview = true;
+    hasMetadata = true;
+    //connect(m_previewProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(slotPreviewStatusChanged(QProcess::ProcessState)));
+}
+
+ArchiveOrg::~ArchiveOrg()
+{
+    if (m_previewProcess) delete m_previewProcess;
+}
+
+void ArchiveOrg::slotStartSearch(const QString searchText, int page)
+{
+    m_listWidget->clear();
+    QString uri = "http://www.archive.org/advancedsearch.php?q=";
+    uri.append(searchText);
+    uri.append("%20AND%20mediatype:MovingImage");
+    uri.append("&rows=30");
+    if (page > 1) uri.append("&page=" + QString::number(page));
+    uri.append("&output=json"); //&callback=callback&save=yes#raw");
+
+    KJob* resolveJob = KIO::storedGet( KUrl(uri), KIO::NoReload, KIO::HideProgressInfo );
+    connect( resolveJob, SIGNAL( result( KJob* ) ), this, SLOT( slotShowResults( KJob* ) ) );
+}
+
+
+void ArchiveOrg::slotShowResults(KJob* job)
+{
+    if (job->error() != 0 ) return;
+    m_listWidget->blockSignals(true);
+    KIO::StoredTransferJob* storedQueryJob = static_cast<KIO::StoredTransferJob*>( job );
+#ifdef USE_QJSON
+    QJson::Parser parser;
+    bool ok;
+    //kDebug()<<"// GOT RESULT: "<<m_result;
+    QVariant data = parser.parse(storedQueryJob->data(), &ok);
+    QVariant sounds;
+    if (data.canConvert(QVariant::Map)) {
+        QMap <QString, QVariant> map = data.toMap();
+        QMap<QString, QVariant>::const_iterator i = map.constBegin();
+        while (i != map.constEnd()) {
+            if (i.key() == "response") {
+                sounds = i.value();
+                if (sounds.canConvert(QVariant::Map)) {
+                    QMap <QString, QVariant> soundsList = sounds.toMap();
+                    if (soundsList.contains("numFound")) emit searchInfo(i18np("Found %1 result", "Found %1 results", soundsList.value("numFound").toInt()));
+                    QList <QVariant> resultsList;
+                    if (soundsList.contains("docs")) {
+                        resultsList = soundsList.value("docs").toList();
+                    }
+                    
+                    for (int j = 0; j < resultsList.count(); j++) {
+                        if (resultsList.at(j).canConvert(QVariant::Map)) {
+                            QMap <QString, QVariant> soundmap = resultsList.at(j).toMap();
+                            if (soundmap.contains("title")) {
+                                QListWidgetItem *item = new   QListWidgetItem(soundmap.value("title").toString(), m_listWidget);
+                                item->setData(descriptionRole, soundmap.value("description").toString());
+                                item->setData(idRole, soundmap.value("identifier").toString());                        
+                                item->setData(licenseRole, soundmap.value("licenseurl").toString());                        
+                            }
+                        }
+                    }
+                }
+            }
+            ++i;
+        }
+    }
+#endif  
+    m_listWidget->blockSignals(false);
+    m_listWidget->setCurrentRow(0);
+}
+    
+
+OnlineItemInfo ArchiveOrg::displayItemDetails(QListWidgetItem *item)
+{
+    OnlineItemInfo info;
+    m_metaInfo.clear();
+    if (!item) {
+        return info;
+    }
+    info.itemPreview = item->data(previewRole).toString();
+    info.itemDownload = item->data(downloadRole).toString();
+    info.itemId = item->data(idRole).toInt();
+    info.itemName = item->text();
+    info.infoUrl = item->data(infoUrl).toString();
+    info.author = item->data(authorRole).toString();
+    info.authorUrl = item->data(authorUrl).toString();
+    m_metaInfo.insert(i18n("Duration"), item->data(durationRole).toString());
+    info.license = item->data(licenseRole).toString();
+    info.description = item->data(descriptionRole).toString();
+    
+    QString extraInfoUrl = item->data(infoData).toString();
+    if (!extraInfoUrl.isEmpty()) {
+        KJob* resolveJob = KIO::storedGet( KUrl(extraInfoUrl), KIO::NoReload, KIO::HideProgressInfo );
+        connect( resolveJob, SIGNAL( result( KJob* ) ), this, SLOT( slotParseResults( KJob* ) ) );
+    }
+    info.imagePreview = item->data(imageRole).toString();
+    return info;
+}
+
+
+void ArchiveOrg::slotParseResults(KJob* job)
+{
+#ifdef USE_QJSON
+    KIO::StoredTransferJob* storedQueryJob = static_cast<KIO::StoredTransferJob*>( job );
+    QJson::Parser parser;
+    bool ok;
+    QVariant data = parser.parse(storedQueryJob->data(), &ok);
+    if (data.canConvert(QVariant::Map)) {
+        QMap <QString, QVariant> infos = data.toMap();
+        //if (m_currentId != infos.value("id").toInt()) return;
+        if (infos.contains("samplerate"))
+            m_metaInfo.insert(i18n("Samplerate"), QString::number(infos.value("samplerate").toDouble()));
+        if (infos.contains("channels"))
+            m_metaInfo.insert(i18n("Channels"), QString::number(infos.value("channels").toInt()));
+        if (infos.contains("filesize")) {
+            KIO::filesize_t fSize = infos.value("filesize").toDouble();
+            m_metaInfo.insert(i18n("File size"), KIO::convertSize(fSize));
+        }
+        if (infos.contains("description")) {
+            m_metaInfo.insert("description", infos.value("description").toString());
+        }
+        if (infos.contains("license")) {
+            m_metaInfo.insert("license", infos.value("license").toString());
+        }
+    }
+    emit gotMetaInfo(m_metaInfo);
+#endif    
+}
+
+
+bool ArchiveOrg::startItemPreview(QListWidgetItem *item)
+{    
+    if (!item) return false;
+    QString url = item->data(previewRole).toString();
+    if (url.isEmpty()) return false;
+    if (m_previewProcess && m_previewProcess->state() != QProcess::NotRunning) {
+        m_previewProcess->close();
+    }
+    m_previewProcess->start("ffplay", QStringList() << url << "-nodisp");
+    return true;
+}
+
+
+void ArchiveOrg::stopItemPreview(QListWidgetItem *item)
+{    
+    if (m_previewProcess && m_previewProcess->state() != QProcess::NotRunning) {
+        m_previewProcess->close();
+    }
+}
+
+QString ArchiveOrg::getExtension(QListWidgetItem *item)
+{
+    if (!item) return QString();
+    return QString("*.") + item->text().section('.', -1);
+}
+
+
+QString ArchiveOrg::getDefaultDownloadName(QListWidgetItem *item)
+{
+    if (!item) return QString();
+    return item->text();
+}
diff --git a/src/utils/archiveorg.h b/src/utils/archiveorg.h
new file mode 100644 (file)
index 0000000..95c9dc4
--- /dev/null
@@ -0,0 +1,63 @@
+/***************************************************************************
+ *   Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *                                                                         *
+ *   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 ARCHIVEORG_H
+#define ARCHIVEORG_H
+
+
+#include "abstractservice.h"
+
+#include <QProcess>
+#include <kio/jobclasses.h>
+
+
+class ArchiveOrg : public AbstractService
+{
+    Q_OBJECT
+
+public:
+    ArchiveOrg(QListWidget *listWidget, QObject * parent = 0);
+    ~ArchiveOrg();
+    virtual QString getExtension(QListWidgetItem *item);
+    virtual QString getDefaultDownloadName(QListWidgetItem *item);
+
+
+public slots:
+    virtual void slotStartSearch(const QString searchText, int page = 0);
+    virtual OnlineItemInfo displayItemDetails(QListWidgetItem *item);
+    virtual bool startItemPreview(QListWidgetItem *item);
+    virtual void stopItemPreview(QListWidgetItem *item);    
+
+private slots:
+    void slotShowResults(KJob* job);
+    void slotParseResults(KJob* job);
+    
+private:
+    QMap <QString, QString> m_metaInfo;
+    QProcess *m_previewProcess;
+
+signals:
+    void addClip(KUrl, const QString &);
+};
+
+
+#endif
+
index 4db1a3c52eb91614275386d5952a31f2e6c188f1..80a663d10bd138795df91cae332cf10e0849e48a 100644 (file)
@@ -22,6 +22,7 @@
 #include "resourcewidget.h"
 #include "freesound.h"
 #include "openclipart.h"
+#include "archiveorg.h"
 
 #include <QPushButton>
 #include <QSpinBox>
@@ -60,6 +61,7 @@ ResourceWidget::ResourceWidget(const QString & folder, QWidget * parent) :
     setAttribute(Qt::WA_DeleteOnClose);
 #ifdef USE_QJSON
     service_list->addItem(i18n("Freesound Audio Library"), FREESOUND);
+    service_list->addItem(i18n("Archive.org Video Library"), ARCHIVEORG);
 #endif
     service_list->addItem(i18n("Open Clip Art Graphic Library"), OPENCLIPART);
     setWindowTitle(i18n("Search Online Resources"));
@@ -242,6 +244,10 @@ void ResourceWidget::slotChangeService()
     else if (service == OPENCLIPART) {
         m_currentService = new OpenClipArt(search_results);
     }
+    else if (service == ARCHIVEORG) {
+        m_currentService = new ArchiveOrg(search_results);
+    }
+    
     connect(m_currentService, SIGNAL(gotMetaInfo(QMap <QString, QString>)), this, SLOT(slotDisplayMetaInfo(QMap <QString, QString>)));
     connect(m_currentService, SIGNAL(maxPages(int)), page_number, SLOT(setMaximum(int)));
     connect(m_currentService, SIGNAL(searchInfo(QString)), search_info, SLOT(setText(QString)));