Added podcast support, only from subsonic API for now, ref #726

This commit is contained in:
emeric
2025-09-13 15:04:13 +02:00
parent 1d584ebcc6
commit 932e7715f5
111 changed files with 4717 additions and 188 deletions
+2
View File
@@ -11,6 +11,8 @@ add_library(lmsdatabase STATIC
impl/objects/Medium.cpp
impl/objects/PlayListFile.cpp
impl/objects/PlayQueue.cpp
impl/objects/Podcast.cpp
impl/objects/PodcastEpisode.cpp
impl/objects/TrackArtistLink.cpp
impl/objects/TrackFeatures.cpp
impl/objects/TrackList.cpp
+3
View File
@@ -21,6 +21,7 @@
#include <memory>
#include <Wt/Dbo/FixedSqlConnectionPool.h>
#include <Wt/Dbo/Logger.h>
#include <Wt/Dbo/backend/Sqlite3.h>
#include "core/IConfig.hpp"
@@ -193,6 +194,8 @@ namespace lms::db
// Session living class handling the database and the login
Db::Db(const std::filesystem::path& dbPath, std::size_t connectionCount)
{
Wt::Dbo::logToWt();
std::string checkType{ "quick" };
LMS_LOG(DB, INFO, "Creating connection pool on file " << dbPath);
+55 -1
View File
@@ -34,7 +34,7 @@ namespace lms::db
{
namespace
{
static constexpr Version LMS_DATABASE_VERSION{ 99 };
static constexpr Version LMS_DATABASE_VERSION{ 100 };
}
VersionInfo::VersionInfo()
@@ -1528,6 +1528,59 @@ FROM track)");
utils::executeCommand(*session.getDboSession(), "UPDATE scan_settings SET audio_scan_version = audio_scan_version + 1");
}
void migrateFromV99(Session& session)
{
// Podcast support
utils::executeCommand(*session.getDboSession(), "ALTER TABLE image ADD COLUMN mime_type TEXT NOT NULL DEFAULT ''");
utils::executeCommand(*session.getDboSession(), R"(CREATE TABLE IF NOT EXISTS "podcast" (
"id" integer primary key autoincrement,
"version" integer not null,
"url" text not null,
"delete_requested" boolean not null,
"title" text not null,
"link" text not null,
"description" text not null,
"language" text not null,
"copyright" text not null,
"last_build_date" text,
"author" text not null,
"category" text not null,
"explicit" boolean not null,
"image_url" text not null,
"owner_email" text not null,
"owner_name" text not null,
"subtitle" text not null,
"summary" text not null,
"artwork_id" bigint,
constraint "fk_podcast_artwork" foreign key ("artwork_id") references "artwork" ("id") on delete set null deferrable initially deferred))");
utils::executeCommand(*session.getDboSession(), R"(CREATE TABLE IF NOT EXISTS "podcast_episode" (
"id" integer primary key autoincrement,
"version" integer not null,
"manual_download_state" integer not null,
"audio_relative_file_path" text not null,
"title" text not null,
"link" text not null,
"description" text not null,
"author" text not null,
"category" text not null,
"enclosure_url" text not null,
"enclosure_content_type" text not null,
"enclosure_size" integer not null,
"pub_date" text,
"image_url" text not null,
"subtitle" text not null,
"summary" text not null,
"explicit" boolean not null,
"duration" integer,
"artwork_id" bigint,
"podcast_id" bigint,
constraint "fk_podcast_episode_artwork" foreign key ("artwork_id") references "artwork" ("id") on delete set null deferrable initially deferred,
constraint "fk_podcast_episode_podcast" foreign key ("podcast_id") references "podcast" ("id") on delete cascade deferrable initially deferred))");
}
bool doDbMigration(Session& session)
{
constexpr std::string_view outdatedMsg{ "Outdated database, please rebuild it (delete the .db file and restart)" };
@@ -1603,6 +1656,7 @@ FROM track)");
{ 96, migrateFromV96 },
{ 97, migrateFromV97 },
{ 98, migrateFromV98 },
{ 99, migrateFromV99 },
};
bool migrationPerformed{};
+1 -1
View File
@@ -23,7 +23,7 @@
namespace lms::db
{
void ObjectPtrBase::checkWriteTransaction(Wt::Dbo::Session& session)
void ObjectPtrBase::checkWriteTransaction([[maybe_unused]] Wt::Dbo::Session& session)
{
#if LMS_CHECK_TRANSACTION_ACCESSES
TransactionChecker::checkWriteTransaction(session);
+4
View File
@@ -36,6 +36,8 @@
#include "database/objects/Medium.hpp"
#include "database/objects/PlayListFile.hpp"
#include "database/objects/PlayQueue.hpp"
#include "database/objects/Podcast.hpp"
#include "database/objects/PodcastEpisode.hpp"
#include "database/objects/RatedArtist.hpp"
#include "database/objects/RatedRelease.hpp"
#include "database/objects/RatedTrack.hpp"
@@ -86,6 +88,8 @@ namespace lms::db
_session.mapClass<Medium>("medium");
_session.mapClass<PlayListFile>("playlist_file");
_session.mapClass<PlayQueue>("playqueue");
_session.mapClass<Podcast>("podcast");
_session.mapClass<PodcastEpisode>("podcast_episode");
_session.mapClass<RatedArtist>("rated_artist");
_session.mapClass<RatedRelease>("rated_release");
_session.mapClass<RatedTrack>("rated_track");
@@ -80,6 +80,18 @@ namespace lms::db
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<Artwork>>("SELECT a FROM artwork a").where("a.image_id = ?").bind(id));
}
Artwork::UnderlyingId Artwork::getUnderlyingId() const
{
Artwork::UnderlyingId res;
if (const TrackEmbeddedImageId embeddedImageId{ _trackEmbeddedImage.id() }; embeddedImageId.isValid())
res = embeddedImageId;
else if (const ImageId imageId{ _image.id() }; imageId.isValid())
res = imageId;
return res;
}
Wt::WDateTime Artwork::getLastWrittenTime() const
{
auto query{ session()->query<Wt::WDateTime>("SELECT MAX(COALESCE(image.file_last_write, track.file_last_write)) AS last_written_datetime FROM artwork") };
@@ -104,4 +116,14 @@ namespace lms::db
return utils::fetchQuerySingleResult(query);
}
ObjectPtr<Image> Artwork::getImage() const
{
return _image;
}
ImageId Artwork::getImageId() const
{
return _image.id();
}
} // namespace lms::db
@@ -0,0 +1,87 @@
/*
* Copyright (C) 2020 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "database/objects/Podcast.hpp"
#include <Wt/Dbo/Impl.h>
#include <Wt/Dbo/WtSqlTraits.h>
#include "database/Session.hpp"
#include "database/objects/Artwork.hpp"
#include "database/objects/PodcastEpisode.hpp"
#include "Utils.hpp"
#include "traits/IdTypeTraits.hpp"
#include "traits/StringViewTraits.hpp"
DBO_INSTANTIATE_TEMPLATES(lms::db::Podcast)
namespace lms::db
{
Podcast::Podcast(std::string_view url)
: _url{ url }
{
}
Podcast::pointer Podcast::create(Session& session, std::string_view url)
{
return session.getDboSession()->add(std::unique_ptr<Podcast>{ new Podcast{ url } });
}
std::size_t Podcast::getCount(Session& session)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->query<int>("SELECT COUNT(*) FROM podcast"));
}
Podcast::pointer Podcast::find(Session& session, PodcastId id)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<Podcast>>("SELECT p from podcast p").where("p.id = ?").bind(id));
}
Podcast::pointer Podcast::find(Session& session, std::string_view url)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<Podcast>>("SELECT p from podcast p").where("p.url = ?").bind(url));
}
void Podcast::find(Session& session, std::function<void(const pointer&)> func)
{
session.checkReadTransaction();
auto query{ session.getDboSession()->query<Wt::Dbo::ptr<Podcast>>("SELECT p from podcast p") };
utils::forEachQueryResult(query, func);
}
ObjectPtr<Artwork> Podcast::getArtwork() const
{
return _artwork;
}
ArtworkId Podcast::getArtworkId() const
{
return _artwork.id();
}
void Podcast::setArtwork(ObjectPtr<Artwork> artwork)
{
_artwork = getDboPtr(artwork);
}
} // namespace lms::db
@@ -0,0 +1,115 @@
/*
* Copyright (C) 2020 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "database/objects/PodcastEpisode.hpp"
#include <Wt/Dbo/Impl.h>
#include <Wt/Dbo/WtSqlTraits.h>
#include "database/Session.hpp"
#include "database/objects/Artwork.hpp"
#include "database/objects/Podcast.hpp"
#include "Utils.hpp"
#include "traits/IdTypeTraits.hpp"
#include "traits/PathTraits.hpp"
DBO_INSTANTIATE_TEMPLATES(lms::db::PodcastEpisode)
namespace lms::db
{
namespace
{
Wt::Dbo::Query<Wt::Dbo::ptr<PodcastEpisode>> createQuery(Session& session, const PodcastEpisode::FindParameters& params)
{
auto query{ session.getDboSession()->query<Wt::Dbo::ptr<PodcastEpisode>>("SELECT p_e from podcast_episode p_e") };
if (params.manualDownloadState.has_value())
query.where("p_e.manual_download_state = ?").bind(static_cast<int>(params.manualDownloadState.value()));
if (params.podcast.isValid())
query.where("p_e.podcast_id = ?").bind(params.podcast);
switch (params.sortMode)
{
case PodcastEpisodeSortMode::None:
break;
case PodcastEpisodeSortMode::PubDateAsc:
query.orderBy("p_e.pub_date ASC");
break;
case PodcastEpisodeSortMode::PubDateDesc:
query.orderBy("p_e.pub_date DESC");
break;
}
return query;
}
} // namespace
PodcastEpisode::PodcastEpisode(ObjectPtr<Podcast> podcast)
: _podcast{ getDboPtr(podcast) }
{
}
PodcastEpisode::pointer PodcastEpisode::create(Session& session, ObjectPtr<Podcast> podcast)
{
return session.getDboSession()->add(std::unique_ptr<PodcastEpisode>{ new PodcastEpisode{ podcast } });
}
std::size_t PodcastEpisode::getCount(Session& session)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->query<int>("SELECT COUNT(*) FROM podcast_episode"));
}
PodcastEpisode::pointer PodcastEpisode::find(Session& session, PodcastEpisodeId id)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<PodcastEpisode>>("SELECT p_e from podcast_episode p_e").where("p_e.id = ?").bind(id));
}
PodcastEpisode::pointer PodcastEpisode::findNewtestEpisode(Session& session, PodcastId podcastId)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<PodcastEpisode>>("SELECT p_e from podcast_episode p_e").where("p_e.podcast_id = ?").bind(podcastId).orderBy("p_e.pub_date DESC").limit(1));
}
void PodcastEpisode::find(Session& session, const FindParameters& params, std::function<void(const pointer&)> func)
{
session.checkReadTransaction();
auto query{ createQuery(session, params) };
utils::forEachQueryRangeResult(query, params.range, func);
}
ObjectPtr<Artwork> PodcastEpisode::getArtwork() const
{
return _artwork;
}
ArtworkId PodcastEpisode::getArtworkId() const
{
return _artwork.id();
}
void PodcastEpisode::setArtwork(ObjectPtr<Artwork> artwork)
{
_artwork = getDboPtr(artwork);
}
} // namespace lms::db
@@ -82,7 +82,7 @@ namespace lms::db
template<typename Object>
void destroy(typename Object::IdType id)
{
destroy(std::span{ &id, 1 });
destroy<Object>(std::span{ &id, 1 });
}
template<typename Object>
@@ -163,6 +163,13 @@ namespace lms::db
PositionAsc,
};
enum class PodcastEpisodeSortMode
{
None,
PubDateAsc,
PubDateDesc,
};
enum class ReleaseSortMethod
{
None,
@@ -20,6 +20,7 @@
#pragma once
#include <filesystem>
#include <variant>
#include <Wt/Dbo/Field.h>
#include <Wt/WDateTime.h>
@@ -47,10 +48,12 @@ namespace lms::db
static pointer find(Session& session, ImageId id);
// getters
TrackEmbeddedImageId getTrackEmbeddedImageId() const { return _trackEmbeddedImage.id(); }
ImageId getImageId() const { return _image.id(); }
using UnderlyingId = std::variant<std::monostate, TrackEmbeddedImageId, ImageId>;
UnderlyingId getUnderlyingId() const;
Wt::WDateTime getLastWrittenTime() const;
std::filesystem::path getAbsoluteFilePath() const;
ObjectPtr<Image> getImage() const;
ImageId getImageId() const;
template<class Action>
void persist(Action& a)
@@ -85,6 +85,7 @@ namespace lms::db
std::size_t getFileSize() const { return _fileSize; }
std::size_t getWidth() const { return _width; }
std::size_t getHeight() const { return _height; }
std::string_view getMimeType() const { return _mimeType; }
// setters
void setAbsoluteFilePath(const std::filesystem::path& p);
@@ -92,6 +93,7 @@ namespace lms::db
void setFileSize(std::size_t fileSize) { _fileSize = fileSize; }
void setWidth(std::size_t width) { _width = width; }
void setHeight(std::size_t height) { _height = height; }
void setMimeType(std::string_view mimeType) { _mimeType = mimeType; }
void setDirectory(const ObjectPtr<Directory>& directory) { _directory = getDboPtr(directory); }
template<class Action>
@@ -104,6 +106,7 @@ namespace lms::db
Wt::Dbo::field(a, _width, "width");
Wt::Dbo::field(a, _height, "height");
Wt::Dbo::field(a, _mimeType, "mime_type");
Wt::Dbo::belongsTo(a, _directory, "directory", Wt::Dbo::OnDeleteCascade);
}
@@ -119,6 +122,7 @@ namespace lms::db
int _fileSize{};
int _width{};
int _height{};
std::string _mimeType;
Wt::Dbo::ptr<Directory> _directory;
};
@@ -0,0 +1,146 @@
/*
* Copyright (C) 2025 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <functional>
#include <string>
#include <string_view>
#include <Wt/Dbo/Field.h>
#include <Wt/Dbo/collection.h>
#include <Wt/WDateTime.h>
#include "database/Object.hpp"
#include "database/objects/ArtworkId.hpp"
#include "database/objects/PodcastId.hpp"
namespace lms::db
{
class Artwork;
class PodcastEpisode;
class Session;
class Podcast final : public Object<Podcast, PodcastId>
{
public:
static const std::size_t maxMediaLength{ 64 };
Podcast() = default;
static std::size_t getCount(Session& session);
static pointer find(Session& session, PodcastId id);
static pointer find(Session& session, std::string_view url);
static void find(Session& session, std::function<void(const pointer&)> func);
// getters
std::string_view getUrl() const { return _url; }
bool isDeleteRequested() const { return _deleteRequested; }
std::string_view getTitle() const { return _title; }
std::string_view getLink() const { return _link; }
std::string_view getDescription() const { return _description; }
std::string_view getLanguage() const { return _language; }
std::string_view getCopyright() const { return _copyright; }
Wt::WDateTime getLastBuildDate() const { return _lastBuildDate; }
std::string_view getAuthor() const { return _author; }
std::string_view getCategory() const { return _category; }
bool isExplicit() const { return _explicit; }
std::string_view getImageUrl() const { return _imageUrl; }
std::string_view getOwnerEmail() const { return _ownerEmail; }
std::string_view getOwnerName() const { return _ownerName; }
std::string_view getSubtitle() const { return _subtitle; }
std::string_view getSummary() const { return _summary; }
ObjectPtr<Artwork> getArtwork() const;
ArtworkId getArtworkId() const;
// setters
void setUrl(std::string_view url) { _url = url; }
void setDeleteRequested(bool deleteRequested) { _deleteRequested = deleteRequested; }
void setTitle(std::string_view title) { _title = title; }
void setLink(std::string_view link) { _link = link; }
void setDescription(std::string_view description) { _description = description; }
void setLanguage(std::string_view language) { _language = language; }
void setCopyright(std::string_view copyright) { _copyright = copyright; }
void setLastBuildDate(const Wt::WDateTime& lastBuildDate) { _lastBuildDate = lastBuildDate; }
void setAuthor(std::string_view author) { _author = author; }
void setCategory(std::string_view category) { _category = category; }
void setExplicit(bool explicit_) { _explicit = explicit_; }
void setImageUrl(std::string_view imageUrl) { _imageUrl = imageUrl; }
void setOwnerEmail(std::string_view ownerEmail) { _ownerEmail = ownerEmail; }
void setOwnerName(std::string_view ownerName) { _ownerName = ownerName; }
void setSubtitle(std::string_view subtitle) { _subtitle = subtitle; }
void setSummary(std::string_view summary) { _summary = summary; }
void setArtwork(ObjectPtr<Artwork> artwork);
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _url, "url");
Wt::Dbo::field(a, _deleteRequested, "delete_requested");
Wt::Dbo::field(a, _title, "title");
Wt::Dbo::field(a, _link, "link");
Wt::Dbo::field(a, _description, "description");
Wt::Dbo::field(a, _language, "language");
Wt::Dbo::field(a, _copyright, "copyright");
Wt::Dbo::field(a, _lastBuildDate, "last_build_date");
Wt::Dbo::field(a, _author, "author");
Wt::Dbo::field(a, _category, "category");
Wt::Dbo::field(a, _explicit, "explicit");
Wt::Dbo::field(a, _imageUrl, "image_url");
Wt::Dbo::field(a, _ownerEmail, "owner_email");
Wt::Dbo::field(a, _ownerName, "owner_name");
Wt::Dbo::field(a, _subtitle, "subtitle");
Wt::Dbo::field(a, _summary, "summary");
Wt::Dbo::belongsTo(a, _artwork, "artwork", Wt::Dbo::OnDeleteSetNull);
Wt::Dbo::hasMany(a, _episodes, Wt::Dbo::ManyToOne, "podcast");
}
private:
friend class Session;
Podcast(std::string_view url);
static pointer create(Session& session, std::string_view url);
std::string _url;
bool _deleteRequested{};
std::string _title;
std::string _link;
std::string _description;
std::string _language;
std::string _copyright;
Wt::WDateTime _lastBuildDate;
// itunes fields
std::string _author;
std::string _category;
bool _explicit{};
std::string _imageUrl;
std::string _ownerEmail;
std::string _ownerName;
std::string _subtitle;
std::string _summary;
Wt::Dbo::ptr<Artwork> _artwork;
Wt::Dbo::collection<Wt::Dbo::ptr<PodcastEpisode>> _episodes;
};
} // namespace lms::db
@@ -0,0 +1,186 @@
/*
* Copyright (C) 2025 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <chrono>
#include <filesystem>
#include <optional>
#include <string>
#include <string_view>
#include <Wt/Dbo/Field.h>
#include <Wt/Dbo/collection.h>
#include <Wt/WDateTime.h>
#include "database/Object.hpp"
#include "database/Types.hpp"
#include "database/objects/ArtworkId.hpp"
#include "database/objects/PodcastEpisodeId.hpp"
#include "database/objects/PodcastId.hpp"
namespace lms::db
{
class Artwork;
class Podcast;
class Session;
class PodcastEpisode final : public Object<PodcastEpisode, PodcastEpisodeId>
{
public:
enum class ManualDownloadState
{
None = 0,
DownloadRequested = 1,
DeleteRequested = 3,
};
struct FindParameters
{
PodcastEpisodeSortMode sortMode = PodcastEpisodeSortMode::None;
db::PodcastId podcast; // if set, only episodes from this podcast
std::optional<Range> range;
std::optional<ManualDownloadState> manualDownloadState; // if set, only episodes that matches one of these states
FindParameters& setSortMode(PodcastEpisodeSortMode _sortMode)
{
sortMode = _sortMode;
return *this;
}
FindParameters& setPodcast(db::PodcastId _podcast)
{
podcast = _podcast;
return *this;
}
FindParameters& setRange(const std::optional<Range>& _range)
{
range = _range;
return *this;
}
FindParameters& setManualDownloadState(std::optional<ManualDownloadState> state)
{
manualDownloadState = state;
return *this;
}
};
PodcastEpisode() = default;
static std::size_t getCount(Session& session);
static pointer find(Session& session, PodcastEpisodeId id);
static pointer findNewtestEpisode(Session& session, PodcastId id);
static void find(Session& session, const FindParameters& params, std::function<void(const pointer&)> func);
// getters
ManualDownloadState getManualDownloadState() const { return _manualDownloadState; }
const std::filesystem::path& getAudioRelativeFilePath() const { return _audioRelativeFilePath; }
std::string_view getTitle() const { return _title; }
std::string_view getLink() const { return _link; }
std::string_view getDescription() const { return _description; }
std::string_view getAuthor() const { return _author; }
std::string_view getCategory() const { return _category; }
std::string_view getEnclosureUrl() const { return _enclosureUrl; }
std::string_view getEnclosureContentType() const { return _enclosureContentType; }
std::int64_t getEnclosureLength() const { return _enclosureLength; }
const Wt::WDateTime& getPubDate() const { return _pubDate; }
std::string_view getImageUrl() const { return _imageUrl; }
std::string_view getSubtitle() const { return _subtitle; }
std::string_view getSummary() const { return _summary; }
bool isExplicit() const { return _explicit; }
std::chrono::duration<int, std::milli> getDuration() const { return _duration; }
ObjectPtr<Podcast> getPodcast() const { return _podcast; }
PodcastId getPodcastId() const { return _podcast.id(); }
ObjectPtr<Artwork> getArtwork() const;
ArtworkId getArtworkId() const;
// setters
void setManualDownloadState(ManualDownloadState state) { _manualDownloadState = state; }
void setAudioRelativeFilePath(const std::filesystem::path& relativeFilePath) { _audioRelativeFilePath = relativeFilePath; }
void setTitle(std::string_view title) { _title = title; }
void setLink(std::string_view link) { _link = link; }
void setDescription(std::string_view description) { _description = description; }
void setAuthor(std::string_view author) { _author = author; }
void setCategory(std::string_view category) { _category = category; }
void setEnclosureUrl(std::string_view enclosureUrl) { _enclosureUrl = enclosureUrl; }
void setEnclosureContentType(std::string_view enclosureContentType) { _enclosureContentType = enclosureContentType; }
void setEnclosureLength(uint64_t enclosureLength) { _enclosureLength = enclosureLength; }
void setPubDate(const Wt::WDateTime& pubDate) { _pubDate = pubDate; }
void setImageUrl(std::string_view imageUrl) { _imageUrl = imageUrl; }
void setSubtitle(std::string_view subtitle) { _subtitle = subtitle; }
void setSummary(std::string_view summary) { _summary = summary; }
void setExplicit(bool explicit_) { _explicit = explicit_; }
void setDuration(std::chrono::duration<int, std::milli> duration) { _duration = duration; }
void setArtwork(ObjectPtr<Artwork> artwork);
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _manualDownloadState, "manual_download_state");
Wt::Dbo::field(a, _audioRelativeFilePath, "audio_relative_file_path");
Wt::Dbo::field(a, _title, "title");
Wt::Dbo::field(a, _link, "link");
Wt::Dbo::field(a, _description, "description");
Wt::Dbo::field(a, _author, "author");
Wt::Dbo::field(a, _category, "category");
Wt::Dbo::field(a, _enclosureUrl, "enclosure_url");
Wt::Dbo::field(a, _enclosureContentType, "enclosure_content_type");
Wt::Dbo::field(a, _enclosureLength, "enclosure_size");
Wt::Dbo::field(a, _pubDate, "pub_date");
Wt::Dbo::field(a, _imageUrl, "image_url");
Wt::Dbo::field(a, _subtitle, "subtitle");
Wt::Dbo::field(a, _summary, "summary");
Wt::Dbo::field(a, _explicit, "explicit");
Wt::Dbo::field(a, _duration, "duration");
Wt::Dbo::belongsTo(a, _artwork, "artwork", Wt::Dbo::OnDeleteSetNull);
Wt::Dbo::belongsTo(a, _podcast, "podcast", Wt::Dbo::OnDeleteCascade);
}
private:
friend class Session;
PodcastEpisode(ObjectPtr<Podcast> podcast);
static pointer create(Session& session, ObjectPtr<Podcast> podcast);
ManualDownloadState _manualDownloadState{ ManualDownloadState::None };
std::filesystem::path _audioRelativeFilePath; // relative to cache dir, only set if downloaded
std::string _url;
std::string _title;
std::string _link;
std::string _description;
std::string _author;
std::string _category;
std::string _enclosureUrl;
std::string _enclosureContentType;
int _enclosureLength{ 0 };
Wt::WDateTime _pubDate;
// itunes fields
std::string _imageUrl;
std::string _subtitle;
std::string _summary;
bool _explicit{};
std::chrono::duration<int, std::milli> _duration{ 0 };
Wt::Dbo::ptr<Artwork> _artwork;
Wt::Dbo::ptr<Podcast> _podcast;
};
} // namespace lms::db
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2025 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "database/IdType.hpp"
LMS_DECLARE_IDTYPE(PodcastEpisodeId)
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2025 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "database/IdType.hpp"
LMS_DECLARE_IDTYPE(PodcastId)
+23
View File
@@ -84,4 +84,27 @@ namespace lms::db::tests
EXPECT_EQ(artwork.get()->getAbsoluteFilePath(), "/tmp/foo");
}
}
TEST_F(DatabaseFixture, Artwork_underlyingId)
{
ScopedImage image1{ session, "/MyImage" };
ScopedArtwork artwork1{ session, image1.lockAndGet() };
ScopedTrackEmbeddedImage image2{ session };
ScopedArtwork artwork2{ session, image2.lockAndGet() };
{
auto transaction{ session.createReadTransaction() };
const auto underlyingId{ artwork1.get()->getUnderlyingId() };
ASSERT_TRUE(std::holds_alternative<db::ImageId>(underlyingId));
EXPECT_EQ(std::get<db::ImageId>(underlyingId), image1.getId());
}
{
auto transaction{ session.createReadTransaction() };
const auto underlyingId{ artwork2.get()->getUnderlyingId() };
ASSERT_TRUE(std::holds_alternative<db::TrackEmbeddedImageId>(underlyingId));
EXPECT_EQ(std::get<db::TrackEmbeddedImageId>(underlyingId), image2.getId());
}
}
} // namespace lms::db::tests
+1
View File
@@ -13,6 +13,7 @@ add_executable(test-database
Medium.cpp
Migration.cpp
PlayListFile.cpp
Podcast.cpp
RatedArtist.cpp
RatedRelease.cpp
RatedTrack.cpp
+4
View File
@@ -28,6 +28,8 @@
#include "database/objects/Medium.hpp"
#include "database/objects/PlayListFile.hpp"
#include "database/objects/PlayQueue.hpp"
#include "database/objects/Podcast.hpp"
#include "database/objects/PodcastEpisode.hpp"
#include "database/objects/RatedArtist.hpp"
#include "database/objects/RatedRelease.hpp"
#include "database/objects/RatedTrack.hpp"
@@ -359,6 +361,8 @@ VALUES
EXPECT_FALSE(Listen::find(session, ListenId{}));
EXPECT_FALSE(PlayListFile::find(session, PlayListFileId{}));
EXPECT_FALSE(PlayQueue::find(session, PlayQueueId{}));
EXPECT_FALSE(Podcast::find(session, PodcastId{}));
EXPECT_FALSE(PodcastEpisode::find(session, PodcastEpisodeId{}));
EXPECT_FALSE(RatedArtist::find(session, RatedArtistId{}));
EXPECT_FALSE(RatedRelease::find(session, RatedReleaseId{}));
EXPECT_FALSE(RatedTrack::find(session, RatedTrackId{}));
+99
View File
@@ -0,0 +1,99 @@
/*
* Copyright (C) 2025 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Common.hpp"
#include "database/objects/Artwork.hpp"
#include "database/objects/Podcast.hpp"
namespace lms::db::tests
{
using ScopedDirectory = ScopedEntity<db::Directory>;
using ScopedPodcast = ScopedEntity<db::Podcast>;
TEST_F(DatabaseFixture, Podcast)
{
{
auto transaction{ session.createReadTransaction() };
EXPECT_EQ(Podcast::getCount(session), 0);
}
ScopedPodcast podcast{ session, "podcastUrl" };
{
auto transaction{ session.createReadTransaction() };
EXPECT_EQ(Podcast::getCount(session), 1);
Podcast::pointer p{ Podcast::find(session, podcast.getId()) };
ASSERT_NE(p, Podcast::pointer{});
EXPECT_EQ(p->getUrl(), "podcastUrl");
EXPECT_EQ(p->getTitle(), "");
EXPECT_EQ(p->getLink(), "");
EXPECT_EQ(p->getDescription(), "");
EXPECT_EQ(p->getLanguage(), "");
EXPECT_EQ(p->getCopyright(), "");
EXPECT_EQ(p->getLastBuildDate(), Wt::WDateTime());
EXPECT_EQ(p->getAuthor(), "");
EXPECT_EQ(p->getCategory(), "");
EXPECT_EQ(p->isExplicit(), false);
EXPECT_EQ(p->getImageUrl(), "");
EXPECT_EQ(p->getOwnerEmail(), "");
}
{
auto transaction{ session.createWriteTransaction() };
Podcast::pointer p{ Podcast::find(session, podcast.getId()) };
ASSERT_NE(p, Podcast::pointer{});
p.modify()->setUrl("newPodcastUrl");
p.modify()->setTitle("newTitle");
p.modify()->setLink("newLink");
p.modify()->setDescription("newDescription");
p.modify()->setLanguage("newLanguage");
p.modify()->setCopyright("newCopyright");
p.modify()->setLastBuildDate(Wt::WDateTime::currentDateTime());
p.modify()->setAuthor("newAuthor");
p.modify()->setCategory("newCategory");
p.modify()->setExplicit(true);
p.modify()->setImageUrl("newImageUrl");
p.modify()->setOwnerEmail("newOwnerEmail");
p.modify()->setOwnerName("newOwnerName");
}
{
auto transaction{ session.createReadTransaction() };
Podcast::pointer img{ Podcast::find(session, podcast.getId()) };
ASSERT_NE(img, Podcast::pointer{});
EXPECT_EQ(img->getUrl(), "newPodcastUrl");
EXPECT_EQ(img->getTitle(), "newTitle");
EXPECT_EQ(img->getLink(), "newLink");
EXPECT_EQ(img->getDescription(), "newDescription");
EXPECT_EQ(img->getLanguage(), "newLanguage");
EXPECT_EQ(img->getCopyright(), "newCopyright");
EXPECT_TRUE(img->getLastBuildDate().isValid());
EXPECT_EQ(img->getAuthor(), "newAuthor");
EXPECT_EQ(img->getCategory(), "newCategory");
EXPECT_TRUE(img->isExplicit());
EXPECT_EQ(img->getImageUrl(), "newImageUrl");
EXPECT_EQ(img->getOwnerEmail(), "newOwnerEmail");
EXPECT_EQ(img->getOwnerName(), "newOwnerName");
}
}
} // namespace lms::db::tests