Пример #1
0
Album ParserAlbum::getAlbumFromFile(const QString &_name)
{
    m_pFile->close();
    if(!m_pFile->open(QIODevice::ReadOnly))
    {
        qDebug() << "Can`t open file : " << m_pFile->fileName();
    }
    Album newAlbum;
    newAlbum.setName(_name);
    QDomElement element = m_pDoc->documentElement();
    QDomNode node = element.firstChild();
    while(!node.isNull())
    {
        if(node.isElement())
        {
            QDomElement domElement = node.toElement();
            if(domElement.nodeName() == "images")
            {
                if(domElement.hasChildNodes())
                {
                    getImages(newAlbum,domElement.childNodes());
                }
            }
            if(domElement.nodeName() == "current")
            {
                newAlbum.setCurrentIndex(domElement.text().toInt());
            }
            node = node.nextSibling().toElement();
        }
    } 
    m_pFile->close();
    return newAlbum;
}
Пример #2
0
void TestAlbum::album_76101()
      {
      Album album;
      album.setName("test");
      album.append(new AlbumItem(root + "/" + DIR + "album_76101-01.mscx"));
      album.append(new AlbumItem(root + "/" + DIR + "album_76101-02.mscx"));
      album.createScore("album_76101.mscx");
      QVERIFY(compareFiles("album_76101.mscx", DIR + "album_76101-ref.mscx"));
      }
Пример #3
0
void TestAlbum::album_78521()
      {
      Album album;
      album.setName("test");
      album.append(new AlbumItem(root + "/" + DIR + "album_78521-vbox.mscx"));
      album.append(new AlbumItem(root + "/" + DIR + "album_78521-vbox.mscx"));
      album.append(new AlbumItem(root + "/" + DIR + "album_78521-empty.mscx"));
      album.createScore("album_78521-vbox-vbox-empty.mscx");
      QVERIFY(compareFiles("album_78521-vbox-vbox-empty.mscx", DIR + "album_78521-vbox-vbox-empty-ref.mscx"));
      }
Пример #4
0
void TestAlbum::album_105716()
      {
      Album album;
      album.setName("test");
      album.append(new AlbumItem(root + "/" + DIR + "album_105716-measure-nobreak.mscx"));
      album.append(new AlbumItem(root + "/" + DIR + "album_105716-measure-linebreak.mscx"));
      album.append(new AlbumItem(root + "/" + DIR + "album_105716-measure-pagebreak.mscx"));
      album.append(new AlbumItem(root + "/" + DIR + "album_105716-measure-linebreak-sectionbreak.mscx"));
      album.append(new AlbumItem(root + "/" + DIR + "album_105716-measure-pagebreak-sectionbreak.mscx"));
      album.append(new AlbumItem(root + "/" + DIR + "album_105716-measure-nobreak.mscx"));

      album.createScore("album_105716-joined-addSectionBreak-addPageBreak.mscx", true, true);
      QVERIFY(compareFiles("album_105716-joined-addSectionBreak-addPageBreak.mscx", DIR + "album_105716-joined-addSectionBreak-addPageBreak-ref.mscx"));

      album.createScore("album_105716-joined-addPageBreak.mscx", true, false);
      QVERIFY(compareFiles("album_105716-joined-addPageBreak.mscx", DIR + "album_105716-joined-addPageBreak-ref.mscx"));

      album.createScore("album_105716-joined-addSectionBreak.mscx", false, true);
      QVERIFY(compareFiles("album_105716-joined-addSectionBreak.mscx", DIR + "album_105716-joined-addSectionBreak-ref.mscx"));

      album.createScore("album_105716-joined-noaddBreak.mscx", false, false);
      QVERIFY(compareFiles("album_105716-joined-noaddBreak.mscx", DIR + "album_105716-joined-noaddBreak-ref.mscx"));
      }
Пример #5
0
vector<string> MusicVideoService::downloadAudio(const string& url) {
  LOG(INFO) << "downloadYouTubeAudio with url " << url;
  vector<string> filepaths;

  boost::filesystem::path tmpPath(SoulSifterSettings::getInstance().get<string>("dir.tmp"));  // todo: use os.tmpdir()
  if (!boost::filesystem::exists(tmpPath)) {
    if (!boost::filesystem::create_directories(tmpPath)) {
      LOG(WARNING) << "Unable to create temporary directory " << tmpPath;
      return filepaths;
    }
  } else if (!boost::filesystem::is_directory(tmpPath)) {
    LOG(WARNING) << "Temporary directory is not a directory " << tmpPath;
    return filepaths;
  }

  FILE *fpipe;
  stringstream command;
  command << "cd " << tmpPath << "; youtube-dl --print-json --write-all-thumbnails --restrict-filenames --extract-audio --audio-format mp3 --audio-quality 0 --quiet " << url;
  if (!(fpipe = (FILE*)popen(command.str().c_str(), "r"))) {
    LOG(WARNING) << "Problem with youtube-dl pipe.";
    return filepaths;
  }

  char buffer[1024];
  stringstream ss;
  LOG(INFO) << "Running command '" << command.str() << "'";
  while (fgets(buffer, sizeof buffer, fpipe)) {
    ss << buffer;
  }

  pclose(fpipe);

  // read output
  string json;
  while (std::getline(ss, json, '\n')) {
    if (json.at(0) == '{') {
      boost::property_tree::ptree ptree;
      std::stringstream tmp(json);
      read_json(tmp, ptree);

      Song* song = new Song();
      Album* album = new Album();
      song->setAlbum(album);

      string baseFileName = ptree.get<string>("_filename").substr(0, ptree.get<string>("_filename").size() - ptree.get<string>("ext").size());
      song->setFilepath(SoulSifterSettings::getInstance().get<string>("dir.tmp") + '/' + baseFileName + "mp3");
      album->setCoverFilepath(SoulSifterSettings::getInstance().get<string>("dir.tmp") + '/' + baseFileName + "jpg");
      string title = ptree.get<string>("title");
      if (!MusicManager::getInstance().splitArtistAndTitle(title, song)) {
        song->setArtist(ptree.get<string>("uploader"));
        song->setTitle(title);
      }
      MusicManager::getInstance().moveFeaturing(song);
      MusicManager::getInstance().copyRemixer(song);
      song->setLowQuality(true);
      song->setCurator(ptree.get<string>("uploader"));
      string date = ptree.get<string>("upload_date", "00000000");
      if (!date.empty() && !!date.compare("null")) {
        album->setReleaseDateYear(std::stoi(date.substr(0, 4)));
        album->setReleaseDateMonth(std::stoi(date.substr(4, 2)));
        album->setReleaseDateDay(std::stoi(date.substr(6, 4)));
      }
      album->setArtist(song->getArtist());
      album->setName(song->getTitle());

      TagService::writeId3v2Tag(song);
      filepaths.push_back(song->getFilepath());
      filepaths.push_back(album->getCoverFilepath());
      delete song;
      return filepaths;
    }
  }
  return filepaths;
}