diff --git a/Olivia.pro.user b/Olivia.pro.user index 518a89c..532e33c 100644 --- a/Olivia.pro.user +++ b/Olivia.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/mainwindow.cpp b/mainwindow.cpp index 10c8fac..eeb9ac4 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -78,6 +78,14 @@ void MainWindow::init_similar_tracks(){ if(similarTracks==nullptr){ similarTracks = new SimilarTracks(this,5); connect(similarTracks, &SimilarTracks::setSimilarTracks,[=](QStringList list){ + similarTracks->isLoadingPLaylist = false; + currentSimilarTrackList.clear(); + currentSimilarTrackList = list; + currentSimilarTrackProcessing = 0; + prepareSimilarTracks(); + }); + connect(similarTracks, &SimilarTracks::setPlaylist,[=](QStringList list){ + similarTracks->isLoadingPLaylist = true; currentSimilarTrackList.clear(); currentSimilarTrackList = list; currentSimilarTrackProcessing = 0; @@ -86,6 +94,10 @@ void MainWindow::init_similar_tracks(){ connect(similarTracks, &SimilarTracks::failedGetSimilarTracks,[=](){ ui->similarTrackLoader->stop(); }); + connect(similarTracks, &SimilarTracks::clearList,[=](){ + currentSimilarTrackList.clear(); + ui->recommListWidget->clear(); + }); } } @@ -1285,7 +1297,6 @@ void MainWindow::addToSimilarTracksQueue(const QVariant Base64andDominantColor){ currentSimilarTrackMeta.append(dominantColor); currentSimilarTrackMeta.append(base64); - QWidget *track_widget = new QWidget(ui->recommListWidget); track_widget->setToolTip(htmlToPlainText(title)); track_widget->setObjectName("track-widget-"+songId); @@ -1370,29 +1381,75 @@ void MainWindow::addToSimilarTracksQueue(const QVariant Base64andDominantColor){ a->start(QPropertyAnimation::DeleteWhenStopped); ui->recommListWidget->addItem(item); - ui->recommListWidget->setCurrentRow(ui->recommListWidget->count()-1); + // ui->recommListWidget->setCurrentRow(ui->recommListWidget->count()-1); if(store_manager->isDownloaded(songId)){ ui->recommListWidget->itemWidget(item)->setEnabled(true); track_ui.url->setText("file://"+setting_path+"/downloadedTracks/"+songId); track_ui.offline->setPixmap(QPixmap(":/icons/offline.png").scaled(track_ui.offline->size(),Qt::KeepAspectRatio,Qt::SmoothTransformation)); }else{ getAudioStream(ytIds,songId); - //reverse the process queue, so that recently added song can get first chance to process - if(ytdlQueue.count()>1){ - ytdlQueue.insert(1, ytdlQueue.takeAt(ytdlQueue.count()-1)); - } } - // ui->recommListWidget->scrollToBottom(); + similarTracksProcessHelper(); + }else{ + QListWidgetItem* item; + item = new QListWidgetItem(ui->recommListWidget); + + QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this); + + item->setSizeHint(track_widget->minimumSizeHint()); + ui->recommListWidget->setItemWidget(item, track_widget); + ui->recommListWidget->itemWidget(item)->setGraphicsEffect(eff); + ui->recommListWidget->itemWidget(item)->setEnabled(false); //enable when finds a url + + QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity"); + a->setDuration(500); + a->setStartValue(0); + a->setEndValue(1); + a->setEasingCurve(QEasingCurve::InCirc); + a->start(QPropertyAnimation::DeleteWhenStopped); + ui->recommListWidget->addItem(item); + + //ui->recommListWidget->setCurrentRow(ui->recommListWidget->count()-1); + if(store_manager->isDownloaded(songId)){ + ui->recommListWidget->itemWidget(item)->setEnabled(true); + track_ui.url->setText("file://"+setting_path+"/downloadedTracks/"+songId); + track_ui.offline->setPixmap(QPixmap(":/icons/offline.png").scaled(track_ui.offline->size(),Qt::KeepAspectRatio,Qt::SmoothTransformation)); + }else{ + QNetworkAccessManager *m_netwManager = new QNetworkAccessManager(this); + connect(m_netwManager,&QNetworkAccessManager::finished,[=](QNetworkReply* rep){ + if(rep->error() == QNetworkReply::NoError){ + QString id = rep->readAll(); + getAudioStream(id,songId); + similarTracksProcessHelper(); + rep->deleteLater(); + m_netwManager->deleteLater(); + }else{ + qDebug()<<"error processing track"<request().url().toString(); + } + }); + QString query = title.replace("N/A","")+" - "+artist.replace("N/A",""); + QUrl url("http://ktechpit.com/USS/Olivia/youtube.php?millis=0&query="+query); + QNetworkRequest request(url); + m_netwManager->get(request); + } } +} +void MainWindow::similarTracksProcessHelper(){ //clear meta of currentSimilarTrack and free it for next track currentSimilarTrackMeta.clear(); //process next track in currentSimilarTrackList list; - if(currentSimilarTrackProcessing < similarTracks->numberOfSimilarTracksToLoad /*currentSimilarTrackList.count()-1*/){ - currentSimilarTrackProcessing++; - prepareSimilarTracks(); + if(similarTracks->isLoadingPLaylist){ + if(currentSimilarTrackProcessing < currentSimilarTrackList.count()-1){ + currentSimilarTrackProcessing++; + prepareSimilarTracks(); + } + }else{ + if(currentSimilarTrackProcessing < similarTracks->numberOfSimilarTracksToLoad /*currentSimilarTrackList.count()-1*/){ + currentSimilarTrackProcessing++; + prepareSimilarTracks(); + } } - } void MainWindow::addToQueue(QString id,QString title, @@ -1969,7 +2026,7 @@ void MainWindow::ytdlReadyRead(){ listWidgetItem->setEnabled(true); QLineEdit *url = listWidgetItem->findChild("url"); static_cast(url)->setText(m48url); - qDebug()<<"NEW URL:"<saveStreamUrl(songId,m48url,getExpireTime(m48url)); mfr->deleteLater(); @@ -2353,11 +2410,17 @@ void MainWindow::listItemDoubleClicked(QListWidget *list,QListWidgetItem *item){ shadow_list_.back()->setColor(QColor("#292929")); lbl->setGraphicsEffect(shadow_list_.back()); } + if(store_manager->isDownloaded(songId)){ radio_manager->playRadio(false,QUrl(url)); }else{ saveTracksAfterBuffer = settingsObj.value("saveAfterBuffer","true").toBool(); - radio_manager->playRadio(saveTracksAfterBuffer,QUrl(url)); + //do not save tracks if playing from similar tracks list + if(list->objectName()=="recommListWidget"){ + radio_manager->playRadio(false,QUrl(url)); + }else{ + radio_manager->playRadio(saveTracksAfterBuffer,QUrl(url)); + } } //update metadata of MPRIS interface @@ -3926,3 +3989,8 @@ void MainWindow::on_showSimilarList_clicked() ui->recommWidget->isVisible() ? ui->showSimilarList->setIcon(QIcon(":/icons/sidebar/hideRecommend.png")): ui->showSimilarList->setIcon(QIcon(":/icons/sidebar/showRecommend.png")); } + +//add playlist from web interface +void MainWindow::addPlaylistByData(QString data){ + similarTracks->addPlaylist(data); +} diff --git a/mainwindow.h b/mainwindow.h index 791dd98..377dffe 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -85,6 +85,7 @@ class MainWindow : public QMainWindow Q_INVOKABLE void delete_song_cache(QVariant track_id); Q_INVOKABLE void remove_song(QVariant track_id); Q_INVOKABLE void addToSimilarTracksQueue(const QVariant Base64andDominantColor); + Q_INVOKABLE void addPlaylistByData(QString data); QString youtubeSearchTerm; bool saveTracksAfterBuffer; @@ -231,6 +232,7 @@ private slots: void showRecommendedTrackOption(); void showPayPalDonationMessageBox(); void prepareSimilarTracks(); + void similarTracksProcessHelper(); private: QStringList currentSimilarTrackMeta ,currentSimilarTrackList; int currentSimilarTrackProcessing = 0; diff --git a/mainwindow.ui b/mainwindow.ui index 43bf6c0..b5663cd 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -1333,7 +1333,7 @@ padding-left: 10px; QTabWidget::Rounded - 0 + 1 Qt::ElideNone @@ -1477,6 +1477,9 @@ QScrollBar:vertical { 5 + + QAbstractItemView::NoDragDrop + QAbstractItemView::ScrollPerPixel @@ -1629,15 +1632,6 @@ QScrollBar:vertical { 5 - - true - - - QAbstractItemView::DragDrop - - - Qt::MoveAction - QAbstractItemView::SingleSelection @@ -1958,6 +1952,9 @@ QScrollBar:vertical { 5 + + QAbstractItemView::NoDragDrop + QAbstractItemView::ScrollPerPixel diff --git a/similartracks.cpp b/similartracks.cpp index 55a6a24..1215e59 100644 --- a/similartracks.cpp +++ b/similartracks.cpp @@ -4,11 +4,12 @@ SimilarTracks::SimilarTracks(QObject *parent,int limit) : QObject(parent) { + numberOfSimilarTracksToLoad = limit; } void SimilarTracks::addSimilarTracks(QString video_id){ - + isLoadingPLaylist = false; QNetworkAccessManager *m_netwManager = new QNetworkAccessManager(this); connect(m_netwManager,&QNetworkAccessManager::finished,[=](QNetworkReply* rep){ if(rep->error() == QNetworkReply::NoError){ @@ -46,3 +47,23 @@ void SimilarTracks::addSimilarTracks(QString video_id){ QNetworkRequest request(url); m_netwManager->get(request); } + +void SimilarTracks::addPlaylist(QString data){ + isLoadingPLaylist = true; + + emit clearList(); + + QStringList list = data.split("gettrackinfo("); + list.removeFirst(); + + QStringList finalList; + foreach (QString str, list) { + finalList.append(QString(str.split(");\">").first()).remove(""")); + } + if(finalList.count()>0){ + emit setPlaylist(finalList); + }else{ + emit failedGetSimilarTracks(); + } +} + diff --git a/similartracks.h b/similartracks.h index 69e7678..a75c408 100644 --- a/similartracks.h +++ b/similartracks.h @@ -10,15 +10,19 @@ class SimilarTracks : public QObject public: explicit SimilarTracks(QObject *parent = nullptr, int limit = 5); int numberOfSimilarTracksToLoad; + bool isLoadingPLaylist = false; private: QStringList playedTracksIds; signals: void setSimilarTracks(QStringList); + void setPlaylist(QStringList); void failedGetSimilarTracks(); + void clearList(); public slots: void addSimilarTracks(QString video_id); + void addPlaylist(QString data); }; #endif // SIMILARTRACKS_H