#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;
clone->published = published;
clone->formattedPublished = formattedPublished;
clone->viewCount = viewCount;
+ clone->formattedViewCount = formattedViewCount;
clone->id = id;
clone->definitionCode = definitionCode;
return clone;
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);
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() {
}
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;
+ }
+}