Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions plex/plex-analyze-cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python3

# Plex analayze all files that are missing analyzation info
# OS: Ubunti 16.04 ( in case of other OS's make sure to change paths )
# Usage: python3 plex-analyze-cli.py

import subprocess
import sqlite3

# Define some variables
DBPath = '/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db' # This is the default path.
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.
analyzeScript = "/scripts/plex/reanalyzeItem.sh" # Path to your refreshMetadataItem script.

conn = sqlite3.connect(DBPath)

c = conn.cursor()
c.execute('''Select media_items.metadata_item_id As id, metadata_items.title As title
From media_items Inner Join metadata_items On media_items.metadata_item_id = metadata_items.id
Where media_items.bitrate Is Null And Not metadata_items.metadata_type = "12"''')

items = c.fetchall()
conn.close()

def analyzeThese(ids):
ids = ids[:-1]
print("Going to analyze the following ID's: {0}".format(ids))
subprocess.check_call([analyzeScript, ids])

print("There are {0} files that need to be analyzed.".format(str(len(items))))

itemString = ''
itemCount = len(items)
count = 0
for row in items:
itemString = itemString + str(row[0]) + ',' # This adds the current item to the ongoing string.
count = count + 1
itemCount = itemCount - 1 # Keep an up to date number of remaining items.
if itemCount >= concurrentCount:
if count >= concurrentCount:
# Analyze these files.
analyzeThese(itemString)
itemString = '' # Reset the itemString.
else:
if itemCount <= 0 and itemString != '':
analyzeThese(itemString)
itemString = '' # Reset the itemString.

print("Finished analyzing all items.")
23 changes: 0 additions & 23 deletions plex/plex-analyze.cli

This file was deleted.

16 changes: 16 additions & 0 deletions plex/reanalyzeItem.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Re-analyze an item or items.
# Usage: bash reanalyzeItem.sh {itemID}
# bash reanalyzeItem.sh {itemID,itemID}
# bash reanalyzeItem.sh 12345
# bash reanalyzeItem.sh 12345,67788,23425

echo "Input items are: ${1}"

PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR='/var/lib/plexmediaserver/Library/Application Support' LD_LIBRARY_PATH='/usr/lib/plexmediaserver' /usr/lib/plexmediaserver/Plex\ Media\ Scanner \
--verbose \
--analyze \
--item ${1}

exit 0