From: Flavio Tordini Date: Wed, 24 Jun 2009 07:58:41 +0000 (+0200) Subject: Removed synchronous http request X-Git-Tag: 0.4~39 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=9d21bba470b09c5bf9c35bfe0e8163e7dd13a4b2;p=minitube Removed synchronous http request This fixes the search'n'stop crash --- diff --git a/src/ListModel.cpp b/src/ListModel.cpp index ac97835..e794d3d 100755 --- a/src/ListModel.cpp +++ b/src/ListModel.cpp @@ -89,8 +89,8 @@ QVariant ListModel::data(const QModelIndex &index, int role) const { return tooltip; */ - case StreamUrlRole: - return video->streamUrl(); + // case StreamUrlRole: + // return video->streamUrl(); } return QVariant(); diff --git a/src/ListModel.h b/src/ListModel.h index 5b1c9bf..1d6228b 100755 --- a/src/ListModel.h +++ b/src/ListModel.h @@ -8,7 +8,6 @@ enum DataRoles { ItemTypeRole = Qt::UserRole, VideoRole, - StreamUrlRole, ActiveTrackRole }; @@ -44,7 +43,7 @@ public: // custom methods void setActiveRow( int row ); bool rowExists( int row ) const { return (( row >= 0 ) && ( row < videos.size() ) ); } - // int activeRow() const { return m_activeRow; } // returns -1 if there is no active row + int activeRow() const { return m_activeRow; } // returns -1 if there is no active row int nextRow() const; void removeIndexes(QModelIndexList &indexes); int rowForVideo(Video* video); diff --git a/src/MediaView.cpp b/src/MediaView.cpp index c6c47df..99641ec 100644 --- a/src/MediaView.cpp +++ b/src/MediaView.cpp @@ -211,8 +211,16 @@ void MediaView::activeRowChanged(int row) { loadingWidget->setVideo(video); loadingWidget->show(); - QUrl streamUrl = video->streamUrl(); - // qDebug() << "setCurrentSource" << streamUrl.toString(); + mediaObject->pause(); + + connect(video, SIGNAL(gotStreamUrl(QUrl)), SLOT(gotStreamUrl(QUrl))); + video->loadStreamUrl(); + + // see you in gotStreamUrl... + +} + +void MediaView::gotStreamUrl(QUrl streamUrl) { // go! mediaObject->setCurrentSource(streamUrl); @@ -222,8 +230,11 @@ void MediaView::activeRowChanged(int row) { listModel->searchNeeded(); // ensure active item is visible - QModelIndex index = listModel->index(row, 0, QModelIndex()); - listView->scrollTo(index, QAbstractItemView::EnsureVisible); + int row = listModel->activeRow(); + if (row != -1) { + QModelIndex index = listModel->index(row, 0, QModelIndex()); + listView->scrollTo(index, QAbstractItemView::EnsureVisible); + } } void MediaView::itemActivated(const QModelIndex &index) { diff --git a/src/MediaView.h b/src/MediaView.h index 9f6e5d6..f39097c 100644 --- a/src/MediaView.h +++ b/src/MediaView.h @@ -57,6 +57,7 @@ private slots: void aboutToFinish(); void currentSourceChanged(const Phonon::MediaSource source); void showVideoContextMenu(QPoint point); + void gotStreamUrl(QUrl streamUrl); // bar void searchMostRelevant(); void searchMostRecent(); diff --git a/src/video.cpp b/src/video.cpp index 96bb81f..0e8d860 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -26,12 +26,11 @@ const QImage Video::thumbnail() const { return m_thumbnail; } -bool Video::getVideoUrl() { +void Video::scrapeStreamUrl() { // https://develop.participatoryculture.org/trac/democracy/browser/trunk/tv/portable/flashscraper.py - QUrl webpage = m_webpage;\ - // if (webpage == ) return false; + QUrl webpage = m_webpage; // qDebug() << webpage.toString(); // Get Video ID @@ -39,8 +38,8 @@ bool Video::getVideoUrl() { // QRegExp re("^((?:http://)?(?:\\w+\\.)?youtube\\.com/(?:(?:v/)|(?:(?:watch(?:\\.php)?)?\\?(?:.+&)?v=)))?([0-9A-Za-z_-]+)(?(1).+)?$"); QRegExp re("^http://www\\.youtube\\.com/watch\\?v=([0-9A-Za-z_-]+)$"); bool match = re.exactMatch(webpage.toString()); - if (!match || re.numCaptures() < 1) return false; - QString videoId = re.cap(1); + // if (!match || re.numCaptures() < 1) return false; + videoId = re.cap(1); // if (!videoId) return false; // qDebug() << videoId; @@ -48,45 +47,12 @@ bool Video::getVideoUrl() { QUrl normalizedUrl = QUrl(QString("http://www.youtube.com/get_video_info?video_id=") .append(videoId).append("&el=embedded&ps=default&eurl=")); - /* QObject *reply = The::http()->get(normalizedUrl); connect(reply, SIGNAL(data(QByteArray)), SLOT(gotVideoInfo(QByteArray))); - return true; - */ - QString videoInfo = The::http()->syncGetString(normalizedUrl); - // qDebug() << videoInfo; - re = QRegExp("^.*&token=([^&]+).*$"); - match = re.exactMatch(videoInfo); - if (!match || re.numCaptures() < 1) return false; - QString videoToken = re.cap(1); - // FIXME proper decode - videoToken = videoToken.replace("%3D", "="); - // qDebug() << "token" << videoToken; - - m_streamUrl = QUrl(QString("http://www.youtube.com/get_video?video_id=") - .append(videoId) - .append("&t=").append(videoToken) - .append("&eurl=&el=embedded&ps=default&fmt=18")); - - // qDebug() << videoUrl; - - // follow redirects - /* - while (true) { - QHttpResponseHeader headers = syncHttp->head(videoUrl); - qDebug() << headers.values(); - if (headers.hasKey("Location")) { - videoUrl = QUrl(headers.value("Location"), QUrl::StrictMode); - // qDebug() << videoUrl; - } else break; - }*/ - - return true; + // see you in gotVideoInfo... } - -/* void Video::gotVideoInfo(QByteArray data) { QString videoInfo = QString::fromUtf8(data); // qDebug() << videoInfo; @@ -104,5 +70,6 @@ void Video::gotVideoInfo(QByteArray data) { .append("&eurl=&el=embedded&ps=default&fmt=18")); m_streamUrl = videoUrl; + + emit gotStreamUrl(videoUrl); } -*/ diff --git a/src/video.h b/src/video.h index 060305a..81e0734 100644 --- a/src/video.h +++ b/src/video.h @@ -23,12 +23,11 @@ public: const QUrl webpage() const { return m_webpage; } void setWebpage( QUrl webpage ) { m_webpage = webpage; } - const QUrl streamUrl() { + void loadStreamUrl() { if (m_streamUrl.isEmpty()) - this->getVideoUrl(); - return m_streamUrl; + this->scrapeStreamUrl(); + else emit gotStreamUrl(m_streamUrl); } - void setStreamUrl( QUrl streamUrl ) { m_streamUrl = streamUrl; } QList thumbnailUrls() const { return m_thumbnailUrls; } void addThumbnailUrl(QUrl url) { @@ -52,12 +51,13 @@ public slots: signals: void gotThumbnail(); + void gotStreamUrl(QUrl streamUrl); private slots: - // void gotVideoInfo(QByteArray); + void gotVideoInfo(QByteArray); private: - bool getVideoUrl(); + void scrapeStreamUrl(); QString m_title; QString m_description; @@ -72,6 +72,9 @@ private: QDateTime m_published; int m_viewCount; + // The YouTube video id + // This is needed by the gotVideoInfo callback + QString videoId; }; // This is required in order to use QPointer