Add:Parsing meta tags from podcast episode audio file #1488

This commit is contained in:
advplyr 2023-03-30 18:04:21 -05:00
parent 704fbaced8
commit 212b97fa20
7 changed files with 197 additions and 5 deletions

View file

@ -1,9 +1,12 @@
class AudioMetaTags {
constructor(metadata) {
this.tagAlbum = null
this.tagAlbumSort = null
this.tagArtist = null
this.tagArtistSort = null
this.tagGenre = null
this.tagTitle = null
this.tagTitleSort = null
this.tagSeries = null
this.tagSeriesPart = null
this.tagTrack = null
@ -20,6 +23,9 @@ class AudioMetaTags {
this.tagIsbn = null
this.tagLanguage = null
this.tagASIN = null
this.tagItunesId = null
this.tagPodcastType = null
this.tagEpisodeType = null
this.tagOverdriveMediaMarker = null
this.tagOriginalYear = null
this.tagReleaseCountry = null
@ -94,9 +100,12 @@ class AudioMetaTags {
construct(metadata) {
this.tagAlbum = metadata.tagAlbum || null
this.tagAlbumSort = metadata.tagAlbumSort || null
this.tagArtist = metadata.tagArtist || null
this.tagArtistSort = metadata.tagArtistSort || null
this.tagGenre = metadata.tagGenre || null
this.tagTitle = metadata.tagTitle || null
this.tagTitleSort = metadata.tagTitleSort || null
this.tagSeries = metadata.tagSeries || null
this.tagSeriesPart = metadata.tagSeriesPart || null
this.tagTrack = metadata.tagTrack || null
@ -113,6 +122,9 @@ class AudioMetaTags {
this.tagIsbn = metadata.tagIsbn || null
this.tagLanguage = metadata.tagLanguage || null
this.tagASIN = metadata.tagASIN || null
this.tagItunesId = metadata.tagItunesId || null
this.tagPodcastType = metadata.tagPodcastType || null
this.tagEpisodeType = metadata.tagEpisodeType || null
this.tagOverdriveMediaMarker = metadata.tagOverdriveMediaMarker || null
this.tagOriginalYear = metadata.tagOriginalYear || null
this.tagReleaseCountry = metadata.tagReleaseCountry || null
@ -128,9 +140,12 @@ class AudioMetaTags {
// Data parsed in prober.js
setData(payload) {
this.tagAlbum = payload.file_tag_album || null
this.tagAlbumSort = payload.file_tag_albumsort || null
this.tagArtist = payload.file_tag_artist || null
this.tagArtistSort = payload.file_tag_artistsort || null
this.tagGenre = payload.file_tag_genre || null
this.tagTitle = payload.file_tag_title || null
this.tagTitleSort = payload.file_tag_titlesort || null
this.tagSeries = payload.file_tag_series || null
this.tagSeriesPart = payload.file_tag_seriespart || null
this.tagTrack = payload.file_tag_track || null
@ -147,6 +162,9 @@ class AudioMetaTags {
this.tagIsbn = payload.file_tag_isbn || null
this.tagLanguage = payload.file_tag_language || null
this.tagASIN = payload.file_tag_asin || null
this.tagItunesId = payload.file_tag_itunesid || null
this.tagPodcastType = payload.file_tag_podcasttype || null
this.tagEpisodeType = payload.file_tag_episodetype || null
this.tagOverdriveMediaMarker = payload.file_tag_overdrive_media_marker || null
this.tagOriginalYear = payload.file_tag_originalyear || null
this.tagReleaseCountry = payload.file_tag_releasecountry || null
@ -166,9 +184,12 @@ class AudioMetaTags {
updateData(payload) {
const dataMap = {
tagAlbum: payload.file_tag_album || null,
tagAlbumSort: payload.file_tag_albumsort || null,
tagArtist: payload.file_tag_artist || null,
tagArtistSort: payload.file_tag_artistsort || null,
tagGenre: payload.file_tag_genre || null,
tagTitle: payload.file_tag_title || null,
tagTitleSort: payload.file_tag_titlesort || null,
tagSeries: payload.file_tag_series || null,
tagSeriesPart: payload.file_tag_seriespart || null,
tagTrack: payload.file_tag_track || null,
@ -185,6 +206,9 @@ class AudioMetaTags {
tagIsbn: payload.file_tag_isbn || null,
tagLanguage: payload.file_tag_language || null,
tagASIN: payload.file_tag_asin || null,
tagItunesId: payload.file_tag_itunesid || null,
tagPodcastType: payload.file_tag_podcasttype || null,
tagEpisodeType: payload.file_tag_episodetype || null,
tagOverdriveMediaMarker: payload.file_tag_overdrive_media_marker || null,
tagOriginalYear: payload.file_tag_originalyear || null,
tagReleaseCountry: payload.file_tag_releasecountry || null,

View file

@ -136,5 +136,74 @@ class PodcastMetadata {
}
return hasUpdates
}
setDataFromAudioMetaTags(audioFileMetaTags, overrideExistingDetails = false) {
const MetadataMapArray = [
{
tag: 'tagAlbum',
altTag: 'tagSeries',
key: 'title'
},
{
tag: 'tagArtist',
key: 'author'
},
{
tag: 'tagGenre',
key: 'genres'
},
{
tag: 'tagLanguage',
key: 'language'
},
{
tag: 'tagItunesId',
key: 'itunesId'
},
{
tag: 'tagPodcastType',
key: 'type',
}
]
const updatePayload = {}
MetadataMapArray.forEach((mapping) => {
let value = audioFileMetaTags[mapping.tag]
let tagToUse = mapping.tag
if (!value && mapping.altTag) {
value = audioFileMetaTags[mapping.altTag]
tagToUse = mapping.altTag
}
if (value && typeof value === 'string') {
value = value.trim() // Trim whitespace
if (mapping.key === 'genres' && (!this.genres.length || overrideExistingDetails)) {
updatePayload.genres = this.parseGenresTag(value)
Logger.debug(`[Podcast] Mapping metadata to key ${tagToUse} => ${mapping.key}: ${updatePayload.genres.join(', ')}`)
} else if (!this[mapping.key] || overrideExistingDetails) {
updatePayload[mapping.key] = value
Logger.debug(`[Podcast] Mapping metadata to key ${tagToUse} => ${mapping.key}: ${updatePayload[mapping.key]}`)
}
}
})
if (Object.keys(updatePayload).length) {
return this.update(updatePayload)
}
return false
}
parseGenresTag(genreTag) {
if (!genreTag || !genreTag.length) return []
const separators = ['/', '//', ';']
for (let i = 0; i < separators.length; i++) {
if (genreTag.includes(separators[i])) {
return genreTag.split(separators[i]).map(genre => genre.trim()).filter(g => !!g)
}
}
return [genreTag]
}
}
module.exports = PodcastMetadata