lastfm12 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +3 -0
- data/Manifest.txt +2 -0
- data/PostInstall.txt +0 -3
- data/README.rdoc +6 -6
- data/lib/lastfm12.rb +43 -17
- data/lib/lastfm12/version.rb +1 -1
- data/sample/more_simple_play.rb +26 -0
- data/sample/play.rb +36 -0
- data/website/index.html +2 -2
- data/website/index.txt +1 -1
- metadata +34 -16
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/PostInstall.txt
CHANGED
data/README.rdoc
CHANGED
|
@@ -4,29 +4,29 @@
|
|
|
4
4
|
|
|
5
5
|
== DESCRIPTION:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
* lastfm12 is a wrapper around the Last.fm protocol version 1.2. This library can manipulate last.fm radio streams. So, you can implement easily a last.fm radio.
|
|
8
8
|
|
|
9
9
|
== FEATURES/PROBLEMS:
|
|
10
10
|
|
|
11
|
-
*
|
|
11
|
+
* foo
|
|
12
12
|
|
|
13
13
|
== SYNOPSIS:
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
|
|
17
17
|
== REQUIREMENTS:
|
|
18
18
|
|
|
19
|
-
*
|
|
19
|
+
* rubygems
|
|
20
20
|
|
|
21
21
|
== INSTALL:
|
|
22
22
|
|
|
23
|
-
*
|
|
23
|
+
* sudo gem install lastfm12
|
|
24
24
|
|
|
25
25
|
== LICENSE:
|
|
26
26
|
|
|
27
27
|
(The MIT License)
|
|
28
28
|
|
|
29
|
-
Copyright (c) 2008
|
|
29
|
+
Copyright (c) 2008 Keiichiro Ui
|
|
30
30
|
|
|
31
31
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
32
32
|
a copy of this software and associated documentation files (the
|
data/lib/lastfm12.rb
CHANGED
|
@@ -85,7 +85,6 @@ class LastFM12
|
|
|
85
85
|
#:user_agent or "user_agent":: an string used as an user agent name for handshake, ajusting radio station and playlist requests
|
|
86
86
|
#:station or "staion":: an array of strings such as ["tag","electoro"]. refer _adjust_station_ method
|
|
87
87
|
#:verbose or "verbose":: true: output oparations, false: no output
|
|
88
|
-
|
|
89
88
|
def initialize(username,password,opt=nil)
|
|
90
89
|
|
|
91
90
|
@user_name = username.to_s
|
|
@@ -102,7 +101,7 @@ class LastFM12
|
|
|
102
101
|
when "station", :station
|
|
103
102
|
@station = _make_lastfm_url(*(v.to_a))
|
|
104
103
|
when "verbose", :verbose
|
|
105
|
-
@verbose =
|
|
104
|
+
@verbose = v
|
|
106
105
|
end
|
|
107
106
|
end
|
|
108
107
|
end
|
|
@@ -136,7 +135,7 @@ class LastFM12
|
|
|
136
135
|
station = _make_lastfm_url(param_name, param)
|
|
137
136
|
|
|
138
137
|
if @station == station
|
|
139
|
-
puts "Already Adjusted The Station" if @verbose
|
|
138
|
+
puts "[lastfm12] Already Adjusted The Station" if @verbose
|
|
140
139
|
return station
|
|
141
140
|
else
|
|
142
141
|
@station = station
|
|
@@ -148,7 +147,7 @@ class LastFM12
|
|
|
148
147
|
|
|
149
148
|
#Getting tracks
|
|
150
149
|
#Return a array of tracks.
|
|
151
|
-
#[
|
|
150
|
+
#[_min_num_tracks_] the minimun number of tracks
|
|
152
151
|
#===Note
|
|
153
152
|
#The length of the returned array is vary. So, sometime, _get_tracks_ get no track.
|
|
154
153
|
#Give _min_num_tracks_, if you want to get tracks more than _min_num_tracks_.
|
|
@@ -165,7 +164,8 @@ class LastFM12
|
|
|
165
164
|
|
|
166
165
|
if @verbose
|
|
167
166
|
z = ret.length.zero?
|
|
168
|
-
|
|
167
|
+
o = (ret.length == 1)
|
|
168
|
+
puts "[lastfm12] #{z ? '' : 'Success'} Getting #{z ? 'No' : ret.length } Track#{z and o}s"
|
|
169
169
|
end
|
|
170
170
|
|
|
171
171
|
end
|
|
@@ -178,6 +178,7 @@ class LastFM12
|
|
|
178
178
|
|
|
179
179
|
end
|
|
180
180
|
|
|
181
|
+
|
|
181
182
|
def play_loop(&block)
|
|
182
183
|
|
|
183
184
|
loop do
|
|
@@ -185,7 +186,33 @@ class LastFM12
|
|
|
185
186
|
end
|
|
186
187
|
|
|
187
188
|
end
|
|
188
|
-
|
|
189
|
+
|
|
190
|
+
#More simple API
|
|
191
|
+
#LastFM12.play_loop(_username_, _password_, _opt_, &block)
|
|
192
|
+
# or
|
|
193
|
+
#LastFM12.play_loop(_hash_, &block)
|
|
194
|
+
#
|
|
195
|
+
#[_username_]
|
|
196
|
+
# an account name on last.fm
|
|
197
|
+
#[_password_]
|
|
198
|
+
# an password for the account
|
|
199
|
+
#[_opt_]
|
|
200
|
+
# a hash as Fig.A
|
|
201
|
+
#[_hash_]
|
|
202
|
+
# a hash as Fig.A*
|
|
203
|
+
#
|
|
204
|
+
#===Fig.A
|
|
205
|
+
#_key_:: _value_
|
|
206
|
+
#:user_agent or "user_agent":: an string used as an user agent name for handshake, ajusting radio station and playlist requests
|
|
207
|
+
#:station or "staion":: an array of strings such as ["tag","electoro"]. refer _adjust_station_ method
|
|
208
|
+
#:verbose or "verbose":: true: output oparations, false: no output
|
|
209
|
+
#===Fig.A*
|
|
210
|
+
#_key_:: _value_
|
|
211
|
+
#:user_name or "user_name":: an account name on last.fm
|
|
212
|
+
#:password or "password":: an password for the account
|
|
213
|
+
#:user_agent or "user_agent":: an string used as an user agent name for handshake, ajusting radio station and playlist requests
|
|
214
|
+
#:station or "staion":: an array of strings such as ["tag","electoro"]. refer _adjust_station_ method
|
|
215
|
+
#:verbose or "verbose":: true: output oparations, false: no output
|
|
189
216
|
def LastFM12.play_loop(*args,&block)
|
|
190
217
|
|
|
191
218
|
if args.length == 1 and args[0].kind_of?(Hash)
|
|
@@ -194,6 +221,8 @@ class LastFM12
|
|
|
194
221
|
hash = args[2]
|
|
195
222
|
hash[:user_name] = args[0]
|
|
196
223
|
hash[:password] = args[1]
|
|
224
|
+
else
|
|
225
|
+
raise ArgumentError
|
|
197
226
|
end
|
|
198
227
|
|
|
199
228
|
new_hash = Hash.new
|
|
@@ -203,7 +232,7 @@ class LastFM12
|
|
|
203
232
|
if @@instance.nil? or @@instance.user_name != hash[:user_name]
|
|
204
233
|
@@instance = LastFM12.new(hash[:user_name],hash[:password],hash)
|
|
205
234
|
else
|
|
206
|
-
puts "Skip Handshake" if @@instance.verbose
|
|
235
|
+
puts "[lastfm12] Skip Handshake" if @@instance.verbose
|
|
207
236
|
end
|
|
208
237
|
|
|
209
238
|
@@instance.play_loop(&block)
|
|
@@ -370,9 +399,9 @@ class LastFM12
|
|
|
370
399
|
@base_url = ret['base_url']
|
|
371
400
|
@base_path = ret['base_path']
|
|
372
401
|
if @session.nil? or @base_url.nil? or @base_path.nil?
|
|
373
|
-
raise HandshakeError, "handshake error(session: #{@session}, base_url#{@base_url}, base_path: #{@base_path})"
|
|
402
|
+
raise HandshakeError, "handshake error(session: '#{@session}', base_url: '#{@base_url}', base_path: '#{@base_path}')"
|
|
374
403
|
else
|
|
375
|
-
puts "Success Handshake" if @verbose
|
|
404
|
+
puts "[lastfm12] Success Handshake" if @verbose
|
|
376
405
|
end
|
|
377
406
|
end
|
|
378
407
|
|
|
@@ -402,7 +431,7 @@ class LastFM12
|
|
|
402
431
|
if ret['response'] == 'FAILED'
|
|
403
432
|
raise AdjustingError, AdjustingError::Messages[ret['error'].to_i-1]
|
|
404
433
|
else
|
|
405
|
-
puts "Success Adjusting #{ret[%[stationname]]} Station" if @verbose
|
|
434
|
+
puts "[lastfm12] Success Adjusting #{ret[%[stationname]]} Station" if @verbose
|
|
406
435
|
end
|
|
407
436
|
end
|
|
408
437
|
|
|
@@ -432,7 +461,7 @@ class LastFM12
|
|
|
432
461
|
xspf = REXML::Document.new(res.body)
|
|
433
462
|
station = xspf.elements['/playlist/title']
|
|
434
463
|
if station.nil? or station.text.nil?
|
|
435
|
-
puts "Failure of Getting the Playlist Title" if @verbose
|
|
464
|
+
puts "[lastfm12] Failure of Getting the Playlist Title" if @verbose
|
|
436
465
|
return []
|
|
437
466
|
end
|
|
438
467
|
|
|
@@ -447,6 +476,7 @@ class LastFM12
|
|
|
447
476
|
tr[:user_agent] = @user_agent
|
|
448
477
|
tracks << Track.new(tr)
|
|
449
478
|
end
|
|
479
|
+
|
|
450
480
|
end # End of "Net::HTTP.new(@base_url).request_get(..."
|
|
451
481
|
|
|
452
482
|
tracks
|
|
@@ -479,13 +509,9 @@ class LastFM12
|
|
|
479
509
|
tmp % ["user", "#{param}/neighbours"]
|
|
480
510
|
when :recommended
|
|
481
511
|
tmp % ["user", "#{param}/recommended/100"]
|
|
512
|
+
else
|
|
513
|
+
raise ArgumentError, "unknown 1st argment (#{param_name.to_s})"
|
|
482
514
|
end
|
|
483
515
|
end
|
|
484
516
|
|
|
485
517
|
end
|
|
486
|
-
|
|
487
|
-
if $0 == __FILE__
|
|
488
|
-
Lastfm12.new("daftbeats","iamcrz4b",:station => ["tag","bossa"]).get_tracks.each do |tr|
|
|
489
|
-
puts tr
|
|
490
|
-
end
|
|
491
|
-
end
|
data/lib/lastfm12/version.rb
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!ruby
|
|
2
|
+
#
|
|
3
|
+
# more simple example with mpg123
|
|
4
|
+
# play similar tracks to Queen
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
user_name = "lastfm_user_name"
|
|
8
|
+
password = "lastfm_password"
|
|
9
|
+
|
|
10
|
+
require "rubygems"
|
|
11
|
+
require "lastfm12"
|
|
12
|
+
|
|
13
|
+
LastFM12.play_loop(
|
|
14
|
+
"user_name" => user_name,
|
|
15
|
+
"password" => password,
|
|
16
|
+
"user_agent"=> "lastfm12_sample",
|
|
17
|
+
"station" => ["artist", "Queen"],
|
|
18
|
+
"verbose"=> true
|
|
19
|
+
) do |track|
|
|
20
|
+
puts "-------------------------------------------"
|
|
21
|
+
puts "artist: #{track.artist}"
|
|
22
|
+
puts "title: #{track.title}"
|
|
23
|
+
puts "album: #{track.album}"
|
|
24
|
+
puts "length: #{track.length/1000}[sec]"
|
|
25
|
+
`mpg123 -b 1024 #{track.location}`
|
|
26
|
+
end
|
data/sample/play.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!ruby
|
|
2
|
+
#
|
|
3
|
+
# basic example with mpg123
|
|
4
|
+
# play similar tracks to Queen
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
user_name = "lastfm_user_name"
|
|
8
|
+
password = "lastfm_password"
|
|
9
|
+
|
|
10
|
+
require "rubygems"
|
|
11
|
+
require "lastfm12"
|
|
12
|
+
|
|
13
|
+
opt = {
|
|
14
|
+
#"user_agent": "lastfm12_sample", # user-agent
|
|
15
|
+
#"verbose": true # verbose output
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
# handshake
|
|
19
|
+
lastfm = LastFM12.new(user_name,password, opt)
|
|
20
|
+
puts "Success Handshake"
|
|
21
|
+
|
|
22
|
+
lastfm.adjust_station("artist", "Queen")
|
|
23
|
+
puts "Success Adjusting Station(#{lastfm.station})"
|
|
24
|
+
|
|
25
|
+
loop do
|
|
26
|
+
tracks = lastfm.get_tracks
|
|
27
|
+
puts "*** Got #{tracks.length} track#{tracks.length==1 ? nil : 's'}"
|
|
28
|
+
tracks.each do |track|
|
|
29
|
+
puts "-------------------------------------------"
|
|
30
|
+
puts "artist: #{track.artist}"
|
|
31
|
+
puts "title: #{track.title}"
|
|
32
|
+
puts "album: #{track.album}"
|
|
33
|
+
puts "length: #{track.length/1000}[sec]"
|
|
34
|
+
`mpg123 -b 1024 #{track.location}`
|
|
35
|
+
end
|
|
36
|
+
end
|
data/website/index.html
CHANGED
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
<h1>lastfm12</h1>
|
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/lastfm12"; return false'>
|
|
35
35
|
<p>Get Version</p>
|
|
36
|
-
<a href="http://rubyforge.org/projects/lastfm12" class="numbers">0.0.
|
|
36
|
+
<a href="http://rubyforge.org/projects/lastfm12" class="numbers">0.0.2</a>
|
|
37
37
|
</div>
|
|
38
38
|
<h2>What</h2>
|
|
39
|
-
<p>lastfm12 is a wrapper around the Last.fm protocol version 1.2. This library can manipulate the last.fm radio streams. So, you can implement easily
|
|
39
|
+
<p>lastfm12 is a wrapper around the Last.fm protocol version 1.2. This library can manipulate the last.fm radio streams. So, you can implement easily a last.fm radio.</p>
|
|
40
40
|
<h2>Installing</h2>
|
|
41
41
|
<p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">lastfm12</span></pre></p>
|
|
42
42
|
<h2>Demonstration of usage</h2>
|
data/website/index.txt
CHANGED
|
@@ -2,7 +2,7 @@ h1. lastfm12
|
|
|
2
2
|
|
|
3
3
|
h2. What
|
|
4
4
|
|
|
5
|
-
lastfm12 is a wrapper around the Last.fm protocol version 1.2. This library can manipulate the last.fm radio streams. So, you can implement easily
|
|
5
|
+
lastfm12 is a wrapper around the Last.fm protocol version 1.2. This library can manipulate the last.fm radio streams. So, you can implement easily a last.fm radio.
|
|
6
6
|
|
|
7
7
|
h2. Installing
|
|
8
8
|
|
metadata
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lastfm12
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
4
|
+
hash: 27
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 2
|
|
10
|
+
version: 0.0.2
|
|
5
11
|
platform: ruby
|
|
6
12
|
authors:
|
|
7
13
|
- Keiichiro Ui
|
|
@@ -9,19 +15,25 @@ autorequire:
|
|
|
9
15
|
bindir: bin
|
|
10
16
|
cert_chain: []
|
|
11
17
|
|
|
12
|
-
date:
|
|
18
|
+
date: 2010-07-22 00:00:00 +09:00
|
|
13
19
|
default_executable:
|
|
14
20
|
dependencies:
|
|
15
21
|
- !ruby/object:Gem::Dependency
|
|
16
22
|
name: hoe
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
prerelease: false
|
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
20
26
|
requirements:
|
|
21
27
|
- - ">="
|
|
22
28
|
- !ruby/object:Gem::Version
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
hash: 21
|
|
30
|
+
segments:
|
|
31
|
+
- 2
|
|
32
|
+
- 6
|
|
33
|
+
- 1
|
|
34
|
+
version: 2.6.1
|
|
35
|
+
type: :development
|
|
36
|
+
version_requirements: *id001
|
|
25
37
|
description: lastfm12 is a wrapper around the Last.fm protocol version 1.2. This library can manipulate the last.fm radio streams. So, you can implement easily the last.fm radio.
|
|
26
38
|
email:
|
|
27
39
|
- keiichiro.ui@gmail.com
|
|
@@ -33,7 +45,6 @@ extra_rdoc_files:
|
|
|
33
45
|
- History.txt
|
|
34
46
|
- Manifest.txt
|
|
35
47
|
- PostInstall.txt
|
|
36
|
-
- README.rdoc
|
|
37
48
|
- website/index.txt
|
|
38
49
|
files:
|
|
39
50
|
- History.txt
|
|
@@ -45,6 +56,8 @@ files:
|
|
|
45
56
|
- config/requirements.rb
|
|
46
57
|
- lib/lastfm12.rb
|
|
47
58
|
- lib/lastfm12/version.rb
|
|
59
|
+
- sample/play.rb
|
|
60
|
+
- sample/more_simple_play.rb
|
|
48
61
|
- script/console
|
|
49
62
|
- script/destroy
|
|
50
63
|
- script/generate
|
|
@@ -62,37 +75,42 @@ files:
|
|
|
62
75
|
- website/template.html.erb
|
|
63
76
|
has_rdoc: true
|
|
64
77
|
homepage: http://lastfm12.rubyforge.org
|
|
78
|
+
licenses: []
|
|
79
|
+
|
|
65
80
|
post_install_message: |+
|
|
66
81
|
|
|
67
82
|
For more information on lastfm12, see http://lastfm12.rubyforge.org
|
|
68
83
|
|
|
69
|
-
NOTE: Change this information in PostInstall.txt
|
|
70
|
-
You can also delete it if you don't want it.
|
|
71
|
-
|
|
72
84
|
|
|
73
85
|
rdoc_options:
|
|
74
86
|
- --main
|
|
75
|
-
- README.
|
|
87
|
+
- README.txt
|
|
76
88
|
require_paths:
|
|
77
89
|
- lib
|
|
78
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
|
+
none: false
|
|
79
92
|
requirements:
|
|
80
93
|
- - ">="
|
|
81
94
|
- !ruby/object:Gem::Version
|
|
95
|
+
hash: 3
|
|
96
|
+
segments:
|
|
97
|
+
- 0
|
|
82
98
|
version: "0"
|
|
83
|
-
version:
|
|
84
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
|
+
none: false
|
|
85
101
|
requirements:
|
|
86
102
|
- - ">="
|
|
87
103
|
- !ruby/object:Gem::Version
|
|
104
|
+
hash: 3
|
|
105
|
+
segments:
|
|
106
|
+
- 0
|
|
88
107
|
version: "0"
|
|
89
|
-
version:
|
|
90
108
|
requirements: []
|
|
91
109
|
|
|
92
110
|
rubyforge_project: lastfm12
|
|
93
|
-
rubygems_version: 1.
|
|
111
|
+
rubygems_version: 1.3.7
|
|
94
112
|
signing_key:
|
|
95
|
-
specification_version:
|
|
113
|
+
specification_version: 3
|
|
96
114
|
summary: lastfm12 is a wrapper around the Last.fm protocol version 1.2. This library can manipulate the last.fm radio streams. So, you can implement easily the last.fm radio.
|
|
97
115
|
test_files:
|
|
98
116
|
- test/test_helper.rb
|