-
-
Save alexanderscott/9841566 to your computer and use it in GitHub Desktop.
This file contains 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
let g:spotify_track_search_url = "http://ws.spotify.com/search/1/track.json?q=" | |
function! OpenUri(uri) | |
exec "silent !explorer " . a:uri | |
endfunction | |
function! OpenLine() | |
let uri = b:uris[line(".")-2] | |
call OpenUri(uri) | |
endfunction | |
function! CurlIntoBuffer(url) | |
exec 'silent r!curl -s "' . a:url . '"' | |
endfunction | |
function! SearchSpot(track) | |
call CurlIntoBuffer(g:spotify_track_search_url . a:track) | |
endfunction | |
function! SearchTrack(track) | |
let cleantrack = substitute(a:track, " ", "\\\\%20", "g") | |
topleft new | |
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap | |
echo "Downloading Search now" | |
call SearchSpot(cleantrack) | |
silent 1d | |
call TrackParse() | |
nnoremap <buffer> <CR> :call OpenLine()<CR> | |
nnoremap <buffer> <2-LeftMouse> :call OpenLine()<CR> | |
setlocal nomodifiable | |
2 | |
endfunction | |
function! TrackParse() | |
silent s/{"album"/\r&/g | |
silent 1d | |
call append(0, "Track Artist Release Year Album") | |
silent! %s/\\"//g | |
silent! %s/\v.*\{"released": "(\d{4})", "href": "[^"]+", "name": "([^"]+)", "availability": \{"territories": "[^"]+"\}}, "name": "([^"]+)", .*"popularity": .*"(spotify:track:[^"]+)", "artists": .*name": "([^"]+)"}].*/\3 \5 \1 \2\4 | |
let b:uris = [] | |
let i = 2 | |
let last = line("$") | |
while i < last | |
call add(b:uris, getline(i)[-36:]) | |
let i = i + 1 | |
endwhile | |
silent! 1,$s/.\{36}$// | |
silent! %Tabularize / | |
silent! %s;\\;;g | |
endfunction | |
command! -nargs=* SpotifySearchTrack call SearchTrack("<args>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment