Skip to content

Instantly share code, notes, and snippets.

@johnmaguire
Last active November 2, 2020 01:40
Show Gist options
  • Save johnmaguire/ca83d79b681a25796685c272090d6761 to your computer and use it in GitHub Desktop.
Save johnmaguire/ca83d79b681a25796685c272090d6761 to your computer and use it in GitHub Desktop.

Plex Music Metadata

Fetching a list of songs from my old Plex library after a hard drive failure...

Descriptive Metadata (things to look for)

  • Title
  • Performing Artist
  • Album
  • Release Date
  • Track #
  • Covert Art
  • Genre

Plex songs (inspecting metadata_items)...

artists - (metadata_type=8, found via: parent_id is null)

title, title_sort, summary, tags_genre, tags_country

albums - (metadata_type=9, found via: parent_id is not null and media_item_count = 0)

parent_id (artist), title, title_sort, studio, summary, tags_genre

songs - (metadata_type=10, found via: parent_id is not null and media_item_count > 0)

parent_id (album), title, title_sort, index (track #), year

Query to fetch all songs, with full details

SELECT
  song.title AS song_title,
  song.title_sort AS song_title_sort,
  song.`index` AS song_track_no,
  song.year AS song_year,
  album.title AS album_title,
  album.title_sort AS album_title_sort,
  album.studio AS album_studio,
  album.summary AS album_summary,
  album.tags_genre AS album_genre,
  artist.title AS artist_title,
  artist.title_sort AS artist_title_sort,
  artist.summary AS artist_summary,
  artist.tags_genre AS artist_genre,
  artist.tags_country AS artist_country
FROM
  (select * from metadata_items where metadata_type=10) AS song
LEFT JOIN
  (select * from metadata_items where metadata_type=9) AS album
    ON song.parent_id = album.id
LEFT JOIN
  (select * from metadata_items where metadata_type=8) AS artist
    ON album.parent_id = artist.id

Album art should be possible too, but didn't look too closely into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment