-
-
Save autumn-mck/6d7fcbbc08f5d18be09f2cc219084675 to your computer and use it in GitHub Desktop.
| #!/usr/bin/env sh | |
| # SPDX-License-Identifier: Beerware | |
| # Script to automate downloading and installing the latest version of MusicBee | |
| # If anything goes wrong/breaks, let me know so I can fix it! | |
| set -eu | |
| export WINEPREFIX="${XDG_DATA_HOME:-$HOME/.local/share}/wineprefixes/MusicBee" | |
| installation_location="$WINEPREFIX/drive_c/Program Files (x86)/MusicBee/" | |
| # the official download mirror links from MajorGeeks | |
| mb_url_1="https://www.majorgeeks.com/mg/getmirror/musicbee,1.html" | |
| mb_url_2="https://www.majorgeeks.com/index.php?ct=files&action=download&=" | |
| # for AAC (.m4a) support | |
| # https://getmusicbee.com/forum/index.php?topic=23454.0 | |
| bass_aac_download_url="https://www.un4seen.com/files/z/2/bass_aac24.zip" | |
| # for MPRIS support (only if --mpris is given, also currently requires wine-staging) | |
| mprisbee_plugin_url="https://github.com/UrbanCMC/mb_MPRISBee/releases/download/1.0.1/mb_MPRISBee.zip" | |
| export WINEDLLOVERRIDES="mscoree,mshtml=" # we don't need wine-mono installed, no need to give a warning over it. https://bugs.winehq.org/show_bug.cgi?id=47316#c4 | |
| export WINEDEBUG="-all" # don't print any debugging messages for wine | |
| app_dir="${XDG_DATA_HOME:-$HOME/.local/share}/applications" | |
| icon_dir="${XDG_DATA_HOME:-$HOME/.local/share}/icons/hicolor/256x256/apps" | |
| # check requirements | |
| require() { | |
| command -v "$1" >/dev/null 2>&1 || { | |
| printf "\n\nError: %s is not installed.\n" "$1" >&2 | |
| printf "\nPlease install it from your distro's repositories and try again." >&2 | |
| printf "\nNote: The package may be named differently than the command.\n" >&2 | |
| exit 1 | |
| } | |
| } | |
| for cmd in wine winetricks curl unzip xdg-icon-resource desktop-file-install; do | |
| require "$cmd" | |
| done | |
| # parse arguments | |
| mpris=false | |
| for arg in "$@"; do | |
| case "$arg" in | |
| --mpris) | |
| mpris=true | |
| ;; | |
| esac | |
| done | |
| cleanup() { | |
| rm -f "$mb_temp_file" "$cookie_temp_file" 2>/dev/null || true | |
| rm -f "$installation_location"/bass_aac.zip "$installation_location"/Plugins/mb_MPRISBee.zip 2>/dev/null || true | |
| } | |
| trap cleanup EXIT HUP INT TERM | |
| mb_temp_file=$(mktemp --tmpdir MusicBee-XXXXXX.exe) | |
| cookie_temp_file=$(mktemp --tmpdir MG_MB_cookie_XXXXXX.txt) | |
| printf "\nSetting up wine prefix (this will take a while)" | |
| printf "Warnings about using a 64-bit prefix and using wow64 mode are expected and can be safely ignored.\n" | |
| # unset display to prevent it displaying the "The wine configuration in ... is being updated, please wait" message | |
| DISPLAY="" WAYLAND_DISPLAY="" winetricks --unattended dotnet48 xmllite gdiplus cjkfonts wmp11 | |
| winetricks --unattended windowmanagerdecorated=n | |
| printf "\nDownloading and extracting MusicBee installer\n" | |
| curl -fsSc "$cookie_temp_file" "$mb_url_1" >/dev/null # initial request to get the cookie, as if we were downloading through a browser | |
| curl -fsSL -b "$cookie_temp_file" "$mb_url_2" | funzip > "$mb_temp_file" # download the zip file containing the installer, pipe it through funzip to unzip it, and write it to the temp file | |
| printf "\nInstalling MusicBee\n" | |
| # I've not dug into what the installer is packaged by, but it supports /S for a silent install | |
| wine "$mb_temp_file" "/S" | |
| cd "$installation_location" | |
| printf "\nDownloading bass_aac to allow playing of AAC/M4A files\n" | |
| curl -fsSL -o "./bass_aac.zip" "$bass_aac_download_url" | |
| unzip -o bass_aac.zip bass_aac.dll | |
| # install mprisbee | |
| if [ "$mpris" = true ]; then | |
| printf "\nInstalling mprisbee plugin\n" | |
| ( | |
| cd "./Plugins" | |
| curl -fsSL -o "./mb_MPRISBee.zip" "$mprisbee_plugin_url" | |
| unzip -o mb_MPRISBee.zip | |
| ) | |
| fi | |
| # find the MusicBee icon and install it as an XDG icon (wine doesn't name icons consistently) | |
| icon_path=$(find "$icon_dir" -type f -iname '*musicbee*.png' -print -quit) | |
| xdg-icon-resource install "$icon_path" musicbee --context apps --size 256 --novendor | |
| # launch script to reformat the given file path when trying to play a specific file from the file manager or wherever | |
| cat > "./launch.sh" << EOL | |
| #!/usr/bin/env sh | |
| export WINEPREFIX="$WINEPREFIX" | |
| installation_location="$installation_location" | |
| file=\$(printf "\$1" | tr "/" "\\\\") # Replace / with \\ | |
| if [ "\$file" ]; then | |
| wine "$installation_location/MusicBee.exe" "/Play" "Z:\$file" | |
| else | |
| wine "$installation_location/MusicBee.exe" | |
| fi | |
| EOL | |
| chmod +x ./launch.sh | |
| printf "\nInstalling XDG Desktop entry\n" | |
| # a better XDG Desktop entry than the one generated by wine | |
| # lists some supported mime types, and correctly categorises musicbee | |
| cat > "./MusicBee.desktop" << EOL | |
| [Desktop Entry] | |
| Type=Application | |
| Version=1.5 | |
| Name=MusicBee | |
| Comment=The Ultimate Music Manager and Player | |
| Icon=musicbee | |
| Exec="$installation_location/launch.sh" "%f" | |
| MimeType=audio/mp4;audio/mpeg;audio/aac;audio/flac;audio/ogg; | |
| Categories=AudioVideo;Audio;Player;Music; | |
| StartupNotify=true | |
| StartupWMClass=musicbee.exe | |
| SingleMainWindow=true | |
| EOL | |
| desktop-file-install --dir="$app_dir" --rebuild-mime-info-cache "./MusicBee.desktop" | |
| # remove the XDG Desktop entry generated by wine (ours is better) | |
| rm -rf "$app_dir/wine/Programs/MusicBee/" | |
| printf "\nInstallation complete!\n" | |
| printf "\nNote: If using HiDPI a display (i.e. you have scaling set to > 100%%), you have to set the DPI." | |
| printf "\nThis can be done through the winecfg gui (run 'WINEPREFIX=\"%s\" winecfg'), under the 'Graphics' tab, or by running one of the below:\n" "$WINEPREFIX" | |
| printf "\n125%% scaling: WINEPREFIX=\"%s\" wine reg add \"HKCU\\Control Panel\\Desktop\" /v LogPixels /t REG_DWORD /d 0x00000078 /f\n" "$WINEPREFIX" | |
| printf "\n150%% scaling: WINEPREFIX=\"%s\" wine reg add \"HKCU\\Control Panel\\Desktop\" /v LogPixels /t REG_DWORD /d 0x00000090 /f\n" "$WINEPREFIX" | |
| printf "\n175%% scaling: WINEPREFIX=\"%s\" wine reg add \"HKCU\\Control Panel\\Desktop\" /v LogPixels /t REG_DWORD /d 0x000000A8 /f\n" "$WINEPREFIX" | |
| printf "\n200%% scaling: WINEPREFIX=\"%s\" wine reg add \"HKCU\\Control Panel\\Desktop\" /v LogPixels /t REG_DWORD /d 0x000000C0 /f\n" "$WINEPREFIX" |
Just saw your blog post! Good stuff. I've been on and off with Linux for a while and part of that was because of MusicBee (used to manage the WINEHQ page lol)
Just some things you might wanna know for the blog post:
- CJK font redirection is better now, even works when changing font (I'm using Noto Sans to make it consistent with KDE). Some symbols are still broken but it's very esoteric stuff at this point. Still reported it to WINE tho.
- Music Presence has a Linux version that works great with MPRISBee if you want Discord rich presence.
EDIT: I'd advise against using --mpris if you're on 11.5 or later since WINE changed a bunch of stuff relating to system calls
@FlakyBlueJay thanks!
i'd seen music presence before (and used something similar myself) but decided not to include it in this script since i'm not too fond of discord, but I'm still thinking about adding more flags for it or any other plugins
i've also updated the script to use an updated fork of the plugin for MPRIS, although it does require wine-staging for now
i do still need to update the blog post to mention a couple other things like that, but that'll take me a while to actually get around to
just wanted to say yay >w< fluffies did a help. fang you fur writing this script bytheway!