vk_music 4.1.4 → 4.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +8 -10
- data/bin/console +7 -6
- data/lib/vk_music/utility/authorizer.rb +45 -0
- data/lib/vk_music/utility/cookie_reader.rb +33 -0
- data/lib/vk_music/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 328e99f052dc0b5088bfe6951340eddbd1d490e314eb87960d4c09567c321c38
|
4
|
+
data.tar.gz: ee672cf125bce6abfd6269a2a2589c546db832334e7a748539834a82f7ad4d91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c96731edad98d27948189374693b6852a46e035a8b4c6fbb76cfcc9b3c6db24d8859f5dd36dea5a071e79ddd9ff9e38a43737694e1499e7ad99a205f754c6fa6
|
7
|
+
data.tar.gz: 1c0d2f09244dbbfa36a741bc384aea0f235c407e5ca718197617c138b47844b69f26e7734fa6fd2e837026f636418750333ff4cbb9652056bb05956f1ddd7179
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vk_music (4.1.
|
4
|
+
vk_music (4.1.5)
|
5
5
|
execjs (~> 2.7)
|
6
6
|
json (~> 2.3)
|
7
7
|
logger (~> 1.4)
|
@@ -26,9 +26,9 @@ GEM
|
|
26
26
|
hashdiff (1.0.1)
|
27
27
|
http-cookie (1.0.4)
|
28
28
|
domain_name (~> 0.5)
|
29
|
-
json (2.
|
30
|
-
logger (1.4.
|
31
|
-
mechanize (2.8.
|
29
|
+
json (2.6.1)
|
30
|
+
logger (1.4.4)
|
31
|
+
mechanize (2.8.3)
|
32
32
|
addressable (~> 2.8)
|
33
33
|
domain_name (~> 0.5, >= 0.5.20190701)
|
34
34
|
http-cookie (~> 1.0, >= 1.0.3)
|
@@ -39,20 +39,18 @@ GEM
|
|
39
39
|
rubyntlm (~> 0.6, >= 0.6.3)
|
40
40
|
webrick (~> 1.7)
|
41
41
|
webrobots (~> 0.1.2)
|
42
|
-
mime-types (3.
|
42
|
+
mime-types (3.4.1)
|
43
43
|
mime-types-data (~> 3.2015)
|
44
|
-
mime-types-data (3.2021.
|
45
|
-
mini_portile2 (2.6.1)
|
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.12.
|
49
|
-
mini_portile2 (~> 2.6.1)
|
47
|
+
nokogiri (1.12.5-x86_64-linux)
|
50
48
|
racc (~> 1.4)
|
51
49
|
parallel (1.21.0)
|
52
50
|
parser (3.0.2.0)
|
53
51
|
ast (~> 2.4.1)
|
54
52
|
public_suffix (4.0.6)
|
55
|
-
racc (1.
|
53
|
+
racc (1.6.0)
|
56
54
|
rainbow (3.0.0)
|
57
55
|
rake (13.0.6)
|
58
56
|
regexp_parser (2.1.1)
|
data/bin/console
CHANGED
@@ -3,16 +3,17 @@
|
|
3
3
|
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'vk_music'
|
6
|
-
require '
|
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
|
-
|
14
|
-
|
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
|
-
|
16
|
+
agent = VkMusic::Utility::Authorizer.call(AGENT_COOKIES_PATH)
|
17
|
+
@client = VkMusic::Client.new(agent: agent)
|
18
|
+
|
19
|
+
IRB.start
|
@@ -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
|
data/lib/vk_music/version.rb
CHANGED
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.
|
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:
|
11
|
+
date: 2022-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: execjs
|
@@ -124,6 +124,8 @@ files:
|
|
124
124
|
- lib/vk_music/utility/audios_from_ids_loader.rb
|
125
125
|
- lib/vk_music/utility/audios_ids_getter.rb
|
126
126
|
- lib/vk_music/utility/audios_loader.rb
|
127
|
+
- lib/vk_music/utility/authorizer.rb
|
128
|
+
- lib/vk_music/utility/cookie_reader.rb
|
127
129
|
- lib/vk_music/utility/data_type_guesser.rb
|
128
130
|
- lib/vk_music/utility/duration_parser.rb
|
129
131
|
- lib/vk_music/utility/last_profile_post_loader.rb
|