Class: DoubanFM::Player
- Inherits:
-
Object
- Object
- DoubanFM::Player
- Defined in:
- lib/doubanfm/player.rb
Instance Method Summary collapse
-
#initialize ⇒ Player
constructor
A new instance of Player.
- #login ⇒ Object
- #play ⇒ Object
- #skip ⇒ Object
- #start ⇒ Object
Constructor Details
Instance Method Details
#login ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/doubanfm/player.rb', line 59 def login return if @client.user_logged? email = ask("邮箱: ") password = ask("密码: ") do |q| q.echo = false end @client.login(email, password) end |
#play ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/doubanfm/player.rb', line 39 def play Thread.new do player_proc = proc do |waiting| if waiting @client.next_song play_current_song do |wait| player_proc.call(wait) end end end player_proc.call(true) end end |
#skip ⇒ Object
54 55 56 57 |
# File 'lib/doubanfm/player.rb', line 54 def skip @client.next_song kill_player_thread end |
#start ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/doubanfm/player.rb', line 10 def start play loop do cmd = ask("DoubanFM> ", %w{login skip rate unrate quit}) do |q| q.overwrite = true q.readline = true end case cmd when 'login' login when 'skip' skip when 'rate' say('请先登录') unless @client.user_logged? @client.rate when 'unrate' say('请先登录') unless @client.user_logged? @client.unrate when 'quit' kill_player_thread break else say('Nothing to do') end end end |