This commit is contained in:
deathbybandaid 2023-03-14 10:51:17 -04:00
parent e20984525c
commit b510ac790e
2 changed files with 49 additions and 10 deletions

View File

@ -11,10 +11,50 @@ if [[ -f "$PLEX_PREFERENCES_XML" ]]; then
echo "Plex Preferences.xml found: $PLEX_PREFERENCES_XML"
# get token
LOCAL_PLEX_TOKEN=`cat "${PLEX_PREFERENCES_XML}" | sed -e 's;^.* PlexOnlineToken=";;' | sed -e 's;".*$;;' | tail -1`
echo "Local Token found in $PLEX_PREFERENCES_XML: $LOCAL_PLEX_TOKEN"
echo "Local Token found: $LOCAL_PLEX_TOKEN"
else
echo "Plex Preferences.xml not found"
exit
fi
exit
if [ -z "$PLEX_LOGIN" ] || [ -z "$PLEX_PASSWORD" ]; then
PLEX_LOGIN=$1
PLEX_PASSWORD=$2
fi
while [ -z "$PLEX_LOGIN" ]; do
>&2 echo -n 'Your Plex login (e-mail or username): '
read PLEX_LOGIN
done
while [ -z "$PLEX_PASSWORD" ]; do
>&2 echo -n 'Your Plex password: '
read PLEX_PASSWORD
done
>&2 echo 'Retrieving a X-Plex-Token using Plex login/password...'
curl -qu "${PLEX_LOGIN}":"${PLEX_PASSWORD}" 'https://plex.tv/users/sign_in.xml' \
-X POST -H 'X-Plex-Device-Name: PlexMediaServer' \
-H 'X-Plex-Provides: server' \
-H 'X-Plex-Version: 0.9' \
-H 'X-Plex-Platform-Version: 0.9' \
-H 'X-Plex-Platform: xcid' \
-H 'X-Plex-Product: Plex Media Server'\
-H 'X-Plex-Device: Linux'\
-H 'X-Plex-Client-Identifier: XXXX' --compressed >/tmp/plex_sign_in
X_PLEX_TOKEN=$(sed -n 's/.*<authentication-token>\(.*\)<\/authentication-token>.*/\1/p' /tmp/plex_sign_in)
if [ -z "$X_PLEX_TOKEN" ]; then
cat /tmp/plex_sign_in
rm -f /tmp/plex_sign_in
>&2 echo 'Failed to retrieve the X-Plex-Token.'
exit 1
fi
rm -f /tmp/plex_sign_in
>&2 echo "Your X_PLEX_TOKEN:"
echo $X_PLEX_TOKEN

View File

@ -4,12 +4,11 @@ echo "Welcome to plex-tools wrapper utility!"
script_delegation ()
{
if [[ $# -gt 0 ]] ; then
echo "$1"
if [[ "$1" "token" ]]
then
source plex-token.sh
else
echo "'$1' is not a valid plex-tools command"
if [ -f "$1" ] ; then
case $1 in
token) source ./plex-token.sh ;;
esac
else
echo "'$1' '$1' is not a valid plex-tools command"
fi
}