File indexing completed on 2025-02-23 04:35:14
0001 // SPDX-FileCopyrightText: 2019 Linus Jahn <lnj@kaidan.im> 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 #include "video.h" 0005 0006 using namespace QInvidious; 0007 using namespace Qt::StringLiterals; 0008 0009 Video Video::fromJson(const QJsonObject &obj, Video &video) 0010 { 0011 VideoBasicInfo::fromJson(obj, video); 0012 0013 const bool isPeerTube = obj.contains("id"_L1); 0014 const bool isInvidious = obj.contains("videoId"_L1); 0015 0016 if (isInvidious) { 0017 parseArray(obj.value("keywords"_L1), video.m_keywords); 0018 video.m_likeCount = obj.value("likeCount"_L1).toInt(); 0019 video.m_dislikeCount = obj.value("dislikeCount"_L1).toInt(); 0020 video.m_isFamilyFriendly = obj.value("isFamilyFriendly"_L1).toBool(true); 0021 parseArray(obj.value("allowedRegions"_L1), video.m_allowedRegions); 0022 video.m_genre = obj.value("genre"_L1).toString(); 0023 video.m_genreUrl = obj.value("genreUrl"_L1).toString(); 0024 parseArray(obj.value("authorThumbnails"_L1), video.m_authorThumbnails); 0025 video.m_subCountText = obj.value("subCountText"_L1).toString(); 0026 video.m_allowRatings = obj.value("allowRatings"_L1).toBool(true); 0027 video.m_rating = obj.value("rating"_L1).toDouble(5.0); 0028 video.m_isListed = obj.value("isListed"_L1).toBool(true); 0029 parseArray(obj.value("recommendedVideos"_L1), video.m_recommendedVideos); 0030 if (obj.contains(u"premiereTimestamp")) { 0031 video.m_premiereTimestamp = QDateTime::fromMSecsSinceEpoch(obj.value(u"premiereTimestamp").toInt()); 0032 } 0033 video.m_hlsUrl = QUrl(obj.value(u"hlsUrl").toString()); 0034 parseArray(obj.value(u"adaptiveFormats"), video.m_adaptiveFormats); 0035 parseArray(obj.value(u"formatStreams"), video.m_combinedFormats); 0036 parseArray(obj.value(u"captions"), video.m_captions); 0037 } else if (isPeerTube) { 0038 // TODO: peertube stub 0039 } else { 0040 video.m_author = obj.value("uploader"_L1).toString(); 0041 parseArray(obj.value("tags"_L1), video.m_keywords); 0042 video.m_likeCount = obj.value("likes"_L1).toInt(); 0043 video.m_dislikeCount = obj.value("dislikes"_L1).toInt(); 0044 0045 VideoThumbnail thumbnail; 0046 thumbnail.setUrl(QUrl(obj.value("uploaderAvatar"_L1).toString())); 0047 video.m_authorThumbnails.push_back(thumbnail); 0048 0049 video.m_subCountText = QString::number(obj.value("uploaderSubscriberCount"_L1).toInt()); 0050 parseArray(obj.value("relatedStreams"_L1), video.m_recommendedVideos); 0051 video.m_hlsUrl = QUrl(obj.value(u"hls").toString()); 0052 } 0053 0054 return video; 0055 } 0056 0057 QStringList Video::keywords() const 0058 { 0059 return m_keywords; 0060 } 0061 0062 qint32 Video::likeCount() const 0063 { 0064 return m_likeCount; 0065 } 0066 0067 qint32 Video::dislikeCount() const 0068 { 0069 return m_dislikeCount; 0070 } 0071 0072 bool Video::isFamilyFriendly() const 0073 { 0074 return m_isFamilyFriendly; 0075 } 0076 0077 QStringList Video::allowedRegions() const 0078 { 0079 return m_allowedRegions; 0080 } 0081 0082 QString Video::genre() const 0083 { 0084 return m_genre; 0085 } 0086 0087 QString Video::genreUrl() const 0088 { 0089 return m_genreUrl; 0090 } 0091 0092 QList<VideoThumbnail> Video::authorThumbnails() const 0093 { 0094 return m_authorThumbnails; 0095 } 0096 0097 QString Video::subCountText() const 0098 { 0099 return m_subCountText; 0100 } 0101 0102 bool Video::allowRatings() const 0103 { 0104 return m_allowRatings; 0105 } 0106 0107 double Video::rating() const 0108 { 0109 return m_rating; 0110 } 0111 0112 bool Video::isListed() const 0113 { 0114 return m_isListed; 0115 } 0116 0117 QList<VideoBasicInfo> Video::recommendedVideos() const 0118 { 0119 return m_recommendedVideos; 0120 } 0121 0122 std::optional<QDateTime> Video::premiereTimestamp() const 0123 { 0124 return m_premiereTimestamp; 0125 } 0126 0127 QUrl Video::hlsUrl() const 0128 { 0129 return m_hlsUrl; 0130 } 0131 0132 QList<MediaFormat> Video::adaptiveFormats() const 0133 { 0134 return m_adaptiveFormats; 0135 } 0136 0137 QList<MediaFormatCombined> Video::combinedFormats() const 0138 { 0139 return m_combinedFormats; 0140 } 0141 0142 QList<Caption> Video::captions() const 0143 { 0144 return m_captions; 0145 }