Skip to content

Instantly share code, notes, and snippets.

@amcolash
Last active August 7, 2023 14:50
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save amcolash/433421a9a729ef42461b48bd006c50af to your computer and use it in GitHub Desktop.
Save amcolash/433421a9a729ef42461b48bd006c50af to your computer and use it in GitHub Desktop.
UPDATE, see here: https://github.com/amcolash/flowkey-scraper - Noteflight auto transcribe
// Find the sheet music images on the page
const elements = document.getElementsByClassName('split-image');
// Check that there are actually images on the page
if (elements.length === 0) {
console.error('No images found');
} else {
// If images were found, extract the base url from the 1st one
const imageUrl = elements[0].src;
const imageIdMatch = /\/sheets\/([\w\d]+)\//;
const baseUrl = 'https://flowkeycdn.com/sheets/';
// Construct the final url to use
const matched = imageUrl.match(imageIdMatch)[1];
const url = `${baseUrl}${matched}/300/`;
// Log the url to the console
console.log(url);
// This last line may fail on some browsers, but you can always manually copy from the log statement above.
copy(url);
}
#!/bin/bash
# Note: To run on large pieces of music, you will need to edit /etc/ImageMagick-6/policy.xml
# to allow stiching a very large image together in ImageMagick. I had these extra lines in my file:
# <policy domain="resource" name="width" value="64KP"/>
# <policy domain="resource" name="height" value="64KP"/>
# Check that only one argument (the base url was passed)
if [ "$#" -ne 1 ]; then
echo "Usage: flowkey [base url]"
exit 1
fi
# Check that imagemagick is installed
if ! [ -x "$(command -v convert)" ]; then
echo 'Error: imagemagick is not installed.' >&2
exit 1
fi
# Check that audiveris is available (you will need to check out the repo and follow install instructions)
if ! [ -d ~/Downloads/audiveris ]; then
echo 'Error: audiveris not installed. Please clone the repository to ~/Downloads/audiveris'
exit 1
fi
# Move to /tmp
pushd /tmp
# Set up temp folder
rm -rf flowkey_tmp
mkdir flowkey_tmp
pushd flowkey_tmp
# Continually try to grab images with wget until this fails. At that point, we know we have the entire song.
i=0
while true; do
URL=$1$i.png
wget -nv $URL
if [ $? -ne 0 ]; then
break
fi
i=$((i+1))
done
# Stitch all images together and fill the background of the output with white
convert $(ls *.png | sort -V) +append stitched.png
convert stitched.png stitched.png -background white -layers merge output.png
popd
# Copy the result to the desktop
cp flowkey_tmp/output.png ~/Desktop/flowkey_music.png
# Run audiveris (maunally you will need to run the OMR)
pushd ~/Downloads/audiveris
./gradlew run
popd
# If you have chrome, open noteflight in a new tab to complete things
if ! [ -x "$(command -v google-chrome)" ]; then
google-chrome https://www.noteflight.com/home
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment