forked from milohr/babe-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube.cpp
121 lines (84 loc) · 3.25 KB
/
youtube.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
Babe - tiny music player
Copyright (C) 2017 Camilo Higuita
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "youtube.h"
YouTube::YouTube(QObject *parent) : QObject(parent)
{
/* ui->setupUi(this);
ui->label->hide();
ui->textBrowser->hide(); ui->frame_3->hide();
movie = new QMovie(":Data/data/ajax-loader.gif");
ui->label->setMovie(movie);*/
}
YouTube::~YouTube(){ }
void YouTube::searchPendingFiles()
{
QDirIterator it(extensionFetchingPath, QStringList() << "*.babe", QDir::Files);
while (it.hasNext())
{
QString song = it.next();
this->urls<<song;
QFileInfo fileInfo(QFile(song).fileName());
QString id=fileInfo.fileName().section(".",0,-2);
this->ids<<id;
}
if (!urls.isEmpty())
{
fetch(ids,urls);
qDebug()<<ids;
}
}
void YouTube::fetch(QStringList ids_,QStringList urls_)
{
for(auto url: urls_) if(!this->urls.contains(url)) this->urls<<url;
//cont=ids.size();
//qDebug()<<"fetching list size: "<<cont;
for(auto id: ids_)
{
if(!this->ids.contains(id)) this->ids<<id;
auto process = new QProcess(this);
process->setWorkingDirectory(cachePath);
//connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(processFinished()));
//connect(process, SIGNAL(finished(int)), this, SLOT(processFinished_totally(int)));
connect(process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
[=](int exitCode, QProcess::ExitStatus exitStatus){
qDebug()<<"processFinished_totally"<<exitCode<<exitStatus;
processFinished_totally(exitCode,process->arguments().at(process->arguments().size()-1),exitStatus);
});
process->start(ydl+" "+id);
}
qDebug()<<"ids in queue:"<<this->ids;
for(auto url:urls) if(QFile::remove(url)) qDebug()<<"the urls are going to be cleaned up"<< url;
}
void YouTube::processFinished_totally(int state,QString id,QProcess::ExitStatus exitStatus)
{
QString doneId=id;
qDebug()<<"process finished totally for"<<state<<doneId<<exitStatus;
qDebug()<<"need to delete the id="<<doneId;
ids.removeAll(doneId);
qDebug()<<"ids left to process: "<<ids;
//qDebug()<<ids.size();
if(ids.isEmpty())
{
emit youtubeTrackReady(true);
}
}
void YouTube::processFinished()
{
/* QByteArray processOutput;
processOutput = process->readAllStandardOutput();
if (!QString(processOutput).isEmpty())
qDebug() << "Output: " << QString(processOutput);*/
}