Created
December 28, 2024 05:07
-
-
Save parzival-space/258324d27d038710c3e84cbdad3f99dc to your computer and use it in GitHub Desktop.
Spotify Downloader Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to print the help message | |
print_help() { | |
echo "Usage: $0 <spotify_url> [-o output_file_path]" | |
echo "Example: $0 https://open.spotify.com/track/0NVAflSkJrc5wUPcCRHuJ6 -o output.txt" | |
echo "The script will auto-detect if the URL is a song or a playlist." | |
} | |
# Check if help is requested | |
if [[ "$1" == "-h" || "$1" == "--help" ]]; then | |
print_help | |
exit 0 | |
fi | |
# Variables to hold the URL and output file path | |
spotify_url="" | |
output_file="" | |
# Parse the arguments | |
while [[ $# -gt 0 ]]; do | |
case "$1" in | |
-o) | |
output_file="$2" | |
shift 2 | |
;; | |
*) | |
spotify_url="$1" | |
shift | |
;; | |
esac | |
done | |
# Ensure a Spotify URL is provided | |
if [[ -z "$spotify_url" ]]; then | |
echo "Error: Spotify URL is required." | |
print_help | |
exit 1 | |
fi | |
# Extract the ID and determine if it's a track or playlist | |
possible_song_id=$(echo $spotify_url | grep -oP '(?<=/track/)[^?]+') | |
possible_playlist_id=$(echo $spotify_url | grep -oP '(?<=/playlist/)[^?]+') | |
if [[ "$possible_song_id" != "" ]]; then | |
type="track" | |
id="$possible_song_id" | |
elif [[ "$possible_playlist_id" != "" ]]; then | |
type="playlist" | |
id="$possible_playlist_id" | |
else | |
echo "Error: Invalid Spotify URL format: $spotify_url" | |
exit 1 | |
fi | |
# Construct the request URL | |
request_url="https://yank.g3v.co.uk/${type}/${id}" | |
# Use curl to send the request | |
if [[ -z "$output_file" ]]; then | |
#curl "$request_url" | |
echo "please provice -o option" | |
else | |
curl "$request_url" -o "$output_file" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script is just a simple wget wrapper for Yank by G3VV to make it easier to download Spotify songs via their API.