Ejemplo n.º 1
0
QList<QList<QString> > YandexmusicApi::getAlbumInfo(const QString &name)
{
  QList<QList<QString> > albumInfo{{}};
  FileDownloader *fd = new FileDownloader(QUrl(QString("https://music.yandex.ru/handlers/search.jsx?text=%1&type=albums").arg(name)));
  QJsonDocument jsonDoc = QJsonDocument::fromJson(fd->downloadedData());
  fd->~FileDownloader();

  albumInfo[0].append(QString::number(jsonDoc.object().value("counts").toObject().value("artists").toDouble()));
  albumInfo[0].append(QString::number(jsonDoc.object().value("counts").toObject().value("albums").toDouble()));
  albumInfo[0].append(QString::number(jsonDoc.object().value("counts").toObject().value("tracks").toDouble()));

  QList<QString> tmp {};
  for(int i = 0; i < jsonDoc.object().value("albums").toObject().value("items").toArray().count(); i++)
    {
      tmp << QString::number(jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("id").toDouble());
      tmp << jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("storageDir").toString();
      tmp << jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("title").toString();
      tmp << QString::number(jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("year").toDouble());
      tmp << jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("coverUri").toString();
      tmp << QString::number(jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("artists").toObject().value("id").toDouble());
      tmp << jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("artists").toObject().value("name").toString();
      tmp << QString::number(jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("trackCount").toDouble());
      tmp << QString::number(jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("genre").toDouble());

      albumInfo << tmp;
      tmp.clear();
    }

  return albumInfo;
}
Ejemplo n.º 2
0
bool FileDownloader::downloadUrl(QString urlStr, QByteArray &data)
{
    FileDownloader fd;
    fd.startDownloadAsync(urlStr);

    Q_ASSERT(fd.lastError() == result_code::Type::Invalid);
    while (fd.lastError() == result_code::Type::Invalid || fd.lastError() == result_code::Type::InProgress)
        qApp->processEvents();

    data = fd.downloadedData();
    return result_code::succeeded(fd.lastError());
}
Ejemplo n.º 3
0
void WebBridgeRS::onUrlDownloaded(){
    FileDownloader * fileDownloader = qobject_cast<FileDownloader *>(QObject::sender());

    //QDir::absoluteFilePath()
    QString fpath = getDownloadDirectory();

    fpath.append("/");
    QString urlstring(fileDownloader->url().toString());
    fpath.append(QFileInfo(urlstring).fileName());
    std::cout << fpath.toStdString() << std::endl;
    QFile file(fpath);
    file.open(QIODevice::WriteOnly);

    file.write(fileDownloader->downloadedData());

    // optional, as QFile destructor will already do it:
    file.close();

    std::cout << fileDownloader->downloadedData().data() << std::endl;
    emit urlDownloaded(fpath, urlstring);

}
Ejemplo n.º 4
0
QString YandexmusicApi::getTrackUrl(const QString &storageDir)
{
  FileDownloader *fd = new FileDownloader(QUrl(QString("https://storage.mds.yandex.net/download-info/%1/2?format=json").arg(storageDir)));
  QJsonDocument jsonDoc = QJsonDocument::fromJson(fd->downloadedData());
  fd->~FileDownloader();

  QByteArray h = QCryptographicHash::hash("XGRlBW9FXlekgbPrRHuSiA" +
                                          jsonDoc.object().value("path").toString().mid(1).toUtf8() +
                                          jsonDoc.object().value("s").toString().toUtf8(), QCryptographicHash::Md5);


  return QString("https://") + jsonDoc.object().value("host").toString() + "/get-mp3/" + QString(h.toHex()) + QString("/") +
      jsonDoc.object().value("ts").toString() + jsonDoc.object().value("path").toString();
}
void QGitHubReleaseAPIPrivate::downloaded(const FileDownloader &fd) {

	QObject::connect(m_apiDownloader, SIGNAL(error(QString)), this, SLOT(fdError(QString)));
	QObject::connect(m_apiDownloader, SIGNAL(downloaded(FileDownloader)),
					 this, SLOT(downloaded(FileDownloader)));
	QObject::connect(m_apiDownloader, SIGNAL(progress(qint64,qint64)),
					 this, SLOT(downloadProgress(qint64,qint64)));

	m_jsonData = fd.downloadedData();

	foreach(const FileDownloader::RAWHEADERPAIR &pair, fd.rawHeaderPairs()) {

		if(pair.first == "ETag") m_eTag = pair.second.mid(2);

		if(pair.first == "X-RateLimit-Reset") {
			m_rateLimitReset = QDateTime::fromTime_t(QString(pair.second).toUInt());
		}

		if(pair.first == "X-RateLimit-Limit") m_rateLimit = QString(pair.second).toUInt();

		if(pair.first == "X-RateLimit-Remaining") {
			m_rateLimitRemaining = QString(pair.second).toUInt();
		}
	}

	QVariant va(parseJSon(m_jsonData, m_errorString));

	if(m_errorString.isNull()) {

		if(m_singleEntryRequested) {
			m_vdata.append(va);
		} else if((m_vdata = va.toList()).isEmpty()) {
			m_errorString = va.toMap()["message"].toString();
			emit error(m_errorString);
			return;
		}

		emit available();

	} else {
		emit error(m_errorString);
	}
}