doubanfm 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -2
- data/lib/doubanfm/doubanfm.rb +65 -5
- data/lib/doubanfm/player.rb +13 -5
- data/lib/doubanfm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 018dd831b6f7ca1807a4e81723a90243353bb69d
|
4
|
+
data.tar.gz: f817d7eceae4da6b6cd386f99235757f7ba316e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84ffd7bc2aa7cc3e0739e07f11ff6404a53c96b989edeb1a53f13409a837872f2239abaeeb76dc16e8be0bf721437efcfa3a9e403d8fcaec750f3e1021c4ad78
|
7
|
+
data.tar.gz: 8e26dd2c80f2c69a77fbd44607bc1288d3d6f556636a0efe5913db92d6b116989fedee951c8fbbbebdc36834b68a6d49b15b031d1b031bcaa372b56cf0c62df1
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Doubanfm
|
2
2
|
|
3
|
-
|
3
|
+
Just another DoubanFM client.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,17 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
$ doubanfm
|
22
|
+
You can use \<Tab\> to list all valid command.
|
23
|
+
|
24
|
+
## Todo
|
25
|
+
|
26
|
+
- [ ] Allow user to throw a song into trash bin
|
27
|
+
- [ ] Allow user to select specific channel
|
28
|
+
- [ ] Introduce a better console interface with `curses` or something similar
|
29
|
+
- [ ] Refactor all
|
30
|
+
- [ ] Use a audio play gem to replace `mpg123` program
|
31
|
+
- [ ] Maybe I'll use JRuby and SWT to implement GUI
|
22
32
|
|
23
33
|
## Contributing
|
24
34
|
|
data/lib/doubanfm/doubanfm.rb
CHANGED
@@ -47,13 +47,10 @@ module DoubanFM
|
|
47
47
|
return true
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
51
|
-
|
50
|
+
def set_channel(channel_id)
|
51
|
+
@current_channel = channel_id
|
52
52
|
end
|
53
53
|
|
54
|
-
def next_playlist
|
55
|
-
fetch_playlist(NEXT_PLAYLIST)
|
56
|
-
end
|
57
54
|
|
58
55
|
def next_song
|
59
56
|
if @current_song == @playlist.last
|
@@ -64,6 +61,56 @@ module DoubanFM
|
|
64
61
|
@current_song = @playlist[next_song_pos]
|
65
62
|
end
|
66
63
|
|
64
|
+
def rate
|
65
|
+
return unless user_logged?
|
66
|
+
return if like?
|
67
|
+
|
68
|
+
params = {
|
69
|
+
app_name: APP_NAME,
|
70
|
+
version: APP_VERSION,
|
71
|
+
user_id: @user_info[:user_id],
|
72
|
+
expire: @user_info[:expire],
|
73
|
+
token: @user_info[:token],
|
74
|
+
channel: @current_channel,
|
75
|
+
sid: @current_song[:sid],
|
76
|
+
type: RATE
|
77
|
+
}
|
78
|
+
|
79
|
+
rate_uri = URI('http://www.douban.com/j/app/radio/people')
|
80
|
+
rate_uri.query = URI.encode_www_form(params)
|
81
|
+
|
82
|
+
@playlist = JSON.parse(
|
83
|
+
@client.get(rate_uri),
|
84
|
+
symbolize_names: true
|
85
|
+
)[:song]
|
86
|
+
@current_song = @playlist.first
|
87
|
+
end
|
88
|
+
|
89
|
+
def unrate
|
90
|
+
return unless user_logged?
|
91
|
+
return unless like?
|
92
|
+
|
93
|
+
params = {
|
94
|
+
app_name: APP_NAME,
|
95
|
+
version: APP_VERSION,
|
96
|
+
user_id: @user_info[:user_id],
|
97
|
+
expire: @user_info[:expire],
|
98
|
+
token: @user_info[:token],
|
99
|
+
channel: @current_channel,
|
100
|
+
sid: @current_song[:sid],
|
101
|
+
type: UNRATE
|
102
|
+
}
|
103
|
+
|
104
|
+
rate_uri = URI('http://www.douban.com/j/app/radio/people')
|
105
|
+
rate_uri.query = URI.encode_www_form(params)
|
106
|
+
|
107
|
+
@playlist = JSON.parse(
|
108
|
+
@client.get(rate_uri),
|
109
|
+
symbolize_names: true
|
110
|
+
)[:song]
|
111
|
+
@current_song = @playlist.first
|
112
|
+
end
|
113
|
+
|
67
114
|
private
|
68
115
|
def fetch_channels
|
69
116
|
@channels = JSON.parse(
|
@@ -75,6 +122,7 @@ module DoubanFM
|
|
75
122
|
def fetch_playlist(type)
|
76
123
|
if @current_channel == INVALID_CHANNEL_ID
|
77
124
|
channel_id = select_random_channel
|
125
|
+
@current_channel = channel_id
|
78
126
|
else
|
79
127
|
channel_id = @current_channel
|
80
128
|
end
|
@@ -107,5 +155,17 @@ module DoubanFM
|
|
107
155
|
which = Random.new.rand(first_channel ... @channels.size)
|
108
156
|
@channels[which][:channel_id]
|
109
157
|
end
|
158
|
+
|
159
|
+
def new_playlist
|
160
|
+
fetch_playlist(NEW_PLAYLIST)
|
161
|
+
end
|
162
|
+
|
163
|
+
def next_playlist
|
164
|
+
fetch_playlist(NEXT_PLAYLIST)
|
165
|
+
end
|
166
|
+
|
167
|
+
def like?
|
168
|
+
return @current_song[:like] == 1 ? true : false;
|
169
|
+
end
|
110
170
|
end
|
111
171
|
end
|
data/lib/doubanfm/player.rb
CHANGED
@@ -8,23 +8,30 @@ module DoubanFM
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def start
|
11
|
+
play
|
12
|
+
|
11
13
|
loop do
|
12
|
-
cmd = ask("DoubanFM> ", %w{login
|
14
|
+
cmd = ask("DoubanFM> ", %w{login skip rate unrate quit}) do |q|
|
15
|
+
q.overwrite = true
|
13
16
|
q.readline = true
|
14
17
|
end
|
15
18
|
|
16
19
|
case cmd
|
17
20
|
when 'login'
|
18
21
|
login
|
19
|
-
when 'play'
|
20
|
-
play
|
21
22
|
when 'skip'
|
22
23
|
skip
|
24
|
+
when 'rate'
|
25
|
+
say('请先登录') unless @client.user_logged?
|
26
|
+
@client.rate
|
27
|
+
when 'unrate'
|
28
|
+
say('请先登录') unless @client.user_logged?
|
29
|
+
@client.unrate
|
23
30
|
when 'quit'
|
24
31
|
kill_player_thread
|
25
32
|
break
|
26
33
|
else
|
27
|
-
|
34
|
+
say('Nothing to do')
|
28
35
|
end
|
29
36
|
end
|
30
37
|
end
|
@@ -66,9 +73,10 @@ module DoubanFM
|
|
66
73
|
|
67
74
|
@waiting = false
|
68
75
|
|
76
|
+
say("Playing #{@client.current_song[:title]}")
|
69
77
|
@player_pid = spawn("mpg123 #{@client.current_song[:url]} > /dev/null 2>&1")
|
70
78
|
|
71
|
-
Process.wait
|
79
|
+
Process.wait(@player_pid)
|
72
80
|
@waiting = true
|
73
81
|
|
74
82
|
@semaphore.unlock
|
data/lib/doubanfm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doubanfm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgar Wang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|