Finding media duration in Plex database

I’m using the Plex Sqlite database to report on my music listening history, and I’m looking for ways to include the media duration in my reporting.

Today I’m getting listens from metadata_item_views, and track information from metadata_items. This works well.

I’ve found a duration column in plex_media_parts and plex_media_items but I haven’t found a common key column to join either one to the corresponding metadata_items records.

Can anyone point me in the right direction here?

I’ll keep exploring, but wanted to ask in case someone else had figured this out already. Thanks in advance!

Edit: adding an example of what I’ve been able to accomplish so far. I’m currently pulling track duration from MusicBrainz, but I’ve recently found many examples of missing durations in their metadata and I’m hoping for something simpler and more reliable…

Maybe something like:

select

md.title
, mi.duration
from metadata_items as md inner JOIN media_items as mi on mi.metadata_item_id = md.id Where md.library_section_id = 8 and md.metadata_type = 10 limit 100

In above, adjust library_section_id to match the one from your music library

2 Likes

Thanks so much - this does what I need!

1 Like