void MediaView::findVideoParts() { Video *video = playlistModel->activeVideo(); if (!video) return; QString query = video->getTitle(); const QLatin1String optionalSpace("\\s*"); const QLatin1String staticCounterSeparators("[\\/\\-]"); const QString counterSeparators = QLatin1String("( of | ") + tr("of", "Used in video parts, as in '2 of 3'") + QLatin1String(" |") + staticCounterSeparators + QLatin1String(")"); // numbers from 1 to 15 const QLatin1String counterNumber("([1-9]|1[0-5])"); // query.remove(QRegExp(counterSeparators + optionalSpace + counterNumber)); query.remove(QRegExp(counterNumber + optionalSpace + counterSeparators + optionalSpace + counterNumber)); query.remove(wordRE("pr?t\\.?" + optionalSpace + counterNumber)); query.remove(wordRE("ep\\.?" + optionalSpace + counterNumber)); query.remove(wordRE("part" + optionalSpace + counterNumber)); query.remove(wordRE("episode" + optionalSpace + counterNumber)); query.remove(wordRE(tr("part", "This is for video parts, as in 'Cool video - part 1'") + optionalSpace + counterNumber)); query.remove(wordRE(tr("episode", "This is for video parts, as in 'Cool series - episode 1'") + optionalSpace + counterNumber)); query.remove(QRegExp("[\\(\\)\\[\\]]")); #define NUMBERS "one|two|three|four|five|six|seven|eight|nine|ten" QRegExp englishNumberRE = QRegExp(QLatin1String(".*(") + NUMBERS + ").*", Qt::CaseInsensitive); // bool numberAsWords = englishNumberRE.exactMatch(query); query.remove(englishNumberRE); QRegExp localizedNumberRE = QRegExp(QLatin1String(".*(") + tr(NUMBERS) + ").*", Qt::CaseInsensitive); // if (!numberAsWords) numberAsWords = localizedNumberRE.exactMatch(query); query.remove(localizedNumberRE); SearchParams *searchParams = new SearchParams(); searchParams->setTransient(true); searchParams->setKeywords(query); searchParams->setChannelId(video->getChannelId()); /* if (!numberAsWords) { qDebug() << "We don't have number as words"; // searchParams->setSortBy(SearchParams::SortByNewest); // TODO searchParams->setReverseOrder(true); // TODO searchParams->setMax(50); } */ search(searchParams); }
void MediaView::onAuthorPushed(QModelIndex index) { Video *video = playlistModel->videoAt(index.row()); if (!video) return; QString channelId = video->getChannelId(); // if (channelId.isEmpty()) channelId = video->channelTitle(); if (channelId.isEmpty()) return; SearchParams *searchParams = new SearchParams(); searchParams->setChannelId(channelId); searchParams->setSortBy(SearchParams::SortByNewest); // go! search(searchParams); }
void MediaView::toggleSubscription() { Video *video = playlistModel->activeVideo(); if (!video) return; QString userId = video->getChannelId(); if (userId.isEmpty()) return; bool subscribed = YTChannel::isSubscribed(userId); if (subscribed) { YTChannel::unsubscribe(userId); MainWindow::instance()->showMessage( tr("Unsubscribed from %1").arg(video->getChannelTitle())); } else { YTChannel::subscribe(userId); MainWindow::instance()->showMessage(tr("Subscribed to %1").arg(video->getChannelTitle())); } updateSubscriptionAction(video, !subscribed); }