return tooltip;
*/
- case StreamUrlRole:
- return video->streamUrl();
+ // case StreamUrlRole:
+ // return video->streamUrl();
}
return QVariant();
enum DataRoles {
ItemTypeRole = Qt::UserRole,
VideoRole,
- StreamUrlRole,
ActiveTrackRole
};
// 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);
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);
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) {
void aboutToFinish();
void currentSourceChanged(const Phonon::MediaSource source);
void showVideoContextMenu(QPoint point);
+ void gotStreamUrl(QUrl streamUrl);
// bar
void searchMostRelevant();
void searchMostRecent();
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
// 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;
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;
.append("&eurl=&el=embedded&ps=default&fmt=18"));
m_streamUrl = videoUrl;
+
+ emit gotStreamUrl(videoUrl);
}
-*/
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<QUrl> thumbnailUrls() const { return m_thumbnailUrls; }
void addThumbnailUrl(QUrl url) {
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;
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<Video> as a QVariant