xiami_radio 1.1.10 → 1.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef36812679c211bf6c72fda6c22fb0a390269e360b382df65e2f98912c3f51b4
4
- data.tar.gz: 233923767c98494bc54bf49bb3bf0bc102b778327cf9f3e3802ed27eec259c72
3
+ metadata.gz: c80df547afbbfc2284323017626b157e353bddeb015ba83a473d0e5cd9fc3336
4
+ data.tar.gz: 7875216b5308b02065d7c7b7f1c115234bc1f980a13f71155e647adf793a0941
5
5
  SHA512:
6
- metadata.gz: 11c216165188696466edf7f5c1fe3b4ed4e20f92205422ad368d8579e6ce8f97fce69c5296282abeab520163edf13afe2eb599027efcdaaf558077f504f6ef67
7
- data.tar.gz: 6325ca7a7f9b84f73505bc1bec2484e792bfdea916374cd9205b072f7d00338886dca32445323e261f010ae9775640f4d748b93c06dd7455da1f39b36604cb2e
6
+ metadata.gz: f789017ef89a92681a64a07b6a8bcb95188b3acc36ef12acb2a5ae6e762b21c2012f1f09626833bc4aaf795849a66d8d8f8ff862941ffb2602532660f4b54b4e
7
+ data.tar.gz: 73ef890cbb1ffeced6dada265b642853609f4039f650763cc6f378b6c6b62c3ae24d1b1b847c58550be1f507d493db1803c6d5921acc1b0bce5925057de4a1e3
@@ -5,6 +5,8 @@ require 'xiami_radio'
5
5
  require 'io/console'
6
6
  require 'daemons'
7
7
 
8
+ XiamiRadio.init
9
+
8
10
  daemons_opts = {
9
11
  app_name: 'xiami_radio',
10
12
  dir_mode: :normal,
@@ -17,15 +19,24 @@ def send_next_signal(app)
17
19
  Process.kill :SIGUSR1, app.pid.pid
18
20
  end
19
21
 
20
- case ARGV[0]
21
- when 'stop', 'status'
22
- Daemons.run_proc 'xiami_radio', daemons_opts
23
- exit
24
- when 'next'
25
- Daemons.run_proc 'xiami_radio', daemons_opts.merge(ARGV: ['status'], show_status_callback: :send_next_signal)
26
- exit
22
+ def send_which_signal(app)
23
+ File.delete XiamiRadio.track_info_swap
24
+ Process.kill :SIGUSR2, app.pid.pid
25
+ sleep 0.1
26
+ puts File.read XiamiRadio.track_info_swap
27
27
  end
28
28
 
29
+ if ARGV[0] == '-s'
30
+ case ARGV[1]
31
+ when 'stop', 'status'
32
+ Daemons.run_proc 'xiami_radio', daemons_opts.merge(ARGV: ARGV[1..-1])
33
+ when 'next'
34
+ Daemons.run_proc 'xiami_radio', daemons_opts.merge(ARGV: ['status'], show_status_callback: :send_next_signal)
35
+ when 'name', 'which', 'what'
36
+ Daemons.run_proc 'xiami_radio', daemons_opts.merge(ARGV: ['status'], show_status_callback: :send_which_signal)
37
+ end
38
+ exit
39
+ end
29
40
 
30
41
  args = ARGV.select { |arg| /^[a-zA-Z]+=.+/ === arg }.inject({}) do |res, arg|
31
42
  k, v = arg.split("=")
@@ -68,7 +79,14 @@ else
68
79
  end
69
80
 
70
81
  if original_argv.include? '-d'
82
+ if RUBY_PLATFORM.include?('x86_64-darwin') && ENV['OBJC_DISABLE_INITIALIZE_FORK_SAFETY'] != 'YES'
83
+ puts "Plz setup OBJC_DISABLE_INITIALIZE_FORK_SAFETY firstly:"
84
+ puts " export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES"
85
+ return
86
+ end
87
+
71
88
  Daemons.run_proc 'xiami_radio', daemons_opts.merge(ARGV: ['start']) do
89
+ XiamiRadio.init
72
90
  XiamiRadio::Player.play XiamiRadio::Radio.new(type: radio_type, oid: radio_oid)
73
91
  end
74
92
  else
@@ -19,24 +19,25 @@ module XiamiRadio
19
19
  Thread.abort_on_exception = true
20
20
 
21
21
  class << self
22
+ attr_reader :logger
23
+
22
24
  def init
23
25
  mktmpdir
24
26
  $stderr.reopen File.join(TMP_DIR, '戊'), 'w'
25
- logger.level = debug? ? :debug : :warn
27
+ @logger = Logger.new File.join(TMP_DIR, '戊')
28
+ logger.level = debug? ? :debug : :info
26
29
  end
27
30
 
28
31
  def mktmpdir
29
32
  Dir.mkdir TMP_DIR, 0700 unless Dir.exist? TMP_DIR
30
33
  end
31
34
 
32
- def logger
33
- @logger ||= Logger.new File.join(TMP_DIR, '戊')
34
- end
35
-
36
35
  def debug?
37
36
  %w(1 true on).include? ENV.fetch('DEBUG', DEBUG)
38
37
  end
38
+
39
+ def track_info_swap
40
+ File.join(XiamiRadio::TMP_DIR, '庚')
41
+ end
39
42
  end
40
43
  end
41
-
42
- XiamiRadio.init
@@ -41,7 +41,7 @@ module XiamiRadio
41
41
  if res.code == '302'
42
42
  request URI(res.header['Location'])
43
43
  else
44
- XiamiRadio.logger.debug "#{@track.title} download start"
44
+ XiamiRadio.logger.info "#{@track.title} download start"
45
45
  @progress, @total = 0, res.header['Content-Length'].to_i
46
46
  @file = File.open(filename, 'w')
47
47
  res.read_body do |chunk|
@@ -51,7 +51,7 @@ module XiamiRadio
51
51
  end
52
52
  end
53
53
  end
54
- XiamiRadio.logger.debug "#{@track.title} download completed"
54
+ XiamiRadio.logger.info "#{@track.title} download completed"
55
55
  end
56
56
  end
57
57
  end
@@ -16,6 +16,11 @@ module XiamiRadio
16
16
  @view.listen_on self
17
17
 
18
18
  trap(:SIGUSR1) { self.next }
19
+ trap(:SIGUSR2) do
20
+ File.open(XiamiRadio.track_info_swap, 'w') do |f|
21
+ f.puts "#{self.track.title} - #{self.track.artist} - #{self.track.album_name}"
22
+ end
23
+ end
19
24
  end
20
25
 
21
26
  def play
@@ -28,7 +33,7 @@ module XiamiRadio
28
33
 
29
34
  def next
30
35
  @track.downloader.stop
31
- if preload?
36
+ if preloading?
32
37
  @track, @next_track = @next_track, nil
33
38
  else
34
39
  @track = @radio.next_track
@@ -54,9 +59,9 @@ module XiamiRadio
54
59
  def position_change(position)
55
60
  @view.refresh @track, position
56
61
 
57
- @track.record position.to_i if (120.0..120.1).include? position
62
+ @track.record position.to_i if (120.0..123.0).include? position
58
63
 
59
- if !preload? && position / @track.duration > 0.7
64
+ if !preloading? && position / @track.duration > 0.8
60
65
  @preloader = Thread.start do
61
66
  @next_track = @radio.next_track
62
67
  @player.queue @next_track.file_path
@@ -65,13 +70,12 @@ module XiamiRadio
65
70
  end
66
71
 
67
72
  def complete
68
- @track, @next_track = @next_track, nil
69
73
  @track.record
74
+ @track, @next_track = @next_track, nil
70
75
  end
71
76
 
72
- def preload?
73
- return true unless @next_track.nil?
74
- !@preloader.nil? && @preloader.alive?
77
+ def preloading?
78
+ !@next_track.nil? || @preloader&.alive?
75
79
  end
76
80
 
77
81
  def self.play(radio)
@@ -6,13 +6,12 @@ module XiamiRadio
6
6
 
7
7
  XIAMI_CAI = {type: 8, oid: 0}.freeze
8
8
 
9
- attr_reader :type, :oid, :nori, :play_queue, :client
9
+ attr_reader :type, :oid, :play_queue, :client
10
10
 
11
11
  def initialize(type:, oid:)
12
12
  @type = type
13
13
  @oid = oid
14
14
  @client = Client.new user: User.instance
15
- @nori = Nori.new(:convert_tags_to => -> (tag) { tag.snakecase.to_sym })
16
15
  @play_queue = []
17
16
  end
18
17
 
@@ -1,6 +1,7 @@
1
1
  module XiamiRadio
2
2
  class Track
3
3
  attr_reader :info, :title, :song_id, :album_name, :artist, :radio, :client
4
+ attr_accessor :recorded
4
5
 
5
6
  def initialize(track, radio:)
6
7
  @info = track
@@ -43,13 +44,16 @@ module XiamiRadio
43
44
  end
44
45
 
45
46
  def record(point = 1)
46
- Thread.start do
47
- client.init_http
48
- uri = client.uri path: '/count/playrecord', query: URI.encode_www_form(
49
- sid: song_id, type:10, start_point: point, _xiamitoken: client.user.xiami_token
50
- )
51
- client.get(uri, headers: radio.headers_referer, format: :xhtml)
52
- XiamiRadio.logger.debug "#{title} record completed"
47
+ @recorded ||= begin
48
+ Thread.start do
49
+ client.init_http
50
+ uri = client.uri path: '/count/playrecord', query: URI.encode_www_form(
51
+ sid: song_id, type:10, start_point: point, _xiamitoken: client.user.xiami_token
52
+ )
53
+ client.get(uri, headers: radio.headers_referer, format: :xhtml)
54
+ XiamiRadio.logger.info "#{title} record completed"
55
+ true
56
+ end
53
57
  end
54
58
  end
55
59
 
@@ -1,5 +1,5 @@
1
1
  module XiamiRadio
2
2
 
3
- VERSION = '1.1.10'
3
+ VERSION = '1.1.11'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xiami_radio
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.10
4
+ version: 1.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Chou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-06 00:00:00.000000000 Z
11
+ date: 2019-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: audite