File indexing completed on 2025-02-23 04:35:13
0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com> 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 #include "channel.h" 0005 0006 using namespace QInvidious; 0007 using namespace Qt::StringLiterals; 0008 0009 Channel Channel::fromJson(const QJsonObject &obj, Channel &channel) 0010 { 0011 const bool isPeerTube = obj.contains("id"_L1) && !obj.contains("nextpage"_L1); 0012 const bool isPiped = obj.contains("url"_L1) || obj.contains("nextpage"_L1); 0013 if (isPiped) { 0014 channel.m_id = obj["url"_L1].toString().remove(QStringLiteral("/channel/")); 0015 channel.m_name = obj["name"_L1].toString(); 0016 channel.m_avatar = obj["avatarUrl"_L1].toString(); 0017 channel.m_banner = obj["bannerUrl"_L1].toString(); 0018 channel.m_description = obj["description"_L1].toString(); 0019 channel.m_subCount = obj["subscriberCount"_L1].toInt(); 0020 } else if (isPeerTube) { 0021 channel.m_name = obj["name"_L1].toString(); 0022 channel.m_description = obj["description"_L1].toString(); 0023 channel.m_subCount = obj["followersCount"_L1].toInt(); 0024 channel.m_avatar = obj["avatar"_L1].toObject()["path"_L1].toString(); 0025 const QJsonValue firstBanners = obj["banners"_L1].toArray().first(); 0026 channel.m_banner = firstBanners.toObject()["path"_L1].toString(); 0027 } else { 0028 channel.m_id = obj["authorId"_L1].toString(); 0029 channel.m_name = obj["author"_L1].toString(); 0030 const QJsonValue firstAvatar = obj["authorThumbnails"_L1].toArray().first(); 0031 channel.m_avatar = firstAvatar.toObject()["url"_L1].toString(); 0032 const QJsonValue firstBanners = obj["authorBanners"_L1].toArray().first(); 0033 channel.m_banner = firstBanners.toObject()["url"_L1].toString(); 0034 channel.m_description = obj["description"_L1].toString(); 0035 channel.m_subCount = obj["subCount"_L1].toInt(); 0036 } 0037 0038 return channel; 0039 } 0040 0041 QString Channel::id() const 0042 { 0043 return m_id; 0044 } 0045 0046 QString Channel::name() const 0047 { 0048 return m_name; 0049 } 0050 0051 QString Channel::banner() const 0052 { 0053 return m_banner; 0054 } 0055 0056 void Channel::setBanner(const QString &banner) 0057 { 0058 m_banner = banner; 0059 } 0060 0061 QString Channel::avatar() const 0062 { 0063 return m_avatar; 0064 } 0065 0066 void Channel::setAvatar(const QString &avatar) 0067 { 0068 m_avatar = avatar; 0069 } 0070 0071 QString Channel::description() const 0072 { 0073 return m_description; 0074 } 0075 0076 int Channel::subCount() const 0077 { 0078 return m_subCount; 0079 }