Skip to content

Commit

Permalink
Merge pull request #834 from hambre/hambre/cd-metadata
Browse files Browse the repository at this point in the history
Query audio CD metadata from MusicBrainz
  • Loading branch information
paul-h authored Jan 10, 2024
2 parents 32c738b + cfc75df commit 498b5a8
Show file tree
Hide file tree
Showing 8 changed files with 602 additions and 4 deletions.
63 changes: 62 additions & 1 deletion mythplugins/configure
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,17 @@ int main(void){ $func(); }
EOF
}

check_class_cxx(){
log check_class_cxx "$@"
class=$1
header=$2
shift 2
check_ld_cxx "$@" <<EOF
#include <$header>
int main(void){ $class; }
EOF
}

check_lib_cxx(){
log check_lib_cxx "$@"
header="$1"
Expand All @@ -269,6 +280,14 @@ check_lib_cxx(){
check_header_cxx $header && check_func_cxx $func $header "$@"
}

check_lib_cxx2(){
log check_lib_cxx2 "$@"
header="$1"
func="$2"
shift 2
check_header_cxx $header && check_class_cxx $func $header "$@"
}

cp_if_changed(){
cmp -s "$1" "$2" && { test "$quiet" != "yes" && echo "$2 is unchanged"; } && return
mkdir -p "$(dirname $2)"
Expand Down Expand Up @@ -302,6 +321,7 @@ exif
newexif
dcraw
cdio
musicbrainz
"

DEPEND_LIST="
Expand Down Expand Up @@ -356,6 +376,7 @@ MythGame related options:
MythMusic related options:
--enable-mythmusic build the mythmusic plugin [$music]
--enable-cdio enable cd playback [$cdio]
--enable-musicbrainz enable fetching cd metadata from musicbrainz [$musicbrainz]
MythNetvision related options:
--enable-mythnetvision build the mythnetvision plugin [$netvision]
Expand Down Expand Up @@ -691,6 +712,22 @@ if test x"$icc" != x ; then
fi
fi

libmusicbrainz_pc(){
if $(pkg-config libmusicbrainz5cc --exists) ; then
echo "libmusicbrainz5cc"
else
echo "libmusicbrainz5"
fi
}

libcoverart_pc(){
if $(pkg-config libcoverartcc --exists) ; then
echo "libcoverartcc"
else
echo "libcoverart"
fi
}

if enabled music ; then

if ! check_lib vorbis/codec.h vorbis_info_init -lvorbis || ! check_lib vorbis/vorbisenc.h vorbis_encode_setup_vbr -lvorbisenc -lvorbis -logg ; then
Expand All @@ -715,7 +752,21 @@ if enabled music ; then
enable cdio; # nop
else
disable cdio
fi
fi
fi
if enabled musicbrainz ; then
if ! check_lib discid/discid.h discid_new -ldiscid ; then
disable musicbrainz
echo "MusicBrainz support requires libdiscid."
elif ! check_lib_cxx2 musicbrainz5/Query.h MusicBrainz5::CQuery\(\"test\"\) $(pkg-config $(libmusicbrainz_pc) --cflags --libs); then
disable musicbrainz
echo "MusicBrainz support requires libmusicbrainz5."
elif ! check_lib_cxx2 coverart/CoverArt.h CoverArtArchive::CCoverArt\(\"test\"\) $(pkg-config $(libcoverart_pc) --cflags --libs); then
disable musicbrainz
echo "MusicBrainz support requires libcoverart."
else
enable musicbrainz; # nop
fi
fi

if ! check_lib lame/lame.h lame_init -lmp3lame ; then
Expand Down Expand Up @@ -852,6 +903,16 @@ if enabled music ; then
echo "#define HAVE_CDIO 1" >> ./mythmusic/mythmusic/config.h
echo "CONFIG += cdio" >> ./mythmusic/mythmusic/config.pro
echo " libcdio support will be included in MythMusic"
if enabled musicbrainz ; then
echo "#define HAVE_MUSICBRAINZ 1" >> ./mythmusic/mythmusic/config.h
echo "CONFIG += link_pkgconfig" >> ./mythmusic/mythmusic/config.pro
echo "CONFIG += musicbrainz" >> ./mythmusic/mythmusic/config.pro
echo "PKGCONFIG += libdiscid $(libmusicbrainz_pc) $(libcoverart_pc)" >> ./mythmusic/mythmusic/config.pro
echo " musicbrainz support will be included in MythMusic"
else
echo "#undef HAVE_MUSICBRAINZ" >> ./mythmusic/mythmusic/config.h
echo " musicbrainz support will not be included in MythMusic"
fi
else
echo "#undef HAVE_CDIO" >> ./mythmusic/mythmusic/config.h
echo " libcdio support will not be included in MythMusic"
Expand Down
29 changes: 27 additions & 2 deletions mythplugins/mythmusic/mythmusic/cddecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ extern "C" {

// MythMusic
#include "constants.h"

static constexpr const char* CDEXT { ".cda" };
static constexpr long kSamplesPerSec { 44100 };

Expand Down Expand Up @@ -661,7 +660,22 @@ MusicMetadata *CdDecoder::getMetadata()
if (title.isEmpty() || artist.isEmpty() || album.isEmpty())
#endif // CDTEXT
{
//TODO: add MusicBrainz lookup
#ifdef HAVE_MUSICBRAINZ
if (isDiscChanged)
{
// lazy load whole CD metadata
getMusicBrainz().queryForDevice(m_deviceName);
}
if (getMusicBrainz().hasMetadata(m_setTrackNum))
{
auto *metadata = getMusicBrainz().getMetadata(m_setTrackNum);
if (metadata)
{
metadata->setFilename(getURL());
return metadata;
}
}
#endif // HAVE_MUSICBRAINZ
}

if (compilation_artist.toLower().left(7) == "various")
Expand All @@ -684,6 +698,17 @@ MusicMetadata *CdDecoder::getMetadata()
return m;
}

#ifdef HAVE_MUSICBRAINZ

MusicBrainz & CdDecoder::getMusicBrainz()
{
static MusicBrainz s_musicBrainz;
return s_musicBrainz;
}

#endif // HAVE_MUSICBRAINZ


// pure virtual
bool CdDecoderFactory::supports(const QString &source) const
{
Expand Down
9 changes: 9 additions & 0 deletions mythplugins/mythmusic/mythmusic/cddecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
# endif
#endif

#ifdef HAVE_MUSICBRAINZ
#include "musicbrainz.h"
#endif // HAVE_MUSICBRAINZ

class MusicMetadata;

class CdDecoder : public Decoder
Expand Down Expand Up @@ -84,6 +88,11 @@ class CdDecoder : public Decoder
lsn_t m_end {CDIO_INVALID_LSN};
lsn_t m_curPos {CDIO_INVALID_LSN};
#endif

#ifdef HAVE_MUSICBRAINZ
static MusicBrainz & getMusicBrainz();
#endif // HAVE_MUSICBRAINZ

};

#endif
Expand Down
Loading

0 comments on commit 498b5a8

Please sign in to comment.