Skip to content

Instantly share code, notes, and snippets.

@maikelthedev
Created February 25, 2019 04:24
Show Gist options
  • Save maikelthedev/96a1461e79c66d678f63c400fd3c108d to your computer and use it in GitHub Desktop.
Save maikelthedev/96a1461e79c66d678f63c400fd3c108d to your computer and use it in GitHub Desktop.
Like Discovery Weekly from Spotify but better and free of charge
#!/usr/bin/fish
function findsong
lynx --dump "https://tunebat.com/Search?q=$argv" | grep " 6. https" | cut -d" " -f5
end
function findrelated
set song (findsong $argv)
lynx --dump $song | grep Info | cut -d/ -f5
end
function getsongurl
lynx --dump "https://www.youtube.com/results?search_query=$argv" | grep watch | head -1 | cut -d" " -f4
end
# Ok so ignore everything before here
function playmore
rm -f /tmp/songs/*
rm -f -d /tmp/songs
mkdir /tmp/songs
set first true
mpc clear
for song in (findrelated $argv)
youtube-dl -f 140 (getsongurl $song) -o /tmp/songs/$song.m4a
# No need to wait for the others to download to start playing
mpc insert file:///tmp/songs/$song.m4a
if test $first = true
mpc play
set first false
end
end
end
# Will do this at some point, need to think whether it is necessary to get the
# mp4tags or not. Because technically we're deleting the files anyway.
# originally this was here due to the spurious characters from Youtube videos
# that broke Mopidy
# function rename_files
# for file in (ls *)
# set artist (echo $file | cut -d"-" -f1)
# set track (echo $file | cut -d"-" -f2 | sed 's/[()]//g')
# mp4tags $file -s $track -a $artist
# set num (math $num+1)
# mv $file (echo $num).m4a
# end
# end
#if you're not using this file as a function / alias of Fish shell in the folder
# .config/fish/functions then uncomment the line below.
#playmore $argv
@maikelthedev
Copy link
Author

I think out of laziness i'm letting it be so verbose it just clutters the screen. I'm going to reduce it's verbosity and isntead just show a progress bar. Well...only if I don't figure out before how to play straight from Youtube without having to download anything first.

@maikelthedev
Copy link
Author

maikelthedev commented Feb 25, 2019

There's one additional issue I need to think about (and if anyone reading this can help that would be greatly appreciated):

  • In which ways do I want to save playlist or vote for songs?
  • How do I query tunebat with more than 1 song at the same time? Should it be, for example 3 different queries and then just randomly shuffle the results?
  • I could always save the playlist from any Mopidy clients, that's the easy part. Is the idea of using already created playlists to find more songs that is a bit more complex.
  • Need to find out how Mopidy handles the playlist (saving them) and probably involve a shared folder of Syncthing for it and/or a vault in BItwarden.

@maikelthedev
Copy link
Author

Newflash:

  • You can save playlists and then load then with mpc load playlistname
    Notice that it is the name of the list, not of the file.
    Once loaded you have to play it so mpc play
  • If you can find a way to save a youtube song to a playlist then you'll get the correct format to open them without downloading them.

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