Song PodcastEpisode::ToSong(const Podcast& podcast) const {
  Song ret;
  ret.set_valid(true);
  ret.set_title(title().simplified());
  ret.set_artist(author().simplified());
  ret.set_length_nanosec(kNsecPerSec * duration_secs());
  ret.set_year(publication_date().date().year());
  ret.set_comment(description());

  if (downloaded() && QFile::exists(local_url().toLocalFile())) {
    ret.set_url(local_url());
  } else {
    ret.set_url(url());
  }

  ret.set_basefilename(QFileInfo(ret.url().path()).fileName());

  // Use information from the podcast if it's set
  if (podcast.is_valid()) {
    ret.set_album(podcast.title().simplified());
    ret.set_art_automatic(podcast.ImageUrlLarge().toString());

    if (author().isEmpty()) ret.set_artist(podcast.title().simplified());
  }
  return ret;
}
Example #2
0
void PodcastBackend::Unsubscribe(const Podcast& podcast) {
  // If this podcast is not already in the database, do nothing
  if (!podcast.is_valid()) {
    return;
  }

  QMutexLocker l(db_->Mutex());
  QSqlDatabase db(db_->Connect());
  ScopedTransaction t(&db);

  // Remove the podcast.
  QSqlQuery q("DELETE FROM podcasts WHERE ROWID = :id", db);
  q.bindValue(":id", podcast.database_id());
  q.exec();
  if (db_->CheckErrors(q)) return;

  // Remove all episodes in the podcast
  q = QSqlQuery("DELETE FROM podcast_episodes WHERE podcast_id = :id", db);
  q.bindValue(":id", podcast.database_id());
  q.exec();
  if (db_->CheckErrors(q)) return;

  t.Commit();

  emit SubscriptionRemoved(podcast);
}