Class: Bilibili::BilibiliBase

Inherits:
Object
  • Object
show all
Defined in:
lib/bilibili_console/base.rb

Overview

base class

Direct Known Subclasses

Fav, Login, Manga, Video

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_client) ⇒ BilibiliBase

Returns a new instance of BilibiliBase.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bilibili_console/base.rb', line 23

def initialize(http_client)
  @http_client = http_client
  create_request_methods
  @options = {
    'config_path' => '~/.bc', 'config_file' => '~/.bc/config.json',
    'cookie_file' => '~/.bc/cookie.txt', 'download_path' => '~/.bc/download'
  }
  BilibiliBase.video_qn = {
    '240' => 6, '360' => 16, '480' => 32, '720' => 64, '720P60' => 74, '1080' => 80,
    '1080+' => 112, '1080P60' => 116, '4K' => 120, 'HDR' => 125
  }
end

Class Attribute Details

.video_qnObject

Returns the value of attribute video_qn.



20
21
22
# File 'lib/bilibili_console/base.rb', line 20

def video_qn
  @video_qn
end

Instance Attribute Details

#http_clientObject

Returns the value of attribute http_client.



17
18
19
# File 'lib/bilibili_console/base.rb', line 17

def http_client
  @http_client
end

#optionsObject

Returns the value of attribute options.



17
18
19
# File 'lib/bilibili_console/base.rb', line 17

def options
  @options
end

Instance Method Details



53
54
55
56
57
# File 'lib/bilibili_console/base.rb', line 53

def clean_cookie
  File.open(cookie_path, 'w') do |file|
    file.write('{}')
  end
end


44
45
46
47
48
49
50
51
# File 'lib/bilibili_console/base.rb', line 44

def load_cookie
  return {} unless File.exist?(cookie_path)

  json_str = File.read(cookie_path)
  return {} if json_str.nil? || json_str.empty?

  JSON.parse(json_str)
end


36
37
38
39
40
41
42
# File 'lib/bilibili_console/base.rb', line 36

def save_cookie
  check_config_path

  @http_client.api_http.cookies = @http_client..cookies
  json_str = @http_client..cookies.to_json
  write_cookie(json_str)
end