Skip to content

Commit

Permalink
Add download functionality
Browse files Browse the repository at this point in the history
It is now possible to download videos with ytdl.
  • Loading branch information
rrooij committed Jan 28, 2016
1 parent 2951d84 commit c7d10c9
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 4 deletions.
20 changes: 18 additions & 2 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include "outputwindow.h"
#include "youtubedl.h"

#include <QFileDialog>
#include <QtConcurrent/QtConcurrent>


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
Expand All @@ -22,9 +26,10 @@ void MainWindow::on_pushButton_clicked()
case 0: // Fetch url
this->actionRetrieveUrl();
break;
case 1: // Download
actionDownload();
break;
}


}

void MainWindow::actionRetrieveUrl()
Expand All @@ -37,3 +42,14 @@ void MainWindow::actionRetrieveUrl()
outputWindow->show();
this->setCursor(Qt::ArrowCursor);
}

void MainWindow::actionDownload()
{
QString saveDirectory = QFileDialog::getExistingDirectory();
OutputWindow *outputWindow = new OutputWindow();
outputWindow->show();
YoutubeDL *ytdl = new YoutubeDL();
outputWindow->setYtdl(ytdl->getYtdl());
outputWindow->connect(ytdl->getYtdl(), SIGNAL(readyRead()), outputWindow, SLOT(readyRead()));
ytdl->startDownload(this->ui->videoUrlEdit->text(), saveDirectory);
}
6 changes: 5 additions & 1 deletion mainwindow.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "youtubedl.h"
#include "outputwindow.h"

#include <QMainWindow>

namespace Ui {
Expand All @@ -17,10 +20,11 @@ class MainWindow : public QMainWindow

private slots:
void on_pushButton_clicked();
void actionRetrieveUrl();

private:
Ui::MainWindow *ui;
void actionRetrieveUrl();
void actionDownload();
};

#endif // MAINWINDOW_H
5 changes: 5 additions & 0 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
<string>Retrieve URL</string>
</property>
</item>
<item>
<property name="text">
<string>Download</string>
</property>
</item>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
Expand Down
13 changes: 13 additions & 0 deletions outputwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "outputwindow.h"
#include "ui_outputwindow.h"

#include <QDialog>
#include <QMessageBox>

OutputWindow::OutputWindow(QWidget *parent) :
QWidget(parent),
Expand All @@ -18,3 +20,14 @@ void OutputWindow::setText(QString text)
{
this->ui->outputTextArea->document()->setPlainText(text);
}

void OutputWindow::setYtdl(QProcess *ytdl)
{
this->ytdl = ytdl;
}


void OutputWindow::readyRead()
{
this->ui->outputTextArea->document()->setPlainText(this->ytdl->readAll());
}
8 changes: 8 additions & 0 deletions outputwindow.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef OUTPUTWINDOW_H
#define OUTPUTWINDOW_H

#include <QProcess>
#include <QWidget>

namespace Ui {
Expand All @@ -15,9 +16,16 @@ class OutputWindow : public QWidget
explicit OutputWindow(QWidget *parent = 0);
~OutputWindow();
void setText(QString text);
void updateOutput(QProcess* process);

void setYtdl(QProcess* ytdl);

public slots:
void readyRead();

private:
Ui::OutputWindow *ui;
QProcess* ytdl;
};

#endif // OUTPUTWINDOW_H
9 changes: 8 additions & 1 deletion youtubedl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ QString YoutubeDL::getUrl(QString url)
return output;
}

QProcess YoutubeDL::getYtdl()
void YoutubeDL::startDownload(QString url, QString workingDirectory)
{
this->arguments << url;
this->ytdl->setWorkingDirectory(workingDirectory);
this->ytdl->start(this->program, this->arguments);
}

QProcess* YoutubeDL::getYtdl()
{
return this->ytdl;
}
1 change: 1 addition & 0 deletions youtubedl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class YoutubeDL
~YoutubeDL();
QString getUrl(QString url);
QProcess *getYtdl();
void startDownload(QString url, QString workingDirectory);
private:
QStringList arguments;
QString program;
Expand Down

0 comments on commit c7d10c9

Please sign in to comment.