music_compare 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1109fa561fe9142a635a7e261cc8b7091070eb0262acb2f794570f9bed69ba1f
4
+ data.tar.gz: f96bd784763b5cf13f1b81ab3927770aecdf6d7dd1edb16b44f69ae4f389a06d
5
+ SHA512:
6
+ metadata.gz: 5bccd75839a6b33a2940bf77a634d70b533a87543b7e0e8187fbf332177ef626a9a243fa98f50194d7f2fa2b1015af413e49884350f2ec67cb1970a791a1f482
7
+ data.tar.gz: 85c559e73d338682ed98f97ad3b100b5410af4bef893265ad3db9334f4e813df8a13950fa830cc8cf4de44cc066f5843f837e1958862265d38d2ab977e2b40e6
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.5
5
+
6
+ Layout/LineLength:
7
+ Max: 120
8
+
9
+ RSpec/NamedSubject:
10
+ Enabled: false
11
+
12
+ Metrics/BlockLength:
13
+ Enabled: false
14
+
15
+ Metrics/AbcSize:
16
+ Enabled: false
17
+
18
+ Style/Documentation:
19
+ Enabled: false
20
+
21
+ Metrics/MethodLength:
22
+ Max: 20
23
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-08-02
4
+
5
+ - Initial release
6
+ ### features:
7
+ - fetch public playlists from spotify into .csv files
8
+ - compare two .csv playlist files for matches
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at kozelolezhka@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Robot-Oleg
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # MusicCompare
2
+
3
+ With this gem you can:
4
+ - fetch public playlists from spotify into .csv files
5
+ - compare two .csv playlist files for matches
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'music_compare'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install music_compare
22
+
23
+ ## Usage
24
+ First you need to specify 'client_id' and 'client_secret', you can do this in .env file or when you create an object:
25
+ ```ruby
26
+ compare = MusicCompare::Compare.new('client_id', 'client_secret')
27
+ ```
28
+ ### Fetch playlists
29
+ To fetch playlists from spotify you need playlists id's, for example:
30
+ - https://open.spotify.com/playlist/<mark>1Iddrohefgh7PJgNjL9Kmp</mark>
31
+ - https://open.spotify.com/playlist/<mark>1Iddrohefgh7PJgNjL9Kmp</mark>?si=0898cf7f075443e9&nd=1
32
+
33
+ ```ruby
34
+ playlists = ['1Iddrohefgh7PJgNjL9Kmp', '7r88KVwegNkxSl36zrhx30']
35
+ compare.fetch_playlists!(playlists)
36
+ ```
37
+ also you can specify directory path, where you want to store you playlists:
38
+
39
+ ```ruby
40
+ compare.fetch_playlists!(playlists, dir_path: 'home/username/')
41
+ ```
42
+ ### Compare playlists
43
+ ```ruby
44
+ compare.compare('1Iddrohefgh7PJgNjL9Kmp', '7r88KVwegNkxSl36zrhx30')
45
+ ```
46
+ or with directory path:
47
+ ```ruby
48
+ compare.compare('1Iddrohefgh7PJgNjL9Kmp', '7r88KVwegNkxSl36zrhx30', dir_path: 'home/username')
49
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "music_compare"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'music_compare/version'
4
+ require 'rspotify'
5
+ require 'dotenv/load'
6
+ require 'csv'
7
+
8
+ module MusicCompare
9
+ class Error < StandardError; end
10
+
11
+ class Compare
12
+ def initialize(client_id: ENV['CLIENT_ID'], client_secret: ENV['CLIENT_SECRET'])
13
+ RSpotify.authenticate(client_id, client_secret)
14
+ end
15
+
16
+ def compare(playlist1, playlist2, dir_path: '')
17
+ fetch_playlists!([playlist1, playlist2], dir_path: dir_path)
18
+ file1 = CSV.read(playlist_path(playlist1, dir_path: @dir_path))
19
+ file2 = CSV.read(playlist_path(playlist2, dir_path: @dir_path))
20
+ matches_arr = file1 & file2
21
+ CSV.open("#{dir_path}matches.csv", 'w') do |matches|
22
+ matches_arr.each { |line| matches << line }
23
+ end
24
+ rm_dir(dir_path)
25
+ end
26
+
27
+ def fetch_playlists!(playlists, dir_path: '')
28
+ create_dir(dir_path)
29
+ playlists.each do |playlist|
30
+ response = make_request(playlist_request(playlist))
31
+ CSV.open(playlist_path(playlist, dir_path: @dir_path), 'a') do |playlist_file|
32
+ loop do
33
+ response['items'].each do |track|
34
+ playlist_file << [
35
+ track['track']['name'],
36
+ track['track']['artists'].map { |artist| artist['name'] }.join(' ')
37
+ ]
38
+ end
39
+ break if response['next'].nil?
40
+
41
+ response = make_request(response['next'])
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def make_request(request)
50
+ RSpotify.resolve_auth_request(nil, request)
51
+ rescue RestClient::BadRequest
52
+ raise Error, 'invalid playlist id'
53
+ end
54
+
55
+ def rm_dir(dir_path)
56
+ FileUtils.rm_rf("#{dir_path}playlists")
57
+ end
58
+
59
+ def create_dir(dir_path)
60
+ process_dir_path!(dir_path)
61
+ Dir.mkdir("#{dir_path}playlists")
62
+ rescue Errno::ENOENT
63
+ @dir_path = ''
64
+ Dir.mkdir('playlists')
65
+ end
66
+
67
+ def playlist_path(playlist, dir_path: '')
68
+ "#{dir_path}playlists/#{playlist}.csv"
69
+ end
70
+
71
+ def playlist_request(playlist)
72
+ "playlists/#{playlist}/tracks?fields=items(track(name,artists(name))),next"
73
+ end
74
+
75
+ def process_dir_path!(dir_path)
76
+ return if dir_path.empty?
77
+
78
+ @dir_path = dir_path
79
+ @dir_path << '/' unless dir_path.end_with?('/')
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MusicCompare
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/music_compare/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'music_compare'
7
+ spec.version = MusicCompare::VERSION
8
+ spec.authors = ['Robot-Oleg']
9
+ spec.email = ['kozelolezhka@gmail.com']
10
+
11
+ spec.summary = 'calculate coincidence(in %) between two music accounts'
12
+ # spec.description = 'TODO: Write a longer description or delete this line.'
13
+ spec.homepage = 'https://github.com/Robot-Oleg/music_compare'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.5.0'
16
+
17
+ # spec.metadata['allowed_push_host'] = 'TODO: Set to 'https://mygemserver.com''
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/Robot-Oleg/music_compare'
21
+ # spec.metadata['changelog_uri'] = 'TODO: Put your gem's CHANGELOG.md URL here.'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_dependency 'csv'
33
+ spec.add_dependency 'dotenv'
34
+ spec.add_dependency 'fileutils'
35
+ spec.add_dependency 'rspotify'
36
+
37
+ spec.add_development_dependency 'pry-byebug'
38
+ spec.add_development_dependency 'rake', '~> 13.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.0'
40
+ spec.add_development_dependency 'rubocop', '~> 1.7'
41
+ spec.add_development_dependency 'rubocop-rspec'
42
+ spec.add_development_dependency 'webmock'
43
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: music_compare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robot-Oleg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: csv
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: dotenv
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: fileutils
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: rspotify
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '13.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '13.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description:
154
+ email:
155
+ - kozelolezhka@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".rspec"
161
+ - ".rubocop.yml"
162
+ - CHANGELOG.md
163
+ - CODE_OF_CONDUCT.md
164
+ - Gemfile
165
+ - LICENSE
166
+ - README.md
167
+ - Rakefile
168
+ - bin/console
169
+ - bin/setup
170
+ - lib/music_compare.rb
171
+ - lib/music_compare/version.rb
172
+ - music_compare.gemspec
173
+ homepage: https://github.com/Robot-Oleg/music_compare
174
+ licenses:
175
+ - MIT
176
+ metadata:
177
+ homepage_uri: https://github.com/Robot-Oleg/music_compare
178
+ source_code_uri: https://github.com/Robot-Oleg/music_compare
179
+ post_install_message:
180
+ rdoc_options: []
181
+ require_paths:
182
+ - lib
183
+ required_ruby_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: 2.5.0
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ requirements: []
194
+ rubygems_version: 3.2.22
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: calculate coincidence(in %) between two music accounts
198
+ test_files: []