# Plex DB where is the flag for --analyze-deeply

**URL:** <https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628>\
**Category:** General Discussions\
**Created:** [January 20, 2017, 2:08pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628 "2017-01-20T14:08:42Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ajki](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ajki/32/21258_2.png) [@Ajki](https://forums.plex.tv/u/Ajki)\
**Post date:** [January 20, 2017, 2:08pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/1 "2017-01-20T14:08:42Z")

</div>

Anyone knows where in plex database is stored info if file had --analyze-deeply preformed on it.

I was pretty sure it would be in media\_items field media\_analysis\_version but they are all set to 5 even after i manually triggered deep analyzation with cli on completely new movie.

The flag should be somewhere as I assume Plex does not try to preform in Scheduled tasks deep analyzation on all media you have in library.

---

<div class="post-metadata">

**Author:** ![gbooker02](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/gbooker02/32/9726_2.png) [@gbooker02](https://forums.plex.tv/u/gbooker02)\
**Post date:** [January 20, 2017, 3:36pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/2 "2017-01-20T15:36:34Z")

</div>

If you get info on an item, and view the XML you will the the XML for this item. Then in the URL, if you add `&includeBandwidths=1` it’ll included the deep analysis info. At the part level, you should see `deepAnalysisVersion="2"` if it has run.

---

<div class="post-metadata">

**Author:** ![Ajki](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ajki/32/21258_2.png) [@Ajki](https://forums.plex.tv/u/Ajki)\
**Post date:** [January 20, 2017, 5:53pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/3 "2017-01-20T17:53:41Z")

</div>

Thanks for answer gbooker02 but do you know where deepAnalysisVersion=“2” is stored in  
/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/ **com.plexapp.plugins.library.db**

---

<div class="post-metadata">

**Author:** ![gbooker02](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/gbooker02/32/9726_2.png) [@gbooker02](https://forums.plex.tv/u/gbooker02)\
**Post date:** [January 20, 2017, 6:49pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/4 "2017-01-20T18:49:52Z")

</div>

I presume you are asking for something like this:

```auto
sqlite> select count(*) from media_parts where extra_data like '%deepAnalysisVersion=2%';
905

```

---

<div class="post-metadata">

**Author:** ![Ajki](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ajki/32/21258_2.png) [@Ajki](https://forums.plex.tv/u/Ajki)\
**Post date:** [January 20, 2017, 6:50pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/5 "2017-01-20T18:50:50Z")

</div>

Great thats it

---

<div class="post-metadata">

**Author:** ![Ajki](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ajki/32/21258_2.png) [@Ajki](https://forums.plex.tv/u/Ajki)\
**Post date:** [January 28, 2017, 5:14pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/6 "2017-01-28T17:14:36Z")

</div>

@gbooker02  
How could I get (with sql) **metadata\_item\_id** for files that do not have deepAnalysisVersion=2.

What is the coloration between media\_items and media\_parts .( on what field to join )  
 ![](http://puu.sh/tE61Q/74ad68b27d.png)

---

<div class="post-metadata">

**Author:** ![Ajki](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ajki/32/21258_2.png) [@Ajki](https://forums.plex.tv/u/Ajki)\
**Post date:** [January 28, 2017, 5:54pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/7 "2017-01-28T17:54:37Z")

</div>

I made a simple script to run cli scanner on all files that dont have analyzation info.

> #!/usr/bin/env python3  
> from subprocess import call  
> import os  
> import requests  
> import sqlite3  
> import sys
> 
> ```
> conn = sqlite3.connect('/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db')
> 
> c = conn.cursor()
> c.execute('select metadata_item_id from media_items where bitrate is null')
> items = c.fetchall()
> conn.close()
> 
> print("To analyze: " + str( len(items) ))
> 
> for row in items:
> os.system('LD_LIBRARY_PATH=/usr/lib/plexmediaserver PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/var/lib/plexmediaserver/Library/Application\ Support /usr/lib/plexmediaserver/Plex\ Media\ Scanner -a -o ' + str(row[0]))
> os.system('sleep 1')
> print(str(row[0]))
> 
> ```

Now i would like to make another one that would do deep analyzation on all files that are missing it eg `Plex\ Media\ Scanner --analyze-deeply -o + str(row[0]`, however since media\_parts are individal file Iam not sure how to get metadata\_item\_id that i would send to scanner.

---

<div class="post-metadata">

**Author:** ![gbooker02](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/gbooker02/32/9726_2.png) [@gbooker02](https://forums.plex.tv/u/gbooker02)\
**Post date:** [January 30, 2017, 2:42pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/8 "2017-01-30T14:42:34Z")

</div>

@Ajki Note: the `bitrate` attribute is not associated with the deep analysis; it comes from the normal (shallow) analysis. You’ll have to look for the `deepAnalysisVersion=2` in the `extra_data`.

As per joins, in `media_parts` the column `media_item_id` is the `id` in `media_items`. In `media_items`, the `metadata_item_id` is the `id` in `metadata_items`. Also, deep analysis is only performed on video types, not music nor pictures. The `metadata_type` values for those deeply analyzed are 1, 4, and 12.

---

<div class="post-metadata">

**Author:** ![Ajki](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ajki/32/21258_2.png) [@Ajki](https://forums.plex.tv/u/Ajki)\
**Post date:** [January 30, 2017, 3:59pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/9 "2017-01-30T15:59:58Z")

</div>

@gbooker02 hmm thats a bit weird since both ID fields are auto increment or i misunderstood something.  
Still not sure on what to join to make it work in query bellow.

```
select media_item_id from media_items
join media_parts on ??
join metadata_items on ??
where 
media_parts.extra_data not like '%deepAnalysisVersion=2%' 
and metadata_items.metadata_type="1" 
or metadata_items.metadata_type="4" 
or metadata_items.metadata_type="12";
```

---

<div class="post-metadata">

**Author:** ![gbooker02](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/gbooker02/32/9726_2.png) [@gbooker02](https://forums.plex.tv/u/gbooker02)\
**Post date:** [January 30, 2017, 4:15pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/10 "2017-01-30T16:15:40Z")

</div>

Perhaps this is better. BTW, I like to explicitly name the tables in the joins:

```auto
select meta.id from metadata_items meta
  join media_items media on media.metadata_item_id = meta.id
  join media_parts part on part.media_item_id = media.id
where part.extra_data not like '%deepAnalysisVersion=2%'
  and meta.metadata_type in (1, 4, 12)
  and part.file != "";

```

The last, `part.file != ""` is there because some metadata items reference remote files such as trailers and other extras. I select the metadata item id since that is the ID you give to the deep analysis.

---

<div class="post-metadata">

**Author:** ![Ajki](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ajki/32/21258_2.png) [@Ajki](https://forums.plex.tv/u/Ajki)\
**Post date:** [January 30, 2017, 5:38pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/11 "2017-01-30T17:38:46Z")

</div>

@gbooker02 So i can run `/Plex Media Scanner --analyze-deeply -o XXX` on those meta.id results.

---

<div class="post-metadata">

**Author:** ![gbooker02](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/gbooker02/32/9726_2.png) [@gbooker02](https://forums.plex.tv/u/gbooker02)\
**Post date:** [January 30, 2017, 5:45pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/12 "2017-01-30T17:45:04Z")

</div>

You’ll need the `LD_LIBRARY_PATH` and `PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR` set, but yeah.

---

<div class="post-metadata">

**Author:** ![Ajki](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ajki/32/21258_2.png) [@Ajki](https://forums.plex.tv/u/Ajki)\
**Post date:** [January 30, 2017, 5:56pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/13 "2017-01-30T17:56:20Z")

</div>

Thanks again 🙂

---

<div class="post-metadata">

**Author:** ![cayars](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/cayars/32/6296_2.png) [@cayars](https://forums.plex.tv/u/cayars)\
**Post date:** [April 28, 2017, 9:38pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/14 "2017-04-28T21:38:16Z")

</div>

> @Ajki said:  
> I made a simple script to run cli scanner on all files that dont have analyzation info.
> 
> > #!/usr/bin/env python3  
> > from subprocess import call  
> > import os  
> > import requests  
> > import sqlite3  
> > import sys
> > 
> > ```
> > conn = sqlite3.connect('/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db')
> > 
> > c = conn.cursor()
> > c.execute('select metadata_item_id from media_items where bitrate is null')
> > items = c.fetchall()
> > conn.close()
> > 
> > print("To analyze: " + str( len(items) ))
> > 
> > for row in items:
> > os.system('LD_LIBRARY_PATH=/usr/lib/plexmediaserver PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/var/lib/plexmediaserver/Library/Application\ Support /usr/lib/plexmediaserver/Plex\ Media\ Scanner -a -o ' + str(row[0]))
> > os.system('sleep 1')
> > print(str(row[0]))
> > 
> > ```
> 
> Now i would like to make another one that would do deep analyzation on all files that are missing it eg `Plex\ Media\ Scanner --analyze-deeply -o + str(row[0]`, however since media\_parts are individal file Iam not sure how to get metadata\_item\_id that i would send to scanner.

I’d try and avoid holding the database open longer then needed or using cursors. Here’s a simple way to do stuff like this on windows.

Create a batch file and put this inside the file: (DeepAnalysis.bat)  
c::  
cd \sqlite  
sqlite3 \< DeepAnalysis.txt  
DeepAnalysisRunning.bat

Create a text file name DeepAnalysis.txt with this contents:  
.open ‘C:\PlexData\Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db’  
.output DeepAnalysisRunning.bat  
SELECT '“C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Scanner.exe” --analyze-deeply --item ’ || meta.id  
from metadata\_items meta  
join media\_items media on media.metadata\_item\_id = meta.id  
join media\_parts part on part.media\_item\_id = media.id  
where part.extra\_data not like ‘%deepAnalysisVersion=2%’  
and meta.metadata\_type in (1, 4, 12)  
and part.file != “”;

It assumes sqlite3 is in the same directory as the batch file. If not adjust with paths.  
This batch file starts sqlite3 with instructions to open the text file.  
The text file opens the database and sets an output file (named as a batch file) and outputs the scanner lines needed to run sequentially one after another.  
The batch file then executes the 2nd batch file it just created.

This way you only have the database open for a very short period of time and can generate thousands of commands to run. Play with it and you’ll see how it works.

Carlo

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [January 7, 2020, 10:37pm UTC](https://forums.plex.tv/t/plex-db-where-is-the-flag-for-analyze-deeply/176628/15 "2020-01-07T22:37:12Z")

</div>


