vk_music 4.1.2 → 4.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +0 -0
  3. data/.github/workflows/ruby.yml +0 -0
  4. data/.gitignore +1 -0
  5. data/.rspec +0 -0
  6. data/.rubocop.yml +8 -0
  7. data/.ruby-version +1 -0
  8. data/Gemfile +13 -12
  9. data/Gemfile.lock +58 -56
  10. data/LICENSE.txt +0 -0
  11. data/README.md +0 -0
  12. data/Rakefile +16 -0
  13. data/bin/console +7 -6
  14. data/lib/vk_music/audio.rb +0 -0
  15. data/lib/vk_music/client.rb +0 -0
  16. data/lib/vk_music/playlist.rb +0 -0
  17. data/lib/vk_music/request/artist.rb +0 -0
  18. data/lib/vk_music/request/audios_reload.rb +0 -0
  19. data/lib/vk_music/request/base.rb +0 -0
  20. data/lib/vk_music/request/login.rb +0 -0
  21. data/lib/vk_music/request/my_page.rb +0 -0
  22. data/lib/vk_music/request/playlist.rb +0 -0
  23. data/lib/vk_music/request/playlist_section.rb +0 -0
  24. data/lib/vk_music/request/post.rb +0 -0
  25. data/lib/vk_music/request/profile.rb +0 -0
  26. data/lib/vk_music/request/search.rb +0 -0
  27. data/lib/vk_music/request/wall_section.rb +0 -0
  28. data/lib/vk_music/request.rb +0 -0
  29. data/lib/vk_music/utility/artist_loader.rb +0 -0
  30. data/lib/vk_music/utility/artist_url_parser.rb +0 -0
  31. data/lib/vk_music/utility/audio_data_parser.rb +0 -0
  32. data/lib/vk_music/utility/audio_items_parser.rb +0 -0
  33. data/lib/vk_music/utility/audio_node_parser.rb +0 -0
  34. data/lib/vk_music/utility/audios_from_ids_loader.rb +0 -0
  35. data/lib/vk_music/utility/audios_ids_getter.rb +0 -0
  36. data/lib/vk_music/utility/audios_loader.rb +0 -0
  37. data/lib/vk_music/utility/authorizer.rb +45 -0
  38. data/lib/vk_music/utility/cookie_reader.rb +33 -0
  39. data/lib/vk_music/utility/data_type_guesser.rb +0 -0
  40. data/lib/vk_music/utility/duration_parser.rb +6 -4
  41. data/lib/vk_music/utility/last_profile_post_loader.rb +0 -0
  42. data/lib/vk_music/utility/link_decoder.rb +0 -0
  43. data/lib/vk_music/utility/node_text_children_reader.rb +0 -0
  44. data/lib/vk_music/utility/playlist_loader.rb +0 -0
  45. data/lib/vk_music/utility/playlist_node_parser.rb +0 -0
  46. data/lib/vk_music/utility/playlist_section_loader.rb +0 -0
  47. data/lib/vk_music/utility/playlist_url_parser.rb +0 -0
  48. data/lib/vk_music/utility/post_loader.rb +3 -1
  49. data/lib/vk_music/utility/post_url_parser.rb +0 -0
  50. data/lib/vk_music/utility/profile_id_resolver.rb +0 -0
  51. data/lib/vk_music/utility/wall_loader.rb +0 -0
  52. data/lib/vk_music/utility.rb +0 -0
  53. data/lib/vk_music/version.rb +1 -1
  54. data/lib/vk_music/web_parser/artist.rb +0 -0
  55. data/lib/vk_music/web_parser/audios_reload.rb +0 -0
  56. data/lib/vk_music/web_parser/base.rb +0 -0
  57. data/lib/vk_music/web_parser/login.rb +0 -0
  58. data/lib/vk_music/web_parser/my_page.rb +0 -0
  59. data/lib/vk_music/web_parser/playlist.rb +0 -0
  60. data/lib/vk_music/web_parser/playlist_section.rb +0 -0
  61. data/lib/vk_music/web_parser/post.rb +0 -0
  62. data/lib/vk_music/web_parser/profile.rb +0 -0
  63. data/lib/vk_music/web_parser/search.rb +0 -0
  64. data/lib/vk_music/web_parser/wall_section.rb +0 -0
  65. data/lib/vk_music/web_parser.rb +0 -0
  66. data/lib/vk_music.rb +0 -0
  67. data/vk_music.gemspec +0 -0
  68. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c96600db101ef3b36aae086473d7954009ee3cd2df78e3c0fb00e17274c9375f
4
- data.tar.gz: 957c1b36785ffdd1f45d772d4a1fa963bf4c9f874947f5f241445801101241a6
3
+ metadata.gz: 328e99f052dc0b5088bfe6951340eddbd1d490e314eb87960d4c09567c321c38
4
+ data.tar.gz: ee672cf125bce6abfd6269a2a2589c546db832334e7a748539834a82f7ad4d91
5
5
  SHA512:
6
- metadata.gz: 07add466eea5a3c516d5b0e9ed968ced90ad5b09077aec19bc4c69f29eeb9894cad9ce174910f323b139daf47bda7b7185664a8e683933210717b75ab0da90c0
7
- data.tar.gz: ba17cb06417c52cbcd45c7204ae36d6a83b76ab6173a2215c0062a7873ccd997eae145a96e397d305258568bbfece837c9186afa7f0789e18b5e0f5543cb10df
6
+ metadata.gz: c96731edad98d27948189374693b6852a46e035a8b4c6fbb76cfcc9b3c6db24d8859f5dd36dea5a071e79ddd9ff9e38a43737694e1499e7ad99a205f754c6fa6
7
+ data.tar.gz: 1c0d2f09244dbbfa36a741bc384aea0f235c407e5ca718197617c138b47844b69f26e7734fa6fd2e837026f636418750333ff4cbb9652056bb05956f1ddd7179
data/.env.example CHANGED
File without changes
File without changes
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ /.cookies
1
2
  /.env
2
3
  /.byebug_history
3
4
  /.bundle/
data/.rspec CHANGED
File without changes
data/.rubocop.yml CHANGED
@@ -54,3 +54,11 @@ Style/DisableCopsWithinSourceCodeDirective:
54
54
  Enabled: false
55
55
  Layout/MultilineHashKeyLineBreaks:
56
56
  Enabled: false
57
+ Layout/SingleLineBlockChain:
58
+ Exclude:
59
+ - 'spec/**/*_spec.rb'
60
+ Style/TopLevelMethodDefinition:
61
+ Exclude:
62
+ - 'spec/login_helper.rb'
63
+ Lint/NumberConversion:
64
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.7.2
data/Gemfile CHANGED
@@ -6,33 +6,34 @@ source 'https://rubygems.org'
6
6
  gemspec
7
7
 
8
8
  group :test, :development do
9
- # Debugging console
10
- gem 'pry'
11
-
12
9
  # Another debugging console
13
- gem 'byebug'
10
+ gem 'byebug', '~> 11.1'
14
11
 
15
12
  # The thing, forcing you to write good code
16
- gem 'rubocop', require: false
13
+ gem 'rubocop', '~> 1.21', require: false
14
+ # Guidelines for writing RSpec tests
15
+ gem 'rubocop-rspec', '~> 2.4', require: false
16
+ # Guidelines for Rake tasks
17
+ gem 'rubocop-rake', '~> 0.6', require: false
17
18
 
18
19
  # Rake tasks
19
- gem 'rake', require: false
20
+ gem 'rake', '~> 13.0', require: false
20
21
 
21
22
  # Testing
22
- gem 'rspec', require: false
23
+ gem 'rspec', '~> 3.10', require: false
23
24
 
24
25
  # Docs
25
- gem 'yard', require: false
26
+ gem 'yard', '~> 0.9', require: false
26
27
 
27
28
  # .env support
28
- gem 'dotenv'
29
+ gem 'dotenv', '~> 2.7'
29
30
 
30
31
  # Save web requests for fast and reliable testing
31
- gem 'vcr'
32
+ gem 'vcr', '~> 6.0'
32
33
 
33
34
  # Stub web requests
34
- gem 'webmock'
35
+ gem 'webmock', '~> 3.14'
35
36
 
36
37
  # Test coverage
37
- gem 'simplecov', require: false, group: :test
38
+ gem 'simplecov', '~> 0.21', require: false, group: :test
38
39
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vk_music (4.1.2)
4
+ vk_music (4.1.5)
5
5
  execjs (~> 2.7)
6
6
  json (~> 2.3)
7
7
  logger (~> 1.4)
@@ -11,55 +11,50 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- addressable (2.7.0)
14
+ addressable (2.8.0)
15
15
  public_suffix (>= 2.0.2, < 5.0)
16
- ast (2.4.1)
16
+ ast (2.4.2)
17
17
  byebug (11.1.3)
18
- coderay (1.1.3)
19
18
  crack (0.4.5)
20
19
  rexml
21
20
  diff-lcs (1.4.4)
22
- docile (1.3.4)
21
+ docile (1.4.0)
23
22
  domain_name (0.5.20190701)
24
23
  unf (>= 0.0.5, < 1.0.0)
25
24
  dotenv (2.7.6)
26
- execjs (2.7.0)
25
+ execjs (2.8.1)
27
26
  hashdiff (1.0.1)
28
- http-cookie (1.0.3)
27
+ http-cookie (1.0.4)
29
28
  domain_name (~> 0.5)
30
- json (2.5.1)
31
- logger (1.4.3)
32
- mechanize (2.7.7)
33
- domain_name (~> 0.5, >= 0.5.1)
34
- http-cookie (~> 1.0)
35
- mime-types (>= 1.17.2)
36
- net-http-digest_auth (~> 1.1, >= 1.1.1)
37
- net-http-persistent (>= 2.5.2)
38
- nokogiri (~> 1.6)
39
- ntlm-http (~> 0.1, >= 0.1.1)
29
+ json (2.6.1)
30
+ logger (1.4.4)
31
+ mechanize (2.8.3)
32
+ addressable (~> 2.8)
33
+ domain_name (~> 0.5, >= 0.5.20190701)
34
+ http-cookie (~> 1.0, >= 1.0.3)
35
+ mime-types (~> 3.0)
36
+ net-http-digest_auth (~> 1.4, >= 1.4.1)
37
+ net-http-persistent (>= 2.5.2, < 5.0.dev)
38
+ nokogiri (~> 1.11, >= 1.11.2)
39
+ rubyntlm (~> 0.6, >= 0.6.3)
40
40
  webrick (~> 1.7)
41
- webrobots (>= 0.0.9, < 0.2)
42
- method_source (1.0.0)
43
- mime-types (3.3.1)
41
+ webrobots (~> 0.1.2)
42
+ mime-types (3.4.1)
44
43
  mime-types-data (~> 3.2015)
45
- mime-types-data (3.2020.1104)
44
+ mime-types-data (3.2021.1115)
46
45
  net-http-digest_auth (1.4.1)
47
46
  net-http-persistent (2.9.4)
48
- nokogiri (1.11.1-x86_64-linux)
47
+ nokogiri (1.12.5-x86_64-linux)
49
48
  racc (~> 1.4)
50
- ntlm-http (0.1.1)
51
- parallel (1.20.1)
52
- parser (3.0.0.0)
49
+ parallel (1.21.0)
50
+ parser (3.0.2.0)
53
51
  ast (~> 2.4.1)
54
- pry (0.13.1)
55
- coderay (~> 1.1)
56
- method_source (~> 1.0)
57
52
  public_suffix (4.0.6)
58
- racc (1.5.2)
53
+ racc (1.6.0)
59
54
  rainbow (3.0.0)
60
- rake (13.0.3)
61
- regexp_parser (2.0.3)
62
- rexml (3.2.4)
55
+ rake (13.0.6)
56
+ regexp_parser (2.1.1)
57
+ rexml (3.2.5)
63
58
  rspec (3.10.0)
64
59
  rspec-core (~> 3.10.0)
65
60
  rspec-expectations (~> 3.10.0)
@@ -69,35 +64,41 @@ GEM
69
64
  rspec-expectations (3.10.1)
70
65
  diff-lcs (>= 1.2.0, < 2.0)
71
66
  rspec-support (~> 3.10.0)
72
- rspec-mocks (3.10.1)
67
+ rspec-mocks (3.10.2)
73
68
  diff-lcs (>= 1.2.0, < 2.0)
74
69
  rspec-support (~> 3.10.0)
75
- rspec-support (3.10.1)
76
- rubocop (1.7.0)
70
+ rspec-support (3.10.2)
71
+ rubocop (1.21.0)
77
72
  parallel (~> 1.10)
78
- parser (>= 2.7.1.5)
73
+ parser (>= 3.0.0.0)
79
74
  rainbow (>= 2.2.2, < 4.0)
80
75
  regexp_parser (>= 1.8, < 3.0)
81
76
  rexml
82
- rubocop-ast (>= 1.2.0, < 2.0)
77
+ rubocop-ast (>= 1.9.1, < 2.0)
83
78
  ruby-progressbar (~> 1.7)
84
- unicode-display_width (>= 1.4.0, < 2.0)
85
- rubocop-ast (1.4.0)
86
- parser (>= 2.7.1.5)
79
+ unicode-display_width (>= 1.4.0, < 3.0)
80
+ rubocop-ast (1.11.0)
81
+ parser (>= 3.0.1.1)
82
+ rubocop-rake (0.6.0)
83
+ rubocop (~> 1.0)
84
+ rubocop-rspec (2.4.0)
85
+ rubocop (~> 1.0)
86
+ rubocop-ast (>= 1.1.0)
87
87
  ruby-progressbar (1.11.0)
88
- simplecov (0.21.1)
88
+ rubyntlm (0.6.3)
89
+ simplecov (0.21.2)
89
90
  docile (~> 1.1)
90
91
  simplecov-html (~> 0.11)
91
92
  simplecov_json_formatter (~> 0.1)
92
93
  simplecov-html (0.12.3)
93
- simplecov_json_formatter (0.1.2)
94
+ simplecov_json_formatter (0.1.3)
94
95
  unf (0.1.4)
95
96
  unf_ext
96
- unf_ext (0.0.7.7)
97
- unicode-display_width (1.7.0)
97
+ unf_ext (0.0.8)
98
+ unicode-display_width (2.1.0)
98
99
  vcr (6.0.0)
99
- webmock (3.11.0)
100
- addressable (>= 2.3.6)
100
+ webmock (3.14.0)
101
+ addressable (>= 2.8.0)
101
102
  crack (>= 0.3.2)
102
103
  hashdiff (>= 0.4.0, < 2.0.0)
103
104
  webrick (1.7.0)
@@ -108,17 +109,18 @@ PLATFORMS
108
109
  ruby
109
110
 
110
111
  DEPENDENCIES
111
- byebug
112
- dotenv
113
- pry
114
- rake
115
- rspec
116
- rubocop
117
- simplecov
118
- vcr
112
+ byebug (~> 11.1)
113
+ dotenv (~> 2.7)
114
+ rake (~> 13.0)
115
+ rspec (~> 3.10)
116
+ rubocop (~> 1.21)
117
+ rubocop-rake (~> 0.6)
118
+ rubocop-rspec (~> 2.4)
119
+ simplecov (~> 0.21)
120
+ vcr (~> 6.0)
119
121
  vk_music!
120
- webmock
121
- yard
122
+ webmock (~> 3.14)
123
+ yard (~> 0.9)
122
124
 
123
125
  BUNDLED WITH
124
126
  2.2.4
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
@@ -16,3 +16,19 @@ YARD::Rake::YardocTask.new do |t|
16
16
  end
17
17
 
18
18
  task default: %i[rubocop spec yard]
19
+
20
+ namespace :clean do
21
+ desc 'Remove generated cassettes'
22
+ task :cassetes do
23
+ require 'fileutils'
24
+
25
+ FileUtils.rm_r Dir.glob('spec/cassetes/*/')
26
+ end
27
+
28
+ desc 'Remove generated cookies'
29
+ task :cookies do
30
+ require 'fileutils'
31
+
32
+ FileUtils.rm('spec/.cookies')
33
+ end
34
+ end
data/bin/console CHANGED
@@ -3,16 +3,17 @@
3
3
 
4
4
  require 'bundler/setup'
5
5
  require 'vk_music'
6
- require 'pry'
6
+ require 'irb'
7
7
  require 'dotenv'
8
8
  Dotenv.load
9
9
 
10
10
  # You can add fixtures and/or initialization code here to make experimenting
11
11
  # with your gem easier. You can also use a different console, if you like.
12
12
 
13
- if ENV['VK_LOGIN'] && ENV['VK_PASSWORD']
14
- client = VkMusic::Client.new(login: ENV['VK_LOGIN'], password: ENV['VK_PASSWORD'])
15
- puts "You now can access client##{client.id}"
16
- end
13
+ # Path to file where development cookies will be stored
14
+ AGENT_COOKIES_PATH = '.cookies'
17
15
 
18
- Pry.start(client || Object.new)
16
+ agent = VkMusic::Utility::Authorizer.call(AGENT_COOKIES_PATH)
17
+ @client = VkMusic::Client.new(agent: agent)
18
+
19
+ IRB.start
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VkMusic
4
+ module Utility
5
+ # Creates authorized client based of cookies file or ENV variables
6
+ module Authorizer
7
+ class << self
8
+ # @param cookie_path [string]
9
+ # @return [Mechanize] logged in Mechanize client
10
+ def call(cookie_path)
11
+ agent = Mechanize.new
12
+ if File.exist?(cookie_path)
13
+ load_cookie_jar(agent.cookie_jar, cookie_path)
14
+ else
15
+ login_agent(agent)
16
+ end
17
+ agent.cookie_jar.save(cookie_path, session: true)
18
+ agent
19
+ end
20
+
21
+ private
22
+
23
+ # @return [Client] logged in client.
24
+ def logged_in_client
25
+ VkMusic::Client.new(agent: logged_in_agent)
26
+ end
27
+
28
+ # @param jar [HTTP::CookieJar]
29
+ # @param path [string]
30
+ def load_cookie_jar(jar, path)
31
+ VkMusic::Utility::CookieReader.call(jar, path)
32
+ rescue StandardError => e
33
+ VkMusic.log.error('authorizer') { "Failed to parse saved cookies: #{e}:\m#{e.full_message}" }
34
+ end
35
+
36
+ # Logs in provided agent
37
+ def login_agent(agent)
38
+ login = VkMusic::Request::Login.new
39
+ login.call(agent)
40
+ login.send_form(ENV['VK_LOGIN'], ENV['VK_PASSWORD'], agent)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VkMusic
4
+ module Utility
5
+ # Reads preserved cookies from file and writes them into a cookie jar
6
+ module CookieReader
7
+ class << self
8
+ # @param jar [HTTP::CookieJar]
9
+ # @param path [string]
10
+ def call(jar, path)
11
+ data = File.read(path)
12
+ data.start_with?('{') ? load_cookie_jar_json(jar, data) : load_cookie_jar_mechanize(jar)
13
+ end
14
+
15
+ private
16
+
17
+ # Loads cookies from JSON data
18
+ def load_cookie_jar_json(jar, data)
19
+ VkMusic.log.info('cookie_reader') { 'Loading JSON cookies' }
20
+ JSON.parse(data).each_pair do |k, v|
21
+ jar.add(URI('https://m.vk.com'), HTTP::Cookie.new(k, v))
22
+ end
23
+ end
24
+
25
+ # Loads cookies from Mechanize file
26
+ def load_cookie_jar_mechanize(jar)
27
+ VkMusic.log.info('cookie_reader') { 'Loading Mechanize cookies' }
28
+ jar.load(AGENT_COOKIES_PATH)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
File without changes
@@ -7,10 +7,12 @@ module VkMusic
7
7
  # @param str [String] string in format "HH:MM:SS" or something alike (+/d++ Regex selector is used)
8
8
  # @return [Integer] amount of seconds
9
9
  def self.call(str)
10
- str.scan(/\d+/)
11
- .map(&:to_i)
12
- .reverse
13
- .each_with_index.reduce(0) { |acc, (count, position)| acc + count * 60**position }
10
+ str
11
+ .scan(/\d+/)
12
+ .map { |i| Integer(i, 10) }
13
+ .reverse
14
+ .each_with_index
15
+ .reduce(0) { |acc, (count, position)| acc + (count * (60**position)) }
14
16
  end
15
17
  end
16
18
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -16,7 +16,9 @@ module VkMusic
16
16
 
17
17
  wall_audios = WallLoader.call(agent, client_id, owner_id, post_id).audios
18
18
 
19
- urlles_audios.map { |urlles| wall_audios.find { |audio| audio.like?(urlles) } }.compact
19
+ urlles_audios
20
+ .map { |urlles| wall_audios.find { |audio| audio.like?(urlles) } }
21
+ .compact
20
22
  end
21
23
  end
22
24
  end
File without changes
File without changes
File without changes
File without changes
@@ -2,6 +2,6 @@
2
2
 
3
3
  module VkMusic
4
4
  # Library version.
5
- VERSION = '4.1.2'
5
+ VERSION = '4.1.5'
6
6
  public_constant :VERSION
7
7
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/lib/vk_music.rb CHANGED
File without changes
data/vk_music.gemspec CHANGED
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vk_music
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.2
4
+ version: 4.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fizvlad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-08 00:00:00.000000000 Z
11
+ date: 2022-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
@@ -92,6 +92,7 @@ files:
92
92
  - ".gitignore"
93
93
  - ".rspec"
94
94
  - ".rubocop.yml"
95
+ - ".ruby-version"
95
96
  - Gemfile
96
97
  - Gemfile.lock
97
98
  - LICENSE.txt
@@ -123,6 +124,8 @@ files:
123
124
  - lib/vk_music/utility/audios_from_ids_loader.rb
124
125
  - lib/vk_music/utility/audios_ids_getter.rb
125
126
  - lib/vk_music/utility/audios_loader.rb
127
+ - lib/vk_music/utility/authorizer.rb
128
+ - lib/vk_music/utility/cookie_reader.rb
126
129
  - lib/vk_music/utility/data_type_guesser.rb
127
130
  - lib/vk_music/utility/duration_parser.rb
128
131
  - lib/vk_music/utility/last_profile_post_loader.rb
@@ -172,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
175
  - !ruby/object:Gem::Version
173
176
  version: '0'
174
177
  requirements: []
175
- rubygems_version: 3.2.4
178
+ rubygems_version: 3.1.4
176
179
  signing_key:
177
180
  specification_version: 4
178
181
  summary: A library to work with audios on popular Russian social network