Skip to content

Commit

Permalink
added integration for download_widget class
Browse files Browse the repository at this point in the history
  • Loading branch information
keshavbhatt committed Sep 1, 2019
1 parent ea2ce19 commit 2e8ff81
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 12 deletions.
72 changes: 64 additions & 8 deletions videooption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@




VideoOption::VideoOption(QWidget *parent,store *store,QString fifopath):
QWidget(parent),
ui(new Ui::VideoOption)
Expand Down Expand Up @@ -36,14 +37,13 @@ VideoOption::VideoOption(QWidget *parent,store *store,QString fifopath):
}
});
fifo->start("bash",QStringList()<<"-c"<<"echo '{\"command\":[\"get_property\" , \"fullscreen\"]}' | socat - "+ used_fifo_file_path);
//fifo->waitForStarted();
});
}

void VideoOption::toggleFullscreen()
{
QProcess *fifo = new QProcess(nullptr);
connect(fifo, SIGNAL(finished(int)), this, SLOT(deleteProcess(int)) );
// QProcess *fifo = new QProcess(nullptr);
// connect(fifo, SIGNAL(finished(int)), this, SLOT(deleteProcess(int)) );
// fifo->start("bash",QStringList()<<"-c"<< "echo '{\"command\": [\"set_property\" ,\"volume\","+QString::number(volume)+"]}' | socat - "+ used_fifo_file_path);
}

Expand Down Expand Up @@ -82,6 +82,9 @@ void VideoOption::setMeta(QString songId){
ytIds = trackMetaList.at(8);
dominantColor = trackMetaList.at(9);

currentTrackMeta.clear();
currentTrackMeta<<songId<<title<<album<<artist<<base64<<ytIds;

QTextDocument text;
text.setHtml(title);
QString plainTitle = text.toPlainText();
Expand Down Expand Up @@ -130,6 +133,8 @@ void VideoOption::resetVars(){
rBtn->deleteLater();
}
ui->watch->setEnabled(false);
ui->download->setEnabled(false);

audioCode.clear();
videoCode.clear();
resolution_List.clear();
Expand All @@ -141,8 +146,10 @@ void VideoOption::resetVars(){
}

void VideoOption::setMetaFromWeb(QVariant data){

resetVars();
QStringList trackMetaList = data.toString().split("<==>");
currentTrackMeta = trackMetaList;
QString ytIds,title,artist,album,coverUrl,songId;

if(trackMetaList.count()>4){
Expand Down Expand Up @@ -189,6 +196,10 @@ void VideoOption::setMetaFromWeb(QVariant data){
void VideoOption::LoadAvatar(const QUrl &avatarUrl)
{
QNetworkAccessManager manager;
QNetworkDiskCache* diskCache = new QNetworkDiskCache(0);
QString cache_path = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
diskCache->setCacheDirectory(cache_path);
manager.setCache(diskCache);
QEventLoop loop;
QNetworkReply *reply = manager.get(QNetworkRequest(avatarUrl));
QObject::connect(reply, &QNetworkReply::finished, &loop, [&reply, this,&loop](){
Expand Down Expand Up @@ -356,37 +367,81 @@ void VideoOption::update_audio_video_code(bool checked){
connect(ui->watch,&QPushButton::clicked,[=](){
getUrlForFormatsAndPLay(audioCode,videoCode);
});

ui->download->disconnect();
connect(ui->download,&QPushButton::clicked,[=](){
getUrlForFormatsAndDownload(audioCode,videoCode);
});

ui->watch->setEnabled(true);
ui->download->setEnabled(true);

}else{
ui->watch->setEnabled(false);
ui->download->setEnabled(false);

}
}


void VideoOption::getUrlForFormatsAndPLay(QString audioFormat,QString videoFormat){
QString addin_path = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
QProcess *audioP = new QProcess(this);

task = "play";
connect(audioP,SIGNAL(finished(int)),this,SLOT(getUrlProcessFinished(int)));


audioP->start("python",QStringList()<<addin_path+"/core"<<"-f"<<videoFormat+"+"+audioFormat<<"--get-url"<<currentUrl);
ui->progressBar->show();
ui->watch->setText("Merging formats...");
ui->watch->setEnabled(false);
ui->download->setEnabled(false);

audioP->waitForStarted();
}

void VideoOption::getUrlForFormatsAndDownload(QString audioFormat,QString videoFormat){
ui->progressBar->show();
task ="download";
addToDownload(videoFormat,audioFormat);
ui->download->setEnabled(false);
ui->progressBar->hide();
}

void VideoOption::getUrlProcessFinished(int code){
if(code==0){
QProcess *process = qobject_cast<QProcess*>(sender());
QString output = process->readAll().trimmed();
if(output.contains("http")){
videoUrl = output.split("\n").first();
audioUrl = output.split("\n").last();
mergeAndPlay(videoUrl,audioUrl);
if(task=="play")
mergeAndPlay(videoUrl,audioUrl);
else
addToDownload(videoUrl,audioUrl);//not being used
}
ui->progressBar->hide();
}else{
QMessageBox msgBox;
msgBox.setText("ERROR: an error occured while performing this task");
msgBox.setIcon(QMessageBox::Information);
msgBox.setInformativeText("Error code: "+QString::number(code));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
}
}

void VideoOption::addToDownload(QString videoFormat, QString audioFormat){

QStringList downloadFormats;
downloadFormats<<videoFormat<<audioFormat;

if(currentTrackMeta.count()>4){
emit downloadRequested(currentTrackMeta,downloadFormats);
}else{
//TODO show error to user
//TODO show error
}
}

Expand All @@ -405,6 +460,8 @@ void VideoOption::playerFinished(int code){
Q_UNUSED(code);
ui->watch->setText("Watch");
ui->watch->setEnabled(true);
ui->download->setEnabled(true);

this->setWindowTitle(QApplication::applicationName()+" - Video Option");
if(this->windowState()==Qt::WindowFullScreen){
this->setWindowState(Qt::WindowNoState);
Expand All @@ -414,6 +471,8 @@ void VideoOption::playerFinished(int code){

void VideoOption::playerReadyRead(){
ui->watch->setEnabled(false);
ui->download->setEnabled(false);

ui->watch->setText("Playing...");
this->setWindowTitle("MPV for Olivia - "+currentTitle);
if(!playerTimer->isActive()){
Expand All @@ -422,6 +481,3 @@ void VideoOption::playerReadyRead(){
}





6 changes: 6 additions & 0 deletions videooption.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class VideoOption : public QWidget

signals:
bool checkEngine();
void downloadRequested(const QStringList currentTrackMeta,const QStringList downloadFormats);

public slots:
void removeStyle();
Expand All @@ -53,6 +54,9 @@ private slots:
void LoadAvatar(const QUrl &avatarUrl);
void toggleFullscreen();
void deleteProcess(int code);

void getUrlForFormatsAndDownload(QString audioFormat, QString videoFormat);
void addToDownload(QString videoFormat, QString audioFormat);
private:
Ui::VideoOption *ui;
store *store_manager = nullptr;
Expand All @@ -64,6 +68,8 @@ private slots:
QString videoUrl,audioUrl;
QString used_fifo_file_path;
QTimer *playerTimer = nullptr;
QString task = "";
QStringList currentTrackMeta;



Expand Down
13 changes: 9 additions & 4 deletions videooption.ui
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ border:none;</string>
<string/>
</property>
<property name="pixmap">
<pixmap resource="icons.qrc">:/icons/sidebar/album.png</pixmap>
<pixmap>:/icons/sidebar/album.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
Expand Down Expand Up @@ -366,6 +366,13 @@ QScrollBar:vertical {
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="download">
<property name="text">
<string>Download</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand All @@ -380,8 +387,6 @@ QScrollBar:vertical {
<header>elidedlabel.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="icons.qrc"/>
</resources>
<resources/>
<connections/>
</ui>

0 comments on commit 2e8ff81

Please sign in to comment.