#include "videoarea.h"
#ifdef APP_ACTIVATION
#include "activation.h"
+#include "activationview.h"
#endif
#ifdef APP_EXTRA
#include "extra.h"
#include "idle.h"
#include "videodefinition.h"
+#include "ivchannelsource.h"
+#include "ivsearch.h"
+#include "ivsinglevideosource.h"
+#include "videoapi.h"
+
MediaView *MediaView::instance() {
static MediaView *i = new MediaView();
return i;
#ifdef APP_ACTIVATION
demoTimer = new QTimer(this);
demoTimer->setSingleShot(true);
- connect(demoTimer, &QTimer::timeout, mainWindow, &MainWindow::showActivationView,
+ connect(
+ demoTimer, &QTimer::timeout, this,
+ [this] {
+ if (media->state() != Media::PlayingState) return;
+ media->pause();
+ connect(
+ ActivationView::instance(), &ActivationView::done, media,
+ [this] { media->play(); }, Qt::UniqueConnection);
+ MainWindow::instance()->showActivationView();
+ },
Qt::QueuedConnection);
#endif
for (auto *name : videoActionNames) {
currentVideoActions.append(mainWindow->getAction(name));
}
+
+ for (int i = 0; i < 10; ++i) {
+ QAction *action = new QAction(QString());
+ action->setShortcut(Qt::Key_0 + i);
+ action->setAutoRepeat(false);
+ connect(action, &QAction::triggered, this, [this, i] {
+ qint64 duration = media->duration();
+ // dur : pos = 100 : i*10
+ qint64 position = (duration * (i * 10)) / 100;
+ media->seek(position);
+ });
+ addAction(action);
+ playingVideoActions << action;
+ }
+
+ QAction *leftAction = new QAction(tr("Rewind %1 seconds").arg(10));
+ leftAction->setShortcut(Qt::Key_Left);
+ leftAction->setAutoRepeat(false);
+ connect(leftAction, &QAction::triggered, this, [this] {
+ qint64 position = media->position();
+ position -= 10000;
+ if (position < 0) position = 0;
+ media->seek(position);
+ });
+ addAction(leftAction);
+ playingVideoActions << leftAction;
+
+ QAction *rightAction = new QAction(tr("Fast forward %1 seconds").arg(10));
+ rightAction->setShortcut(Qt::Key_Right);
+ rightAction->setAutoRepeat(false);
+ connect(rightAction, &QAction::triggered, this, [this] {
+ qint64 position = media->position();
+ position += 10000;
+ qint64 duration = media->duration();
+ if (position > duration) position = duration;
+ media->seek(position);
+ });
+ addAction(rightAction);
+ playingVideoActions << rightAction;
}
void MediaView::setMedia(Media *media) {
SearchParams *MediaView::getSearchParams() {
VideoSource *videoSource = playlistModel->getVideoSource();
- if (videoSource && videoSource->metaObject()->className() == QLatin1String("YTSearch")) {
- YTSearch *search = qobject_cast<YTSearch *>(videoSource);
+ if (!videoSource) return nullptr;
+ auto clazz = videoSource->metaObject()->className();
+ if (clazz == QLatin1String("YTSearch")) {
+ auto search = qobject_cast<YTSearch *>(videoSource);
+ return search->getSearchParams();
+ }
+ if (clazz == QLatin1String("IVSearch")) {
+ auto search = qobject_cast<IVSearch *>(videoSource);
+ return search->getSearchParams();
+ }
+ if (clazz == QLatin1String("IVChannelSource")) {
+ auto search = qobject_cast<IVChannelSource *>(videoSource);
return search->getSearchParams();
}
return nullptr;
searchParams->keywords().startsWith("https://")) {
QString videoId = YTSearch::videoIdFromUrl(searchParams->keywords());
if (!videoId.isEmpty()) {
- YTSingleVideoSource *singleVideoSource = new YTSingleVideoSource(this);
- singleVideoSource->setVideoId(videoId);
+ VideoSource *singleVideoSource = nullptr;
+ if (VideoAPI::impl() == VideoAPI::YT3) {
+ auto source = new YTSingleVideoSource(this);
+ source->setVideoId(videoId);
+ singleVideoSource = source;
+ } else if (VideoAPI::impl() == VideoAPI::IV) {
+ auto source = new IVSingleVideoSource(this);
+ source->setVideoId(videoId);
+ singleVideoSource = source;
+ }
setVideoSource(singleVideoSource);
+
QTime tstamp = YTSearch::videoTimestampFromUrl(searchParams->keywords());
pauseTime = QTime(0, 0).msecsTo(tstamp);
return;
}
}
}
- YTSearch *ytSearch = new YTSearch(searchParams);
- ytSearch->setAsyncDetails(true);
- connect(ytSearch, SIGNAL(gotDetails()), playlistModel, SLOT(emitDataChanged()));
- setVideoSource(ytSearch);
+
+ VideoSource *search = nullptr;
+ if (VideoAPI::impl() == VideoAPI::YT3) {
+ YTSearch *ytSearch = new YTSearch(searchParams);
+ ytSearch->setAsyncDetails(true);
+ connect(ytSearch, SIGNAL(gotDetails()), playlistModel, SLOT(emitDataChanged()));
+ search = ytSearch;
+ } else if (VideoAPI::impl() == VideoAPI::IV) {
+ if (searchParams->channelId().isEmpty()) {
+ search = new IVSearch(searchParams);
+ } else {
+ search = new IVChannelSource(searchParams);
+ }
+ }
+ setVideoSource(search);
}
void MediaView::setVideoSource(VideoSource *videoSource, bool addToHistory, bool back) {
// qDebug() << "Adding VideoSource" << videoSource->getName() << videoSource;
- YTSearch * ytSearch = qobject_cast<YTSearch *>(videoSource);
- if (nullptr != ytSearch) {
- if (!ytSearch->getSearchParams()->channelId().isEmpty()) {
- updateSubscriptionActionForChannel(ytSearch->getSearchParams()->channelId());
- }
- }
-
if (addToHistory) {
int currentIndex = getHistoryIndex();
if (currentIndex >= 0 && currentIndex < history.size() - 1) {
}
}
+ SearchParams *searchParams = getSearchParams();
+
sidebar->showPlaylist();
- sidebar->getRefineSearchWidget()->setSearchParams(getSearchParams());
+ sidebar->getRefineSearchWidget()->setSearchParams(searchParams);
sidebar->hideSuggestions();
sidebar->getHeader()->updateInfo();
- SearchParams *searchParams = getSearchParams();
bool isChannel = searchParams && !searchParams->channelId().isEmpty();
+ if (isChannel) {
+ updateSubscriptionActionForChannel(searchParams->channelId());
+ }
playlistView->setClickableAuthors(!isChannel);
}
handleError(media->errorString());
}
+ bool enablePlayingVideoActions = state == Media::PlayingState || state == Media::PausedState;
+ for (QAction *action : qAsConst(playingVideoActions))
+ action->setEnabled(enablePlayingVideoActions);
+
if (state == Media::PlayingState) {
bool res = Idle::preventDisplaySleep(QString("%1 is playing").arg(Constants::NAME));
if (!res) qWarning() << "Error disabling idle display sleep" << Idle::displayErrorMessage();
}
#ifdef APP_ACTIVATION
- if (!Activation::instance().isActivated() && !demoTimer->isActive()) {
- int ms = (60000 * 5) + (qrand() % (60000 * 5));
+ if (!demoTimer->isActive() && !Activation::instance().isActivated()) {
+ int ms = (60000 * 2) + (QRandomGenerator::global()->generate() % (60000 * 2));
demoTimer->start(ms);
}
#endif
void MediaView::relatedVideos() {
Video *video = playlistModel->activeVideo();
if (!video) return;
- YTSingleVideoSource *singleVideoSource = new YTSingleVideoSource();
- singleVideoSource->setVideo(video->clone());
- singleVideoSource->setAsyncDetails(true);
- setVideoSource(singleVideoSource);
+
+ if (VideoAPI::impl() == VideoAPI::YT3) {
+ YTSingleVideoSource *singleVideoSource = new YTSingleVideoSource();
+ singleVideoSource->setVideo(video->clone());
+ singleVideoSource->setAsyncDetails(true);
+ setVideoSource(singleVideoSource);
+ } else if (VideoAPI::impl() == VideoAPI::IV) {
+ auto source = new IVSingleVideoSource(this);
+ source->setVideo(video->clone());
+ setVideoSource(source);
+ }
+
MainWindow::instance()->getAction("relatedVideos")->setEnabled(false);
}