Add copyright/copyrightURL support and display it in the release view
This commit is contained in:
@@ -79,6 +79,9 @@
|
||||
<message id="Lms.Explore.ArtistsInfo.recently-added">Recently added</message>
|
||||
<message id="Lms.Explore.ArtistsInfo.most-played">Top artists</message>
|
||||
|
||||
<!--Explore:Release-->
|
||||
<message id="Lms.Explore.Release.copyright">Copyright</message>
|
||||
|
||||
<!--Explore:Releases-->
|
||||
<message id="Lms.Explore.ReleasesInfo.recently-added">Recently added</message>
|
||||
<message id="Lms.Explore.ReleasesInfo.most-played">Top releases</message>
|
||||
|
||||
@@ -16,6 +16,13 @@
|
||||
${play-btn}${add-btn}
|
||||
</div>
|
||||
${tracks}
|
||||
${<if-has-copyright-or-copyright-url>}
|
||||
<div class="page-header">
|
||||
<h4><small>${tr:Lms.Explore.Release.copyright}</small></h4>
|
||||
</div>
|
||||
${<if-has-copyright>}<small>${copyright}</small>${</if-has-copyright>}
|
||||
${<if-has-copyright-url>}<small>${copyright-url}</small>${</if-has-copyright-url>}
|
||||
${</if-has-copyright-or-copyright-url>}
|
||||
</message>
|
||||
|
||||
<message id="Lms.Explore.Release.template.entry">
|
||||
|
||||
@@ -48,9 +48,9 @@ struct TranscodeParameters
|
||||
Encoding encoding = Encoding::MP3;
|
||||
std::size_t bitrate = 128000;
|
||||
boost::optional<std::size_t> stream = boost::none; // Id of the stream to be transcoded (auto detect by default)
|
||||
boost::optional<std::chrono::seconds> offset;
|
||||
boost::optional<std::chrono::seconds> offset = boost::none;;
|
||||
|
||||
TranscodeParameters() {}
|
||||
TranscodeParameters() = default;
|
||||
};
|
||||
|
||||
class Transcoder
|
||||
|
||||
@@ -178,15 +178,14 @@ Grabber::getFromTrack(Wt::Dbo::Session& session, Database::IdType trackId, std::
|
||||
Track::pointer track = Track::getById(session, trackId);
|
||||
if (track)
|
||||
{
|
||||
Track::CoverType coverType = track->getCoverType();
|
||||
bool hasCover = track->hasCover();
|
||||
boost::filesystem::path trackPath = track->getPath();
|
||||
|
||||
transaction.commit();
|
||||
|
||||
if (coverType == Track::CoverType::Embedded)
|
||||
if (hasCover)
|
||||
cover = getFromTrack(trackPath);
|
||||
|
||||
if (!cover)
|
||||
else
|
||||
cover = getFromDirectory(trackPath.parent_path());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "Release.hpp"
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
|
||||
#include "Artist.hpp"
|
||||
#include "Cluster.hpp"
|
||||
#include "SqlQuery.hpp"
|
||||
@@ -163,7 +165,7 @@ Release::getReleaseYear(bool original) const
|
||||
.groupBy(field)
|
||||
.bind(this->id());
|
||||
|
||||
/* various dates, no date */
|
||||
// various dates => no date
|
||||
if (dates.empty() || dates.size() > 1)
|
||||
return boost::none;
|
||||
|
||||
@@ -175,6 +177,46 @@ Release::getReleaseYear(bool original) const
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
boost::optional<std::string>
|
||||
Release::getCopyright() const
|
||||
{
|
||||
assert(session());
|
||||
|
||||
Wt::Dbo::collection<std::string> copyrights = session()->query<std::string>
|
||||
("SELECT copyright FROM track t INNER JOIN release r ON r.id = t.release_id")
|
||||
.where("r.id = ?")
|
||||
.groupBy("copyright")
|
||||
.bind(this->id());
|
||||
|
||||
std::vector<std::string> values(copyrights.begin(), copyrights.end());
|
||||
|
||||
// various copyrights => no copyright
|
||||
if (values.empty() || values.size() > 1 || values.front().empty())
|
||||
return boost::none;
|
||||
|
||||
return values.front();
|
||||
}
|
||||
|
||||
boost::optional<std::string>
|
||||
Release::getCopyrightURL() const
|
||||
{
|
||||
assert(session());
|
||||
|
||||
Wt::Dbo::collection<std::string> copyrights = session()->query<std::string>
|
||||
("SELECT copyright_url FROM track t INNER JOIN release r ON r.id = t.release_id")
|
||||
.where("r.id = ?")
|
||||
.groupBy("copyright_url")
|
||||
.bind(this->id());
|
||||
|
||||
std::vector<std::string> values(copyrights.begin(), copyrights.end());
|
||||
|
||||
// various copyright URLs => no copyright URL
|
||||
if (values.empty() || values.size() > 1 || values.front().empty())
|
||||
return boost::none;
|
||||
|
||||
return values.front();
|
||||
}
|
||||
|
||||
std::vector<Wt::Dbo::ptr<Artist>>
|
||||
Release::getArtists() const
|
||||
{
|
||||
|
||||
@@ -69,6 +69,8 @@ class Release : public Wt::Dbo::Dbo<Release>
|
||||
|
||||
// Utility functions
|
||||
boost::optional<int> getReleaseYear(bool originalDate = false) const; // 0 if unknown or various
|
||||
boost::optional<std::string> getCopyright() const;
|
||||
boost::optional<std::string> getCopyrightURL() const;
|
||||
|
||||
// Accessors
|
||||
std::string getName() const { return _name; }
|
||||
|
||||
@@ -224,6 +224,18 @@ Track::getOriginalYear() const
|
||||
return (_originalYear > 0) ? boost::make_optional<int>(_originalYear) : boost::none;
|
||||
}
|
||||
|
||||
boost::optional<std::string>
|
||||
Track::getCopyright() const
|
||||
{
|
||||
return _copyright != "" ? boost::make_optional<std::string>(_copyright) : boost::none;
|
||||
}
|
||||
|
||||
boost::optional<std::string>
|
||||
Track::getCopyrightURL() const
|
||||
{
|
||||
return _copyrightURL != "" ? boost::make_optional<std::string>(_copyrightURL) : boost::none;
|
||||
}
|
||||
|
||||
std::vector<std::vector<Cluster::pointer>>
|
||||
Track::getClusterGroups(std::vector<ClusterType::pointer> clusterTypes, std::size_t size) const
|
||||
{
|
||||
|
||||
+15
-11
@@ -49,12 +49,6 @@ class Track : public Wt::Dbo::Dbo<Track>
|
||||
Track() {}
|
||||
Track(const boost::filesystem::path& p);
|
||||
|
||||
enum class CoverType
|
||||
{
|
||||
Embedded, // Contains embedded cover
|
||||
None, // No local cover available
|
||||
};
|
||||
|
||||
// Find utility functions
|
||||
static pointer getByPath(Wt::Dbo::Session& session, const boost::filesystem::path& p);
|
||||
static pointer getById(Wt::Dbo::Session& session, IdType id);
|
||||
@@ -95,8 +89,10 @@ class Track : public Wt::Dbo::Dbo<Track>
|
||||
void setYear(int year) { _year = year; }
|
||||
void setOriginalYear(int year) { _originalYear = year; }
|
||||
void setGenres(const std::string& genreList) { _genreList = genreList; }
|
||||
void setCoverType(CoverType coverType) { _coverType = coverType; }
|
||||
void setHasCover(bool hasCover) { _hasCover = hasCover; }
|
||||
void setMBID(const std::string& MBID) { _MBID = MBID; }
|
||||
void setCopyright(const std::string& copyright) { _copyright = std::string(copyright, 0, _maxCopyrightLength); }
|
||||
void setCopyrightURL(const std::string& copyrightURL) { _copyrightURL = std::string(copyrightURL, 0, _maxCopyrightURLLength); }
|
||||
void setArtist(Wt::Dbo::ptr<Artist> artist) { _artist = artist; }
|
||||
void setRelease(Wt::Dbo::ptr<Release> release) { _release = release; }
|
||||
|
||||
@@ -113,8 +109,10 @@ class Track : public Wt::Dbo::Dbo<Track>
|
||||
Wt::WDateTime getLastWriteTime() const { return _fileLastWrite; }
|
||||
Wt::WDateTime getAddedTime() const { return _fileAdded; }
|
||||
const std::vector<unsigned char>& getChecksum() const { return _fileChecksum; }
|
||||
CoverType getCoverType() const { return _coverType; }
|
||||
bool hasCover() const { return _hasCover; }
|
||||
const std::string& getMBID() const { return _MBID; }
|
||||
boost::optional<std::string> getCopyright() const;
|
||||
boost::optional<std::string> getCopyrightURL() const;
|
||||
Wt::Dbo::ptr<Artist> getArtist() const { return _artist; }
|
||||
Wt::Dbo::ptr<Release> getRelease() const { return _release; }
|
||||
std::vector<Wt::Dbo::ptr<Cluster>> getClusters() const;
|
||||
@@ -138,8 +136,10 @@ class Track : public Wt::Dbo::Dbo<Track>
|
||||
Wt::Dbo::field(a, _fileLastWrite, "file_last_write");
|
||||
Wt::Dbo::field(a, _fileAdded, "file_added");
|
||||
Wt::Dbo::field(a, _fileChecksum, "checksum");
|
||||
Wt::Dbo::field(a, _coverType, "cover_type");
|
||||
Wt::Dbo::field(a, _hasCover, "has_cover");
|
||||
Wt::Dbo::field(a, _MBID, "mbid");
|
||||
Wt::Dbo::field(a, _copyright, "copyright");
|
||||
Wt::Dbo::field(a, _copyrightURL, "copyright_url");
|
||||
Wt::Dbo::belongsTo(a, _release, "release", Wt::Dbo::OnDeleteCascade);
|
||||
Wt::Dbo::belongsTo(a, _artist, "artist", Wt::Dbo::OnDeleteCascade);
|
||||
Wt::Dbo::hasMany(a, _clusters, Wt::Dbo::ManyToMany, "track_cluster", "", Wt::Dbo::OnDeleteCascade);
|
||||
@@ -149,6 +149,8 @@ class Track : public Wt::Dbo::Dbo<Track>
|
||||
private:
|
||||
|
||||
static const std::size_t _maxNameLength = 128;
|
||||
static const std::size_t _maxCopyrightLength = 128;
|
||||
static const std::size_t _maxCopyrightURLLength = 128;
|
||||
|
||||
int _scanVersion = 0;
|
||||
int _trackNumber = 0;
|
||||
@@ -166,8 +168,10 @@ class Track : public Wt::Dbo::Dbo<Track>
|
||||
std::vector<unsigned char> _fileChecksum;
|
||||
Wt::WDateTime _fileLastWrite;
|
||||
Wt::WDateTime _fileAdded;
|
||||
CoverType _coverType = CoverType::None;
|
||||
std::string _MBID = ""; // Musicbrainz Identifier
|
||||
bool _hasCover;
|
||||
std::string _MBID; // Musicbrainz Identifier
|
||||
std::string _copyright;
|
||||
std::string _copyrightURL;
|
||||
|
||||
Wt::Dbo::ptr<Artist> _artist;
|
||||
Wt::Dbo::ptr<Release> _release;
|
||||
|
||||
@@ -50,6 +50,8 @@ namespace MetaData
|
||||
MusicBrainzTrackID, // string
|
||||
MusicBrainzRecordingID, // string
|
||||
AcoustID, // string
|
||||
Copyright, // string
|
||||
CopyrightURL, // string
|
||||
};
|
||||
|
||||
// Used by Streams
|
||||
|
||||
@@ -194,6 +194,14 @@ TagLibParser::parse(const boost::filesystem::path& p, bool debug)
|
||||
if (items.find(MetaData::Type::HasCover) == items.end())
|
||||
items.insert( std::make_pair(MetaData::Type::HasCover, true));
|
||||
}
|
||||
else if (tag == "COPYRIGHT")
|
||||
{
|
||||
items.insert(std::make_pair(MetaData::Type::Copyright, values.front().to8Bit()));
|
||||
}
|
||||
else if (tag == "COPYRIGHTURL")
|
||||
{
|
||||
items.insert(std::make_pair(MetaData::Type::CopyrightURL, values.front().to8Bit()));
|
||||
}
|
||||
else if (_clusterTypeNames.find(tag) != _clusterTypeNames.end())
|
||||
{
|
||||
std::set<std::string> clusterNames;
|
||||
|
||||
@@ -566,7 +566,18 @@ MediaScanner::scanAudioFile(const boost::filesystem::path& file, bool forceScan,
|
||||
{
|
||||
bool hasCover = boost::any_cast<bool>((*items)[MetaData::Type::HasCover]);
|
||||
|
||||
track.modify()->setCoverType( hasCover ? Track::CoverType::Embedded : Track::CoverType::None );
|
||||
track.modify()->setHasCover(hasCover);
|
||||
}
|
||||
|
||||
if ((*items).find(MetaData::Type::Copyright) != (*items).end())
|
||||
{
|
||||
|
||||
track.modify()->setCopyright( boost::any_cast<std::string>((*items)[MetaData::Type::Copyright]) );
|
||||
}
|
||||
|
||||
if ((*items).find(MetaData::Type::CopyrightURL) != (*items).end())
|
||||
{
|
||||
track.modify()->setCopyrightURL( boost::any_cast<std::string>((*items)[MetaData::Type::CopyrightURL]) );
|
||||
}
|
||||
|
||||
transaction.commit();
|
||||
|
||||
@@ -94,6 +94,28 @@ Release::refresh()
|
||||
}
|
||||
}
|
||||
|
||||
boost::optional<std::string> copyright = release->getCopyright();
|
||||
boost::optional<std::string> copyrightURL = release->getCopyrightURL();
|
||||
|
||||
t->setCondition("if-has-copyright-or-copyright-url", copyright || copyrightURL);
|
||||
|
||||
if (copyrightURL)
|
||||
{
|
||||
t->setCondition("if-has-copyright-url", true);
|
||||
|
||||
Wt::WLink link(*copyrightURL);
|
||||
link.setTarget(Wt::LinkTarget::NewWindow);
|
||||
Wt::WAnchor* anchor = t->bindNew<Wt::WAnchor>("copyright-url", link);
|
||||
anchor->setTextFormat(Wt::TextFormat::Plain);
|
||||
anchor->setText(Wt::WString::fromUTF8(*copyrightURL));
|
||||
}
|
||||
|
||||
if (copyright)
|
||||
{
|
||||
t->setCondition("if-has-copyright", true);
|
||||
t->bindString("copyright", Wt::WString::fromUTF8(*copyright), Wt::TextFormat::Plain);
|
||||
}
|
||||
|
||||
{
|
||||
auto artists = release->getArtists();
|
||||
if (artists.size() > 1)
|
||||
|
||||
@@ -112,6 +112,14 @@ int main(int argc, char *argv[])
|
||||
std::cout << "AcoustID: " << boost::any_cast<std::string>(item.second) << std::endl;
|
||||
break;
|
||||
|
||||
case MetaData::Type::Copyright:
|
||||
std::cout << "Copyright: " << boost::any_cast<std::string>(item.second) << std::endl;
|
||||
break;
|
||||
|
||||
case MetaData::Type::CopyrightURL:
|
||||
std::cout << "CopyrightURL: " << boost::any_cast<std::string>(item.second) << std::endl;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user