spotify-music-importer 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98a102cddebecaa8f9ca19531fd3c0841a7a1712
4
- data.tar.gz: 0d36de17b933bee5e607ea4b138626b33df6eb31
3
+ metadata.gz: b515ce34364f422408aff7ba94df8d0baf87b652
4
+ data.tar.gz: 9c658d923536dbf56ca066e9bfa4266b7b885789
5
5
  SHA512:
6
- metadata.gz: 0ad95c6fefbbe29dc4cd97da92d736d76c40a2df8305033d475b307deacdf54f88dfa063d55617c13344e277a6713a8fd1587b1b39516ac037675c5753d8404e
7
- data.tar.gz: 89d7a08f557479f02570009549a45d8e0673b04410a18e167fc247ff4547361e0a9c31923063b9ad306187b6159f7795299e59a9e04a594cdecff60b223eca4f
6
+ metadata.gz: d1f3e6c13eb6cb2434bcd1bc6df9d69d54d91ddb85298e0ed0faf3a9b9bd81c734ad061d7fe56d594897d9388eddefa76ed92218f5867e2d942a8837d13c3c56
7
+ data.tar.gz: e644443e1da4970aa370ea4e90f78361e514508d7e774a0a648792cb7f8c24c8e31ef3c7f7d296e61ae77118e2329b3bad9d5cc1e19883c5e338bf9c3c35d6c4
data/.gitignore CHANGED
@@ -33,3 +33,5 @@ Gemfile.lock
33
33
 
34
34
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
35
  .rvmrc
36
+
37
+ *.json
data/Gemfile CHANGED
@@ -5,7 +5,3 @@ gemspec
5
5
 
6
6
  # Need to use this branch right now
7
7
  gem 'spotify-client', :github => 'X0nic/spotify-client', :branch => 'add-library'
8
-
9
- group :development do
10
- gem 'pry'
11
- end
data/README.md CHANGED
@@ -9,7 +9,7 @@ If you want to import your library of music into spotify, this will help. It use
9
9
  ## Usage
10
10
 
11
11
  ```sh
12
- bundle exec ./import.rb -f CSV_FILE -t SPOTIFY_ACCESS_TOKEN
12
+ bundle exec spotify-music-importer import -f CSV_FILE -t SPOTIFY_ACCESS_TOKEN
13
13
  ```
14
14
 
15
15
  ## Contributing
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'bundler/gem_tasks'
4
+
5
+ task :default => :build
@@ -1,42 +1,19 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
-
5
- require 'optparse'
3
+ require 'thor'
6
4
  require 'spotify/music/importer'
7
5
 
8
- options = {}
9
- OptionParser.new do |opts|
10
- opts.banner = "Usage: import.rb [options]"
11
-
12
- opts.on("-f", "--file FILENAME", "The filename to import") do |filename|
13
- options[:filename] = filename
14
- end
15
-
16
- opts.on("-m", "--missing MISSING.json", "The output filename of bad matches") do |missing|
17
- options[:missing] = missing
18
- end
19
-
20
- opts.on("-l", "--limit LIMIT", "Limit the number of lines to import") do |limit|
21
- options[:limit] = limit.to_i
22
- end
23
-
24
- opts.on("-s", "--skip SKIP", "Skip the first X lines of import") do |skip|
25
- options[:skip] = skip.to_i
26
- end
27
-
28
- opts.on("-t", "--access-token ACCESS_TOKEN", "Your access token to access the Spotify API. Find one here: https://developer.spotify.com/web-api/console/") do |token|
29
- options[:access_token] = token
30
- end
31
-
32
- end.parse!
33
-
34
- importer = Spotify::Music::Importer::Cli.new
35
- importer.import(options[:filename], options)
36
-
37
- if options[:missing]
38
- File.open(options[:missing], 'w') do |f|
39
- puts "Writing to file #{options[:missing]}"
40
- f.write(JSON.pretty_generate(importer.missing))
6
+ class Spotify::Music::Importer::CLI < Thor
7
+ option :filename, :required => true, :aliases => :f, :desc => "The filename to import"
8
+ option :missing, :aliases => :m, :desc => 'The output filename of bad matches'
9
+ option :limit, :aliases => :l, :desc => "Limit the number of lines to import"
10
+ option :skip, :aliases => :s, :default => 0, :desc => "Skip the first X lines of import"
11
+ option :access_token, :required => true, :aliases => :t, :desc => "Your access token to access the Spotify API. Find one here: https://developer.spotify.com/web-api/console/"
12
+ desc 'import', "Import your music library into spotify"
13
+ def import
14
+ importer = Spotify::Music::Importer::Processor.new
15
+ importer.import(options[:filename], options)
41
16
  end
42
17
  end
18
+
19
+ Spotify::Music::Importer::CLI.start
@@ -6,19 +6,16 @@ require 'colorize'
6
6
  require 'csv'
7
7
  require 'spotify-client'
8
8
 
9
-
10
9
  module Spotify
11
10
  module Music
12
11
  module Importer
13
- class Cli
14
- def initialize
15
- end
16
-
12
+ class Processor
17
13
  def import(filename, options)
18
- @options = options
14
+ @options = options.dup
19
15
  @library = SpotifyLibrary.new(client)
20
- limit = options.delete(:limit) { nil }
21
- skip = options.delete(:skip) { 0 }
16
+ require 'pry' ; binding.pry
17
+ limit = options.fetch(:limit) { nil }
18
+ skip = options.fetch(:skip) { 0 }
22
19
 
23
20
  collection = CSV.read(filename, :headers => true)
24
21
  collection.each_with_index do |row, index|
@@ -29,6 +26,13 @@ module Spotify
29
26
  results = SpotifyMatch.new(client.search(:track, format_query(record)), :clean_album => true, :clean_track => true)
30
27
  @library.find_and_add_to_library(record, results, index)
31
28
  end
29
+
30
+ if options[:missing]
31
+ File.open(options[:missing], 'w') do |f|
32
+ puts "Writing to file #{options[:missing]}"
33
+ f.write(JSON.pretty_generate(importer.missing))
34
+ end
35
+ end
32
36
  end
33
37
 
34
38
  def missing
@@ -1,7 +1,7 @@
1
1
  module Spotify
2
2
  module Music
3
3
  module Importer
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  end
7
7
  end
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_dependency 'spotify-client'
26
26
  spec.add_dependency 'colorize'
27
+ spec.add_dependency 'thor'
27
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spotify-music-importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description:
84
98
  email:
85
99
  - nathan@globalphobia.com