Пример #1
0
 Album::Album(const Album& album) :
 id(album.getId()),
 name(album.getName()),
 artist(album.getArtist()),
 coverFilepath(album.getCoverFilepath()),
 mixed(album.getMixed()),
 label(album.getLabel()),
 catalogId(album.getCatalogId()),
 releaseDateYear(album.getReleaseDateYear()),
 releaseDateMonth(album.getReleaseDateMonth()),
 releaseDateDay(album.getReleaseDateDay()),
 basicGenreId(album.getBasicGenreId()),
 basicGenre(NULL) {
     if (album.basicGenre) setBasicGenre(*album.basicGenre);
 }
Пример #2
0
 void Album::operator=(const Album& album) {
     id = album.getId();
     name = album.getName();
     artist = album.getArtist();
     coverFilepath = album.getCoverFilepath();
     mixed = album.getMixed();
     label = album.getLabel();
     catalogId = album.getCatalogId();
     releaseDateYear = album.getReleaseDateYear();
     releaseDateMonth = album.getReleaseDateMonth();
     releaseDateDay = album.getReleaseDateDay();
     basicGenreId = album.getBasicGenreId();
     if (!album.getBasicGenreId() && album.basicGenre) {
         if (!basicGenre) basicGenre = new BasicGenre(*album.basicGenre);
         else *basicGenre = *album.basicGenre;
     } else {
         delete basicGenre;
         basicGenre = NULL;
     }
 }
Пример #3
0
    bool Album::sync() {
        Album* album = findById(id);
        if (!album) {
            if (!basicGenreId && basicGenre) {
                basicGenre->sync();
                basicGenreId = basicGenre->getId();
            }
        }
        if (!album) album = findByNameAndArtist(getName(), getArtist());
        if (!album) return true;

        // check fields
        bool needsUpdate = false;
        boost::regex decimal("(-?\\d+)\\.?\\d*");
        boost::smatch match1;
        boost::smatch match2;
        if (id != album->getId()) {
            if (id) {
                LOG(INFO) << "updating album " << id << " id from " << album->getId() << " to " << id;
                needsUpdate = true;
            } else {
                id = album->getId();
            }
        }
        if (name.compare(album->getName())  && (!boost::regex_match(name, match1, decimal) || !boost::regex_match(album->getName(), match2, decimal) || match1[1].str().compare(match2[1].str()))) {
            if (!name.empty()) {
                LOG(INFO) << "updating album " << id << " name from " << album->getName() << " to " << name;
                needsUpdate = true;
            } else {
                name = album->getName();
            }
        }
        if (artist.compare(album->getArtist())  && (!boost::regex_match(artist, match1, decimal) || !boost::regex_match(album->getArtist(), match2, decimal) || match1[1].str().compare(match2[1].str()))) {
            if (!artist.empty()) {
                LOG(INFO) << "updating album " << id << " artist from " << album->getArtist() << " to " << artist;
                needsUpdate = true;
            } else {
                artist = album->getArtist();
            }
        }
        if (coverFilepath.compare(album->getCoverFilepath())  && (!boost::regex_match(coverFilepath, match1, decimal) || !boost::regex_match(album->getCoverFilepath(), match2, decimal) || match1[1].str().compare(match2[1].str()))) {
            if (!coverFilepath.empty()) {
                LOG(INFO) << "updating album " << id << " coverFilepath from " << album->getCoverFilepath() << " to " << coverFilepath;
                needsUpdate = true;
            } else {
                coverFilepath = album->getCoverFilepath();
            }
        }
        if (mixed != album->getMixed()) {
            if (mixed) {
                LOG(INFO) << "updating album " << id << " mixed from " << album->getMixed() << " to " << mixed;
                needsUpdate = true;
            } else {
                mixed = album->getMixed();
            }
        }
        if (label.compare(album->getLabel())  && (!boost::regex_match(label, match1, decimal) || !boost::regex_match(album->getLabel(), match2, decimal) || match1[1].str().compare(match2[1].str()))) {
            if (!label.empty()) {
                LOG(INFO) << "updating album " << id << " label from " << album->getLabel() << " to " << label;
                needsUpdate = true;
            } else {
                label = album->getLabel();
            }
        }
        if (catalogId.compare(album->getCatalogId())  && (!boost::regex_match(catalogId, match1, decimal) || !boost::regex_match(album->getCatalogId(), match2, decimal) || match1[1].str().compare(match2[1].str()))) {
            if (!catalogId.empty()) {
                LOG(INFO) << "updating album " << id << " catalogId from " << album->getCatalogId() << " to " << catalogId;
                needsUpdate = true;
            } else {
                catalogId = album->getCatalogId();
            }
        }
        if (releaseDateYear != album->getReleaseDateYear()) {
            if (releaseDateYear) {
                LOG(INFO) << "updating album " << id << " releaseDateYear from " << album->getReleaseDateYear() << " to " << releaseDateYear;
                needsUpdate = true;
            } else {
                releaseDateYear = album->getReleaseDateYear();
            }
        }
        if (releaseDateMonth != album->getReleaseDateMonth()) {
            if (releaseDateMonth) {
                LOG(INFO) << "updating album " << id << " releaseDateMonth from " << album->getReleaseDateMonth() << " to " << releaseDateMonth;
                needsUpdate = true;
            } else {
                releaseDateMonth = album->getReleaseDateMonth();
            }
        }
        if (releaseDateDay != album->getReleaseDateDay()) {
            if (releaseDateDay) {
                LOG(INFO) << "updating album " << id << " releaseDateDay from " << album->getReleaseDateDay() << " to " << releaseDateDay;
                needsUpdate = true;
            } else {
                releaseDateDay = album->getReleaseDateDay();
            }
        }
        if (basicGenreId != album->getBasicGenreId()) {
            if (basicGenreId) {
                LOG(INFO) << "updating album " << id << " basicGenreId from " << album->getBasicGenreId() << " to " << basicGenreId;
                needsUpdate = true;
            } else {
                basicGenreId = album->getBasicGenreId();
            }
        }
        if (basicGenre) needsUpdate |= basicGenre->sync();
        return needsUpdate;
    }
Пример #4
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;
}