1 #include "searchvideosource.h"
3 #include "searchparams.h"
9 #include "ivchannelsource.h"
11 #include "ivsinglevideosource.h"
13 #include "ytjschannelsource.h"
14 #include "ytjssearch.h"
15 #include "ytjssinglevideosource.h"
17 SearchVideoSource::SearchVideoSource(SearchParams *searchParams, QObject *parent)
18 : VideoSource(parent), searchParams(searchParams) {}
20 void SearchVideoSource::loadVideos(int max, int startIndex) {
23 if (VideoAPI::impl() == VideoAPI::YT3) {
24 YTSearch *ytSearch = new YTSearch(searchParams);
25 ytSearch->setAsyncDetails(true);
26 // --- connect(ytSearch, SIGNAL(gotDetails()), playlistModel, SLOT(emitDataChanged()));
28 } else if (VideoAPI::impl() == VideoAPI::IV) {
29 if (searchParams->channelId().isEmpty()) {
30 source = new IVSearch(searchParams);
32 source = new IVChannelSource(searchParams);
34 } else if (VideoAPI::impl() == VideoAPI::JS) {
35 if (searchParams->channelId().isEmpty()) {
36 source = new YTJSSearch(searchParams);
38 source = new YTJSChannelSource(searchParams);
41 connectSource(max, startIndex);
43 source->loadVideos(max, startIndex);
46 bool SearchVideoSource::hasMoreVideos() {
47 if (source) return source->hasMoreVideos();
48 return VideoSource::hasMoreVideos();
51 QString SearchVideoSource::getName() {
52 if (source) return source->getName();
56 const QList<QAction *> &SearchVideoSource::getActions() {
57 if (source) return source->getActions();
58 return VideoSource::getActions();
61 int SearchVideoSource::maxResults() {
62 if (source) return source->maxResults();
63 return VideoSource::maxResults();
66 void SearchVideoSource::connectSource(int max, int startIndex) {
67 connect(source, &VideoSource::finished, this, &VideoSource::finished);
68 connect(source, &VideoSource::gotVideos, this, [this](auto &videos) {
70 emit gotVideos(videos);
72 connect(source, &VideoSource::error, this, [this, max, startIndex](auto msg) {
73 qDebug() << source << msg;
75 if (QLatin1String(source->metaObject()->className()).startsWith(QLatin1String("YTJS"))) {
76 qDebug() << "Falling back to IV";
77 source->deleteLater();
78 if (searchParams->channelId().isEmpty()) {
79 source = new IVSearch(searchParams);
81 source = new IVChannelSource(searchParams);
83 connectSource(max, startIndex);
84 source->loadVideos(max, startIndex);