# Finding media duration in Plex database

**URL:** <https://forums.plex.tv/t/finding-media-duration-in-plex-database/934413>\
**Category:** Dev/API Corner\
**Tags:** other-dev, metadata\
**Created:** [December 10, 2025, 1:39pm UTC](https://forums.plex.tv/t/finding-media-duration-in-plex-database/934413 "2025-12-10T13:39:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MatthewRoche](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/matthewroche/32/9333_2.png) [@MatthewRoche](https://forums.plex.tv/u/MatthewRoche)\
**Post date:** [December 10, 2025, 1:39pm UTC](https://forums.plex.tv/t/finding-media-duration-in-plex-database/934413/1 "2025-12-10T13:39:12Z")

</div>

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…

 ![2025-12-10_08-41-41](https://global.discourse-cdn.com/plex/original/4X/3/4/4/344200a044dde1375088f12c1fec091d4e84c7da.jpeg)

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [December 10, 2025, 2:58pm UTC](https://forums.plex.tv/t/finding-media-duration-in-plex-database/934413/2 "2025-12-10T14:58:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MatthewRoche](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/matthewroche/32/9333_2.png) [@MatthewRoche](https://forums.plex.tv/u/MatthewRoche)\
**Post date:** [December 10, 2025, 3:50pm UTC](https://forums.plex.tv/t/finding-media-duration-in-plex-database/934413/3 "2025-12-10T15:50:13Z")

</div>

> [@dane22](#):
>
> 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

Thanks so much - this does what I need!
