deezify 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c8dbfad3fc904e960f7b6df2967a725ac27cffdc
4
+ data.tar.gz: 79f89eaa0378a01ee67ca0bae733a89ba6d22bc8
5
+ SHA512:
6
+ metadata.gz: 3ef21f873817f0770e7cc5eb97189d301ccd007efd8e4ee5d6812f9c6d5834f59a3696123364d89291c0a68a52665430349727bba9d0ca7d4d38b1ef3d77b298
7
+ data.tar.gz: 1880e45ee45c781e11a73d60fa069026e5bc72d6505393f1f09c7c6ed8fe2dc34e1d7fe692f478305d806b792395f08a37a5e4761fba4132bdb32cca652390d9
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in deezify.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 dmsirotenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # Deezify
2
+
3
+ A simple command line tool that can export any Spotify playlists to your Deezer account.
4
+
5
+ ## Installation
6
+
7
+ Install it using command:
8
+
9
+ $ gem install deezify
10
+
11
+ ## Configuration
12
+
13
+ Before using this tool, you should set the following environment variables:
14
+
15
+ - ``SPOTIFY_CLIENT_ID`` and ``SPOTIFY_CLIENT_SECRET``: You can easily generate them [here](https://developer.spotify.com/my-applications)
16
+ - ``DEEZER_ACCESS_TOKEN``
17
+
18
+ ## Usage
19
+
20
+ Export a playlist created by spotify:
21
+
22
+ $ deezify export PLAYLIST_ID
23
+
24
+ Or by any other user:
25
+
26
+ $ deezify export PLAYLIST_ID -u=USER
27
+
28
+ ## License
29
+
30
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'deezify'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'deezify'
4
+
5
+ Deezify::CLI.start(ARGV)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'deezify/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'deezify'
8
+ spec.version = Deezify::VERSION
9
+ spec.authors = ['Dmitry Sirotenko']
10
+ spec.email = ['dmitriy.sirotencko@gmail.com']
11
+
12
+ spec.summary = %q{A simple command line tool which transfers spotify playlists to your deezer account.}
13
+ spec.homepage = 'https://github.com/dmsirotenko/deezify'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'bin'
20
+ spec.executables = ['deezify']
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'thor'
24
+ spec.add_dependency 'faraday'
25
+ spec.add_dependency 'rspotify'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.15'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ end
@@ -0,0 +1,8 @@
1
+ require 'deezify/version'
2
+ require 'deezify/api'
3
+ require 'deezify/exporter'
4
+ require 'deezify/cli'
5
+
6
+ module Deezify
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,7 @@
1
+ require 'deezify/api/spotify'
2
+ require 'deezify/api/deezer'
3
+
4
+ module Deezify
5
+ module API
6
+ end
7
+ end
@@ -0,0 +1,62 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Deezify
5
+ module API
6
+ class Deezer
7
+ def initialize
8
+ @connection = connection
9
+ end
10
+
11
+ def user_info
12
+ res = @connection.get do |req|
13
+ req.url '/user/me'
14
+ end
15
+
16
+ json_decode res.body
17
+ end
18
+
19
+ def search(query, params={})
20
+ unless params.empty?
21
+ query = params.map{ |k, v| %Q(#{k}:"#{v}") }.join(' ')
22
+ end
23
+
24
+ res = @connection.get do |req|
25
+ req.url '/search'
26
+ req.params[:q] = query
27
+ end
28
+
29
+ json_decode(res.body)[:data]
30
+ end
31
+
32
+ def create_playlist(title)
33
+ res = @connection.post do |req|
34
+ req.url '/user/me/playlists'
35
+ req.params[:title] = title
36
+ end
37
+
38
+ json_decode res.body
39
+ end
40
+
41
+ def add_tracks(playlist_id, *tracks)
42
+ @connection.post do |req|
43
+ req.url "/playlist/#{playlist_id}/tracks"
44
+ req.params[:songs] = tracks.join ','
45
+ end
46
+ end
47
+
48
+ def connection
49
+ Faraday.new url: 'https://api.deezer.com/' do |conn|
50
+ conn.adapter Faraday.default_adapter
51
+ conn.params[:access_token] = ENV.fetch('DEEZER_ACCESS_TOKEN')
52
+ end
53
+ end
54
+
55
+ def json_decode(string)
56
+ JSON.parse string, symbolize_names: true
57
+ end
58
+
59
+ private :connection, :json_decode
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,22 @@
1
+ require 'rspotify'
2
+
3
+ module Deezify
4
+ module API
5
+ class Spotify
6
+ def initialize
7
+ authenticate
8
+ end
9
+
10
+ def playlist(user_id, playlist_id)
11
+ RSpotify::Playlist.find user_id, playlist_id
12
+ end
13
+
14
+ def authenticate
15
+ RSpotify.authenticate ENV.fetch('SPOTIFY_CLIENT_ID'),
16
+ ENV.fetch('SPOTIFY_CLIENT_SECRET')
17
+ end
18
+
19
+ private :authenticate
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ require 'thor'
2
+
3
+ module Deezify
4
+ class CLI < Thor
5
+ desc 'export PLAYLIST', 'export playlist with id PLAYLIST to your deezer account'
6
+
7
+ method_option :user, aliases: '-u', default: 'spotify', desc: 'Specify owner of playlist'
8
+
9
+ def export(playlist)
10
+ exporter = Deezify::Exporter.new
11
+ exporter.export_playlist options[:user], playlist
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,51 @@
1
+ module Deezify
2
+ class Exporter
3
+ def initialize
4
+ @spotify = Deezify::API::Spotify.new
5
+ @deezer = Deezify::API::Deezer.new
6
+ end
7
+
8
+ def export_playlist(user_id, playlist_id)
9
+ playlist = @spotify.playlist user_id, playlist_id
10
+
11
+ puts "Starting to export: #{playlist.name}"
12
+
13
+ tracks = get_tracks playlist
14
+ create_playlist playlist.name, tracks
15
+
16
+ puts "Successfully added #{tracks.size} tracks"
17
+
18
+ # @TODO: export more than 100 tracks
19
+ # @TODO: add progress bar
20
+ # @TODO: check playlist existence and recreate it
21
+
22
+ # @FIXME: sometimes finds wrong tracks or doesn't find track at all
23
+ end
24
+
25
+ def get_tracks(playlist)
26
+ playlist.tracks(limit: 100).map { |track|
27
+ track = find_track(track)
28
+ track[:id] unless track.nil?
29
+ }.reject(&:nil?)
30
+ end
31
+
32
+ def find_track(track)
33
+ search_params = {
34
+ artist: track.artists.map(&:name).join(' '),
35
+ name: track.name,
36
+ album: track.album.name
37
+ }
38
+
39
+ tracks = @deezer.search search_params.values.join ' '
40
+
41
+ tracks.first unless tracks.empty?
42
+ end
43
+
44
+ def create_playlist(name, tracks)
45
+ playlist = @deezer.create_playlist "#{name} on Spotify"
46
+ @deezer.add_tracks playlist[:id], tracks
47
+ end
48
+
49
+ private :find_track, :create_playlist
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module Deezify
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deezify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry Sirotenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspotify
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.15'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.15'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description:
84
+ email:
85
+ - dmitriy.sirotencko@gmail.com
86
+ executables:
87
+ - deezify
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/deezify
98
+ - bin/setup
99
+ - deezify.gemspec
100
+ - lib/deezify.rb
101
+ - lib/deezify/api.rb
102
+ - lib/deezify/api/deezer.rb
103
+ - lib/deezify/api/spotify.rb
104
+ - lib/deezify/cli.rb
105
+ - lib/deezify/exporter.rb
106
+ - lib/deezify/version.rb
107
+ homepage: https://github.com/dmsirotenko/deezify
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5.2
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: A simple command line tool which transfers spotify playlists to your deezer
131
+ account.
132
+ test_files: []