Skip to content

Instantly share code, notes, and snippets.

@jetfir3
Last active April 27, 2024 11:17
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jetfir3/d66f491d0683e2bdbdf9f60068e9984b to your computer and use it in GitHub Desktop.
Save jetfir3/d66f491d0683e2bdbdf9f60068e9984b to your computer and use it in GitHub Desktop.
Temporarily enable developer mode for the Spotify desktop client on Linux and macOS.
#!/usr/bin/env bash
# Temporarily enable developer mode for the Spotify desktop client on Linux and macOS.
showHelp () {
echo -e \
"Usage: ./tmpdevmodify.sh [option]\n
Options:
-c, --clearcache Clear Spotify app cache
-d, --debug Add Debug Tools to user dropdown menu
--help Print this help message"
}
clear="\033[0m"
red="\033[0;31m"
while getopts ':cd-:' flag; do
case "${flag}" in
-)
case "${OPTARG}" in
clearcache) clearCache='true' ;;
debug) debug='true' ;;
help) showHelp; exit 0 ;;
*) echo -e "${red}Error:${clear} '--""${OPTARG}""' not supported\n\n$(showHelp)\n" >&2; exit 1 ;;
esac ;;
c) clearCache='true' ;;
d) debug='true' ;;
\?) echo -e "${red}Error:${clear} '-""${OPTARG}""' not supported\n\n$(showHelp)\n" >&2; exit 1 ;;
esac
done
command -v perl >/dev/null || { echo -e "\n${red}Error:${clear} perl command not found.\nInstall perl on your system then try again.\n" >&2; exit 1; }
searchCacheLinux () {
local timeout=7
local paths=("$HOME/.cache" "$HOME" "/")
for path in "${paths[@]}"; do
local path="${path}"
local timeLimit=$(($(date +%s) + timeout))
while (( $(date +%s) < "${timeLimit}" )); do
cachePath=$(find "${path}" -type d -path "*cache/spotify*" -print -quit 2>/dev/null)
[[ -n "${cachePath}" ]] && return 0
pgrep -x find > /dev/null || break
sleep 1
done
done
return 1
}
searchPrefsLinux () {
local timeout=7
local paths=("$HOME/.config" "$HOME" "/")
for path in "${paths[@]}"; do
local path="${path}"
local timeLimit=$(($(date +%s) + timeout))
while (( $(date +%s) < "${timeLimit}" )); do
prefsPath=$(find "${path}" -type f -path "*/spotify/prefs" -print -quit 2>/dev/null)
[[ -n "${prefsPath}" ]] && return 0
pgrep -x find > /dev/null || break
sleep 1
done
done
return 1
}
case $(uname | tr '[:upper:]' '[:lower:]') in
darwin*) platformType='macOS' ;;
*) platformType='Linux' ;;
esac
if [[ "${platformType}" == "macOS" ]]; then
cachePath="${HOME}/Library/Caches/com.spotify.client"
offlineBnk="${HOME}/Library/Application Support/Spotify/PersistentCache/offline.bnk"
prefsPath="${HOME}/Library/Application Support/Spotify/prefs"
else
searchCacheLinux
offlineBnk="${cachePath}/offline.bnk"
fi
command pgrep [sS]potify 2>/dev/null | xargs kill -9 2>/dev/null
[[ "${clearCache}" ]] && { rm -rf "${cachePath}/Browser" 2>/dev/null; rm -rf "${cachePath}/Data" 2>/dev/null; rm "${cachePath}/LocalPrefs.json" 2>/dev/null; }
if [[ "${debug}" ]]; then
[[ "${platformType}" == "Linux" ]] && searchPrefsLinux
[[ ! -f "${prefsPath}" ]] && { echo -e "${red}prefs not found!${clear} Run Spotify once then try again.\n" >&2; exit 1; }
[[ ! -f "${offlineBnk}" ]] && { echo -e "${red}offline.bnk not found!${clear} Run Spotify once then try again.\n" >&2; exit 1; }
echo "app.enable-developer-mode=true" >> "${prefsPath}"
perl -pi -w -e 's|\x01\x2A\x63\x6F\x6D\x2E\x73\x70\x6F\x74\x69\x66\x79\x2E\x6D\x61\x64\x70\x72\x6F\x70\x73\x2E\x75\x73\x65\x2E\x75\x63\x73\x2E\x70\x72\x6F\x64\x75\x63\x74\x2E\x73\x74\x61\x74\x65\x09\x01[\x30\x31]\x78||' "${offlineBnk}"
perl -pi -w -e 's|\x01\x0D\x61\x70\x70\x2D\x64\x65\x76\x65\x6C\x6F\x70\x65\x72\x09\x01[\x30\x31\x32\x33]\x78|\x01\x08\x65\x6D\x70\x6C\x6F\x79\x65\x65\x09\x01\x31\x78\x01\x2A\x63\x6F\x6D\x2E\x73\x70\x6F\x74\x69\x66\x79\x2E\x6D\x61\x64\x70\x72\x6F\x70\x73\x2E\x75\x73\x65\x2E\x75\x63\x73\x2E\x70\x72\x6F\x64\x75\x63\x74\x2E\x73\x74\x61\x74\x65\x09\x01\x31\x78|' "${offlineBnk}"
else
[[ ! -f "${offlineBnk}" ]] && { echo -e "${red}offline.bnk not found!${clear} Run Spotify once then try again.\n" >&2; exit 1; }
perl -pi -w -e 's#\x70\x65\x72\x3E\K[\x30\x31]|\x70\x65\x72\x09\x01\K[\x30\x31]#\x33#g' "${offlineBnk}"
fi
echo -e "Finished! Spotify developer options will be enabled on next run.\n"
exit 0
@jetfir3
Copy link
Author

jetfir3 commented Jul 7, 2023

  • Run script to patch offline.bnk then open desktop client, "Develop" option will be available in toolbar.
  • Patch will be overwritten after Spotify sends the remote config, requiring running script again to re-enable.
  • Use -c / --clearcache to wipe app cache, reverting any changes made in dev mode.
  • Use -d / --debug to add Debug Tools menu item under the user icon dropdown.

Run directly with:

bash <(curl -sSL https://gist.github.com/jetfir3/d66f491d0683e2bdbdf9f60068e9984b/raw/tmpdevmodify.sh)

More devmode-related scripts on github...

@chrismessina
Copy link

Awesome!

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