]> git.sur5r.net Git - minitube/blobdiff - src/video.cpp
New upstream version 3.1
[minitube] / src / video.cpp
index 52432b8d0efcf950566c4eb27f941d2448240f22..05d9761b58eb52ea899706c959587dd49114d466 100644 (file)
@@ -23,12 +23,13 @@ $END_LICENSE */
 #include "http.h"
 #include "httputils.h"
 #include "jsfunctions.h"
+#include "playlistitemdelegate.h"
 #include "videodefinition.h"
 #include "ytvideo.h"
 
 Video::Video()
     : duration(0), viewCount(-1), license(LicenseYouTube), definitionCode(0),
-      loadingThumbnail(false), ytVideo(0) {}
+      loadingThumbnail(false), ytVideo(nullptr) {}
 
 Video::~Video() {
     qDebug() << "Deleting" << id;
@@ -50,6 +51,7 @@ Video *Video::clone() {
     clone->published = published;
     clone->formattedPublished = formattedPublished;
     clone->viewCount = viewCount;
+    clone->formattedViewCount = formattedViewCount;
     clone->id = id;
     clone->definitionCode = definitionCode;
     return clone;
@@ -89,6 +91,11 @@ void Video::setDuration(int value) {
     formattedDuration = DataUtils::formatDuration(duration);
 }
 
+void Video::setViewCount(int value) {
+    viewCount = value;
+    formattedViewCount = DataUtils::formatCount(viewCount);
+}
+
 void Video::setPublished(const QDateTime &value) {
     published = value;
     formattedPublished = DataUtils::formatDateTime(published);
@@ -98,19 +105,20 @@ void Video::setThumbnail(const QByteArray &bytes) {
     qreal ratio = qApp->devicePixelRatio();
     thumbnail.loadFromData(bytes);
     thumbnail.setDevicePixelRatio(ratio);
-    const int thumbWidth = 160 * ratio;
+    const int thumbWidth = PlaylistItemDelegate::thumbWidth * ratio;
     if (thumbnail.width() > thumbWidth)
         thumbnail = thumbnail.scaledToWidth(thumbWidth, Qt::SmoothTransformation);
     emit gotThumbnail();
     loadingThumbnail = false;
 }
 
-void Video::streamUrlLoaded(const QUrl &streamUrl) {
+void Video::streamUrlLoaded(const QString &streamUrl, const QString &audioUrl) {
+    qDebug() << "Streams loaded";
     definitionCode = ytVideo->getDefinitionCode();
     this->streamUrl = streamUrl;
-    emit gotStreamUrl(this->streamUrl);
-    delete ytVideo;
-    ytVideo = 0;
+    emit gotStreamUrl(streamUrl, audioUrl);
+    ytVideo->deleteLater();
+    ytVideo = nullptr;
 }
 
 void Video::loadStreamUrl() {
@@ -120,7 +128,18 @@ void Video::loadStreamUrl() {
     }
     ytVideo = new YTVideo(id, this);
     connect(ytVideo, &YTVideo::gotStreamUrl, this, &Video::streamUrlLoaded);
-    connect(ytVideo, &YTVideo::errorStreamUrl, this, &Video::errorStreamUrl);
-    connect(ytVideo, &YTVideo::errorStreamUrl, ytVideo, &QObject::deleteLater);
+    connect(ytVideo, &YTVideo::errorStreamUrl, this, [this](const QString &msg) {
+        emit errorStreamUrl(msg);
+        ytVideo->deleteLater();
+        ytVideo = nullptr;
+    });
     ytVideo->loadStreamUrl();
 }
+
+void Video::abortLoadStreamUrl() {
+    if (ytVideo) {
+        ytVideo->disconnect(this);
+        ytVideo->deleteLater();
+        ytVideo = nullptr;
+    }
+}