-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathyinyuetai.cpp
More file actions
107 lines (99 loc) · 2.74 KB
/
yinyuetai.cpp
File metadata and controls
107 lines (99 loc) · 2.74 KB
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
#include "yinyuetai.h"
#include <QtDebug>
yinyuetai::yinyuetai(QObject *parent) : QObject(parent)
{
dPage=new downloader();
connect(dPage,SIGNAL(finished()),this,SLOT(pageDownloaded()));
connect(dPage,SIGNAL(downloadError(QString)),this,SLOT(downloadFailed(QString)));
connect(dPage,SIGNAL(redirected(QString)),this,SLOT(downloadFailed(QString)));
dInfo=new downloader();
connect(dInfo,SIGNAL(finished()),this,SLOT(infoDownloaded()));
connect(dInfo,SIGNAL(downloadError(QString)),this,SLOT(downloadFailed(QString)));
connect(dInfo,SIGNAL(redirected(QString)),this,SLOT(downloadFailed(QString)));
}
void yinyuetai::init(QString inUrl)
{
vid=inUrl.split("/").last();
qDebug()<<vid;
dPage->init(inUrl,"page.html");
dPage->setUserAgent(UA);
dPage->doGet();
}
void yinyuetai::downloadFailed(QString inStr)
{
emit status(inStr);
emit finished(false);
}
void yinyuetai::pageDownloaded()
{
title=QString("");
QFile file("page.html");
char tmp[100];
if(!file.open(QIODevice::ReadOnly))
{
emit status("page.html 打开失败");
emit finished(false);
return;
}
QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName("UTF-8"));
QString a;
while(!stream.atEnd())
{
a=stream.readLine();
if(a.contains("og:title"))
{
a=stream.readLine();
getStringBetweenAandB(a.toStdString().c_str(),"content=\"","\"",tmp);
title=tmp;
qDebug()<<title;
break;
}
}
file.close();
dInfo->init(QString("http://www.yinyuetai.com/api/info/get-video-urls?json=true&videoId=%1").arg(vid),"info.json");
dInfo->setUserAgent(UA);
dInfo->doGet();
}
void yinyuetai::infoDownloaded()
{
QFile file("info.json");
if(!file.open(QIODevice::ReadOnly))
{
emit status("info.json 打开失败");
emit finished(false);
return;
}
QString line=file.readLine();
char tmp[300];
if(-2==getStringBetweenAandB(line.toStdString().c_str(),"hcVideoUrl\":\"","\"",tmp))
hcLink="";
else
hcLink=tmp;
if(-2==getStringBetweenAandB(line.toStdString().c_str(),"hdVideoUrl\":\"","\"",tmp))
hdLink="";
else
hdLink=tmp;
if(-2==getStringBetweenAandB(line.toStdString().c_str(),"heVideoUrl\":\"","\"",tmp))
heLink="";
else
heLink=tmp;
file.close();
emit finished(true);
}
QString yinyuetai::getHCLink()
{
return hcLink;
}
QString yinyuetai::getHDLink()
{
return hdLink;
}
QString yinyuetai::getHELink()
{
return heLink;
}
QString yinyuetai::getTile()
{
return title;
}