spotify-to-mp3 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +18 -0
- data/README.markdown +31 -0
- data/bin/spotify-to-mp3 +88 -0
- data/spotify-to-mp3.gemspec +15 -0
- metadata +72 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
colorize (0.5.8)
|
5
|
+
grooveshark (0.2.2)
|
6
|
+
json (>= 1.4.6)
|
7
|
+
rest-client (>= 1.5.1)
|
8
|
+
json (1.6.1)
|
9
|
+
mime-types (1.16)
|
10
|
+
rest-client (1.6.7)
|
11
|
+
mime-types (>= 1.16)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
colorize
|
18
|
+
grooveshark
|
data/README.markdown
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Spotify to MP3
|
2
|
+
|
3
|
+
A simple command line utility to download MP3 files of Spotify tracks
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install spotify-to-mp3
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
1. Drag Spotify songs to a file (eg, songs.txt). It will look like this:
|
12
|
+
|
13
|
+
http://open.spotify.com/track/1JqTcOjOn7gEpeC0JcRVPa
|
14
|
+
http://open.spotify.com/track/4pQIl2gJyRDKiwIhEOc1gW
|
15
|
+
http://open.spotify.com/track/2rREB1sRvcb5i6AZRhOhey
|
16
|
+
http://open.spotify.com/track/6UOvd5f3oyfIGW3GA8dn89
|
17
|
+
|
18
|
+
2. Download songs. Errors will appear in red (eg, when a song is not found)
|
19
|
+
|
20
|
+
$ spotify-to-mp3 < songs.txt
|
21
|
+
|
22
|
+
## TODO
|
23
|
+
|
24
|
+
- Get best song on Grooveshark
|
25
|
+
- Best matching artist, title and length
|
26
|
+
- Best quality
|
27
|
+
- Consider multiple artists songs
|
28
|
+
- Show download progress
|
29
|
+
- Estimated download time
|
30
|
+
- Per song
|
31
|
+
- Total
|
data/bin/spotify-to-mp3
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'grooveshark'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'colorize'
|
7
|
+
require 'cgi'
|
8
|
+
|
9
|
+
class SpotifyToMp3
|
10
|
+
def initialize(log)
|
11
|
+
@grooveshark = Grooveshark.new
|
12
|
+
@spotify = Spotify.new
|
13
|
+
@log = log
|
14
|
+
end
|
15
|
+
|
16
|
+
def download_song(spotify_uri)
|
17
|
+
log("Getting song info for #{spotify_uri} from Spotify")
|
18
|
+
track = @spotify.track(spotify_uri)
|
19
|
+
filename = File.basename("#{track.artist()} - #{track.name()}.mp3".tr('/', '-'))
|
20
|
+
if (File.exists?(filename))
|
21
|
+
log("File #{filename} already exists, skipping")
|
22
|
+
return
|
23
|
+
end
|
24
|
+
log("Getting download URL for \"#{track.artist()} - #{track.name()}\" from Grooveshark")
|
25
|
+
url = @grooveshark.song_url(track.artist(), track.name())
|
26
|
+
log("Downloading song")
|
27
|
+
download_url(url, filename)
|
28
|
+
log("Song downloaded to #{filename}")
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def log(message)
|
34
|
+
@log.call(message)
|
35
|
+
end
|
36
|
+
|
37
|
+
def download_url(url, path)
|
38
|
+
content = open(url).read
|
39
|
+
file = open(path, 'wb')
|
40
|
+
file.write(content)
|
41
|
+
file.close
|
42
|
+
end
|
43
|
+
|
44
|
+
class Grooveshark
|
45
|
+
def initialize
|
46
|
+
@client = ::Grooveshark::Client.new
|
47
|
+
end
|
48
|
+
|
49
|
+
def song_url(artist, title)
|
50
|
+
song = @client.search_songs("#{artist} #{title}").first
|
51
|
+
raise "Song not found" if song.nil?
|
52
|
+
@client.get_song_url(song)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class Spotify
|
57
|
+
def track(uri)
|
58
|
+
content = open('http://ws.spotify.com/lookup/1/.json?uri=' + CGI.escape(uri))
|
59
|
+
json = JSON.parse(content.string)
|
60
|
+
Track.new(json)
|
61
|
+
end
|
62
|
+
|
63
|
+
class Track
|
64
|
+
def initialize(json)
|
65
|
+
@json = json
|
66
|
+
end
|
67
|
+
|
68
|
+
def name
|
69
|
+
@json['track']['name']
|
70
|
+
end
|
71
|
+
|
72
|
+
def artist
|
73
|
+
@json['track']['artists'].first['name']
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
spotifyToMp3 = SpotifyToMp3.new(lambda { |message| puts message })
|
80
|
+
|
81
|
+
ARGF.each do |spotify_uri|
|
82
|
+
spotify_uri.strip!
|
83
|
+
begin
|
84
|
+
spotifyToMp3.download_song(spotify_uri)
|
85
|
+
rescue
|
86
|
+
puts "ERROR: #{$!}".red
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'spotify-to-mp3'
|
3
|
+
s.summary = 'Spotify to MP3'
|
4
|
+
s.description = 'Download MP3 files of Spotify tracks'
|
5
|
+
s.version = '0.1'
|
6
|
+
s.author = 'Francesc Rosàs'
|
7
|
+
s.email = 'francescrosasbosque@gmail.com'
|
8
|
+
s.homepage = 'https://github.com/frosas/spotify-to-mp3'
|
9
|
+
|
10
|
+
s.add_dependency 'grooveshark'
|
11
|
+
s.add_dependency 'colorize'
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spotify-to-mp3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Francesc Rosàs
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-20 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: grooveshark
|
16
|
+
requirement: &70125705522200 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70125705522200
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: colorize
|
27
|
+
requirement: &70125705513320 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70125705513320
|
36
|
+
description: Download MP3 files of Spotify tracks
|
37
|
+
email: francescrosasbosque@gmail.com
|
38
|
+
executables:
|
39
|
+
- spotify-to-mp3
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- Gemfile
|
44
|
+
- Gemfile.lock
|
45
|
+
- README.markdown
|
46
|
+
- bin/spotify-to-mp3
|
47
|
+
- spotify-to-mp3.gemspec
|
48
|
+
homepage: https://github.com/frosas/spotify-to-mp3
|
49
|
+
licenses: []
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.8.10
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Spotify to MP3
|
72
|
+
test_files: []
|