Skip to content

Instantly share code, notes, and snippets.

@metriics
Last active November 24, 2024 19:36
Show Gist options
  • Select an option

  • Save metriics/c85e9fa6a852e9c1dd280da68b79ceec to your computer and use it in GitHub Desktop.

Select an option

Save metriics/c85e9fa6a852e9c1dd280da68b79ceec to your computer and use it in GitHub Desktop.
Bash script to refresh a Plex library, or specific path in a library. I use this in conjuction with qBittorrent to refresh a specific file or folder in my library so that Plex doesn't try to grab metadata for a half downloaded item. This happens if there are multiple items downloading to the same library.
#!/usr/bin/env bash
domain=
token=
library=$1
refPath=$2
libIndex=-1
echoerr() { echo "$@" 1>&2; }
# Match qBittorrent Category name to Plex library index
# (find by doing 'Get Info > View XML' on an item in each library
case "$library" in
"Anime")
libIndex=3;;
"Movies")
libIndex=1;;
"TV Shows")
libIndex=2;;
esac
# Validate that a library was specified, exit if not
if [ $libIndex -eq -1 ]; then
echoerr "Invalid library name"
exit 1
fi
# Check if a path was specified for a targeted refresh
if [ $refPath ]; then
echo "Refreshing $refPath"
curl --globoff "http://$domain:32400/library/sections/$libIndex/refresh?path=$refPath&X-Plex-Token=$token"
else
echo "Refreshing $library @ library section $libIndex"
curl --globoff "http://$domain:32400/library/sections/$libIndex/refresh?X-Plex-Token=$token"
fi
@metriics
Copy link
Author

usage:

plex_refresh.sh "<library name>" "[path]"

path is optional, if not supplied the entire library will be refreshed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment