Parse multiple links directly from Spotify
Details
Parse multiple links in the search bar.
This would allow you to directly select and then copy/drag songs/links from the Spotify client into the search bar, and have the selected links added directly to the download queue (instead of having to make a temporary playlist with the selected songs)
Currently works (single link):
https://open.spotify.com/track/5e9TFTbltYBg2xThimr0rU?si=CfnABhn0Ss2mi-sTLH4F0A
This link is then sent to the download queue
Currently does not work (multiple links):
https://open.spotify.com/track/0ofHAoxe9vBkTCp2UQIavz?si=t6pDXfkuRlmg6j96ugQrwAhttps://open.spotify.com/track/5e9TFTbltYBg2xThimr0rU?si=lcAahTooT7CwVkn4Cjzm3whttps://open.spotify.com/track/5ihS6UUlyQAfmp48eSkxuQ?si=q4ghleFRTreFlza0Cb8bUw
Proposed code:
# Simple setup code for my example
import sys
command_line_args = sys.argv # Get command line arguments
command_line_args = command_line_args[1:] # Remove first argument referencing the python file ('link-split.py')
command_line_args = ''.join(command_line_args) # Merge the array into a string
links = command_line_args
# 'links' would be the value of the items in the search bar
links = links.replace('\n', '')
# Split links based off of 'https://'
if 'https://' in links: # If 'links' contains 'https://'
links = links.split('https://') # Split each link into an array (according to the 'https://')
# Add 'https' back to the links where it was removed due to the splitting
for i, link in enumerate(links): # For every link in the array created by the splitting
links[i] = 'https://'+link # Add 'https://' back to the beginning of each link (that was removed during splitting)
# The previous for loop may have left array values such as 'https://' (invalid link). Remove values which don't contain a '.'
for i, link in enumerate(links): # For every link in the array
if '.' not in links[i]: # If links[i] is not a proper link (does not contain a .)
del links[i] # Remove the value from the array
else:
links = [links] # Convert the link into an array ['https://link.com'] (for a single link for example)
print(links)
Example code output
Example input (command line args):
https://open.spotify.com/track/0ofHAoxe9vBkTCp2UQIavz?si=t6pDXfkuRlmg6j96ugQrwAhttps://open.spotify.com/track/5e9TFTbltYBg2xThimr0rU?si=lcAahTooT7CwVkn4Cjzm3whttps://open.spotify.com/track/5ihS6UUlyQAfmp48eSkxuQ?si=q4ghleFRTreFlza0Cb8bUw
Example output (print statement):
['https://open.spotify.com/track/0ofHAoxe9vBkTCp2UQIavz?si=t6pDXfkuRlmg6j96ugQrwA', 'https://open.spotify.com/track/5e9TFTbltYBg2xThimr0rU?si=lcAahTooT7CwVkn4Cjzm3w', 'https://open.spotify.com/track/5ihS6UUlyQAfmp48eSkxuQ?si=q4ghleFRTreFlza0Cb8bUw']
Implimentation
Instead of the print statement, you would use this psuedocode:
for link in links:
add_link_to_download_queue(link)