Skip to content

Commit cceda4a

Browse files
hjone72hjone72
authored andcommitted
Improved analyzer
Renamed plex-analyze.cli to plex-analyze.py. Usage of reanalyzeItem.sh.
1 parent c532058 commit cceda4a

File tree

3 files changed

+65
-23
lines changed

3 files changed

+65
-23
lines changed

plex/plex-analyze-cli.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
3+
# Plex analayze all files that are missing analyzation info
4+
# OS: Ubunti 16.04 ( in case of other OS's make sure to change paths )
5+
# Usage: python3 plex-analyze-cli.py
6+
7+
import subprocess
8+
import sqlite3
9+
10+
# Define some variables
11+
DBPath = '/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db' # This is the default path.
12+
concurrentCount = 100 # This is how many files will be analyzed in 1 command. Plex handles them one at a time but this reduces the number of calls to the scanner and speeds things up.
13+
analyzeScript = "/scripts/plex/reanalyzeItem.sh" # Path to your refreshMetadataItem script.
14+
15+
conn = sqlite3.connect(DBPath)
16+
17+
c = conn.cursor()
18+
c.execute('''Select media_items.metadata_item_id As id, metadata_items.title As title
19+
From media_items Inner Join metadata_items On media_items.metadata_item_id = metadata_items.id
20+
Where media_items.bitrate Is Null And Not metadata_items.metadata_type = "12"''')
21+
22+
items = c.fetchall()
23+
conn.close()
24+
25+
def analyzeThese(ids):
26+
ids = ids[:-1]
27+
print("Going to analyze the following ID's: {0}".format(ids))
28+
subprocess.check_call([analyzeScript, ids])
29+
30+
print("There are {0} files that need to be analyzed.".format(str(len(items))))
31+
32+
itemString = ''
33+
itemCount = len(items)
34+
count = 0
35+
for row in items:
36+
itemString = itemString + str(row[0]) + ',' # This adds the current item to the ongoing string.
37+
count = count + 1
38+
itemCount = itemCount - 1 # Keep an up to date number of remaining items.
39+
if itemCount >= concurrentCount:
40+
if count >= concurrentCount:
41+
# Analyze these files.
42+
analyzeThese(itemString)
43+
itemString = '' # Reset the itemString.
44+
else:
45+
if itemCount <= 0 and itemString != '':
46+
analyzeThese(itemString)
47+
itemString = '' # Reset the itemString.
48+
49+
print("Finished analyzing all items.")

plex/plex-analyze.cli

Lines changed: 0 additions & 23 deletions
This file was deleted.

plex/reanalyzeItem.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# Re-analyze an item or items.
4+
# Usage: bash reanalyzeItem.sh {itemID}
5+
# bash reanalyzeItem.sh {itemID,itemID}
6+
# bash reanalyzeItem.sh 12345
7+
# bash reanalyzeItem.sh 12345,67788,23425
8+
9+
echo "Input items are: ${1}"
10+
11+
PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR='/opt/plexmediaserver/Library/Application Support' LD_LIBRARY_PATH='/usr/lib/plexmediaserver' /usr/lib/plexmediaserver/Plex\ Media\ Scanner \
12+
--verbose \
13+
--analyze \
14+
--item ${1}
15+
16+
exit 0

0 commit comments

Comments
 (0)