Skip to content

Instantly share code, notes, and snippets.

@unixpickle
Created July 10, 2012 23:26
Show Gist options
  • Save unixpickle/3086896 to your computer and use it in GitHub Desktop.
Save unixpickle/3086896 to your computer and use it in GitHub Desktop.
List all of the items in Plex (w/ view count)
#!/bin/bash
#
# Simply pass in your plex library database file and have some fun!
# NOTE: your DB file is probably called "com.plexapp.plugins.library.db"
#
if [ $# != 1 ]; then
echo "plexdblist - lists the media items in a plex DB file."
echo "Usage: plexdblist <database>"
exit 1
fi
database=$1
# read the metadata ID for each media item
sqlite3 -line "$database" "select metadata_item_id from media_items" | while read line
do
# parse the metadata ID
metaID=`echo $line | sed -n 's/^[\t ]*metadata_item_id = \(.*\)/\1/p'`
if [ "$metaID" != '' ]; then
# get the metadata GUID to associate with the item_settings table
guid=`sqlite3 -line "$database" "select guid from metadata_items where id=$metaID" | sed -n 's/^[\t ]*guid = \(.*\)/\1/p'`
title=`sqlite3 -line "$database" "select title from metadata_items where id=$metaID" | sed -n 's/^[\t ]*title = \(.*\)/\1/p'`
if [ "$guid" != '' ]; then
# get our fun view fields
viewCount=`sqlite3 -line "$database" "select view_count from metadata_item_settings where guid=\"$guid\"" | sed -n 's/^[\t ]*view_count = \(.*\)/\1/p'`
viewOffset=`sqlite3 -line "$database" "select view_offset from metadata_item_settings where guid=\"$guid\"" | sed -n 's/^[\t ]*view_offset = \(.*\)/\1/p'`
# display our fun view fields as best we can
if [ "$viewOffset" != '' ]; then
echo "$title - $viewCount views (view offset: $viewOffset)"
else
echo "$title - $viewCount views"
fi
else
echo "Failed to get GID for meta ID $metaID" >&2
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment