lily 0.1.32 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -4
- data/lib/lily.rb +165 -29
- data/lib/lily/version.rb +2 -2
- 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: 75b97ec581e49684c65d5359805346373829b643
|
4
|
+
data.tar.gz: b1356a98ccbc565653a07995256cf89d4539192e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5a5f107c4cff6e69ce9e619ace0b9bdc2b2f30af266873f2bb4ef8863cd7b11abd83fe40fcf0db7509ed501e25819b9f357ba93f49aab71f8a56c68d0a80fbb
|
7
|
+
data.tar.gz: 5ef72f04e4f2169f68cf1d2112875fb2d06aaa324c278932fc131e794572d5c362db74702395d370afc6e493a348179ac2a3164514caf01424058d30aa502b27
|
data/README.md
CHANGED
@@ -19,10 +19,10 @@ lily init # Initialize :)
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
-
What's a CLI without usage docs? A bad one. Below you'll find out how Lily can be used. Keep in mind, you can reference every command Lily has with `lily help`
|
22
|
+
What's a CLI without usage docs? A bad one. Below you'll find out how Lily can be used. Keep in mind, you can reference every command Lily has with `lily help`. You can find out what version of Lily you are running with `lily version` or `lily --version`.
|
23
23
|
|
24
|
-
### Initializing
|
25
|
-
Initializing Lily is very easy. Just run `lily init`, log in with LastFM, and you're set.
|
24
|
+
### Initializing and Resetting
|
25
|
+
Initializing Lily is very easy. Just run `lily init`, log in with LastFM, and you're set. There may be cases where a URL cannot be opened natively, in that case, run `lily init --no-open` and you can open the URL manually, which will work the same way. If you are having trouble, or want to move to a new account, just run `lily reset` to start over and re-initialize with `lily init` as usual.
|
26
26
|
|
27
27
|
### Scrobbling
|
28
28
|
Lily's scrobbling feature is very useful, particularly for scrobbling things that can't be scrobbled automatically. For example, when you listen to a vinyl, a CD, that song you really like on the radio, or just something that bugged out and didn't scrobble. Here's how you do that:
|
@@ -36,7 +36,6 @@ Lily can simply and easily scrobble any individual song for you, assuming you ju
|
|
36
36
|
|
37
37
|
```bash
|
38
38
|
lily scrobble song "Here Comes the Sun" "The Beatles" # scrobbles Here Comes the Sun from Abbey Road, the most popular album it is on
|
39
|
-
|
40
39
|
lily scrobble song "Here Comes the Sun" "The Beatles" "The Beatles Ballads" # if you're a hipster, you can optionally specify the exact album you're listening to the song on
|
41
40
|
```
|
42
41
|
|
@@ -67,4 +66,26 @@ lily unlove album "The Beatles" "Abbey Road"
|
|
67
66
|
|
68
67
|
lily love song "Here Comes the Sun" "The Beatles" "The Beatles Ballads"
|
69
68
|
lily unlove song "Here Comes the Sun" "The Beatles"
|
69
|
+
```
|
70
|
+
|
71
|
+
### Information
|
72
|
+
Lily can give you information on users, albums, and songs.
|
73
|
+
|
74
|
+
**Syntax for songs:** `lily info song (<song> <artist>) [<album>]`
|
75
|
+
|
76
|
+
**Syntax for albums:** `lily info album (<album> <artist> | <eponymous album>)`
|
77
|
+
|
78
|
+
**Syntax for users:** `lily info user <username>`
|
79
|
+
|
80
|
+
**Examples:**
|
81
|
+
|
82
|
+
```bash
|
83
|
+
lily info song "Here Comes the Sun" "The Beatles"
|
84
|
+
lily info song "Here Comes the Sun" "The Beatles" "The Beatles Ballads"
|
85
|
+
|
86
|
+
lily info album "The Beatles"
|
87
|
+
lily info album "The Beatles" "The White Album"
|
88
|
+
|
89
|
+
lily info user "soodologica"
|
90
|
+
lily info user "jshtrmml"
|
70
91
|
```
|
data/lib/lily.rb
CHANGED
@@ -25,7 +25,7 @@ class Lily
|
|
25
25
|
|
26
26
|
# returns {sk, signature}
|
27
27
|
rescue
|
28
|
-
puts "~/.lily.json appears empty"
|
28
|
+
puts "Your settings file (~/.lily.json) appears to be empty, please initialize Lily."
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -51,7 +51,7 @@ class Lily
|
|
51
51
|
begin
|
52
52
|
res.album
|
53
53
|
rescue
|
54
|
-
puts "
|
54
|
+
puts "That album does not exist."
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -62,12 +62,22 @@ class Lily
|
|
62
62
|
res.token
|
63
63
|
end
|
64
64
|
|
65
|
-
def auth
|
65
|
+
def auth(cmd)
|
66
66
|
lastfmURL = "http://www.last.fm/api/auth/?api_key=#{@keys.public}&token=#{@token}"
|
67
|
+
|
68
|
+
if cmd == "--no-open" then puts "Open this URL and sign in to give access: #{lastfmURL}" else
|
69
|
+
Launchy.open(lastfmURL)
|
70
|
+
end
|
71
|
+
|
67
72
|
print "Press Enter once you've given access..."
|
68
|
-
Launchy.open(lastfmURL)
|
69
73
|
STDIN.gets
|
70
74
|
end
|
75
|
+
|
76
|
+
def reset
|
77
|
+
# reset sk and config stuff
|
78
|
+
File.delete(ENV["HOME"] + "/.lily.json")
|
79
|
+
puts "Lily has been reset, please re-initialize."
|
80
|
+
end
|
71
81
|
|
72
82
|
def session_key
|
73
83
|
sig = Digest::MD5.hexdigest("api_key#{@keys.public}methodauth.getSessiontoken#{@token}#{@keys.private}")
|
@@ -79,6 +89,119 @@ class Lily
|
|
79
89
|
file.write(JSON.pretty_generate({"session_key" => sk}))
|
80
90
|
end
|
81
91
|
end
|
92
|
+
|
93
|
+
def get_dashes(string)
|
94
|
+
# create dashes for cosmetic reasons
|
95
|
+
string_array = string.split("")
|
96
|
+
dashes = ""
|
97
|
+
|
98
|
+
string_array.each do
|
99
|
+
dashes += "-"
|
100
|
+
end
|
101
|
+
|
102
|
+
return dashes
|
103
|
+
end
|
104
|
+
|
105
|
+
def tags(toptags)
|
106
|
+
tags = ""
|
107
|
+
|
108
|
+
toptags.tag.each do |i|
|
109
|
+
if i != toptags.tag[-1]
|
110
|
+
tags += i.name + ", "
|
111
|
+
elsif
|
112
|
+
tags += i.name
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
tags
|
117
|
+
end
|
118
|
+
|
119
|
+
def info
|
120
|
+
# http://www.last.fm/api/show/user.getInfo
|
121
|
+
command = @args.shift
|
122
|
+
|
123
|
+
if command == "user"
|
124
|
+
# user profile
|
125
|
+
username = @args[0]
|
126
|
+
info_url = "http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user=" + username + "&api_key=" + @keys.public + "&format=json"
|
127
|
+
top_artists_url = "http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=" + username + "&api_key=" + @keys.public + "&format=json"
|
128
|
+
recent_tracks_url = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=" + username + "&api_key=" + @keys.public + "&format=json"
|
129
|
+
|
130
|
+
# get profile
|
131
|
+
info = JSON.parse(HTTP.get(info_url))
|
132
|
+
top_artists = JSON.parse(HTTP.get(top_artists_url))
|
133
|
+
recent_tracks = JSON.parse(HTTP.get(recent_tracks_url))
|
134
|
+
|
135
|
+
# create dashes for cosmetic reasons
|
136
|
+
dashes = get_dashes(username)
|
137
|
+
|
138
|
+
# figure out what to show
|
139
|
+
information = [username, "#{dashes}\n\n", "profile link: #{info.user.url}", "songs played: #{info.user.playcount}", "top artist: #{top_artists.topartists.artist[0].name}, with #{top_artists.topartists.artist[0].playcount} total plays", "most recent track: #{recent_tracks.recenttracks.track[0].name} by #{recent_tracks.recenttracks.track[0].artist['#text']}"]
|
140
|
+
|
141
|
+
if info.user.age != "0" then information.push("age: #{info.user.age}") end
|
142
|
+
if info.user.country != "" then information.push("country: #{info.user.country}") end
|
143
|
+
|
144
|
+
information.each do |i|
|
145
|
+
puts i
|
146
|
+
end
|
147
|
+
elsif command == "album"
|
148
|
+
# album info
|
149
|
+
|
150
|
+
# we got eponymous albums covered :)
|
151
|
+
if @args[1] == nil then album, artist = @args[0], @args[0] else album, artist = @args[0], @args[1] end
|
152
|
+
|
153
|
+
album_info = get_album_info(album, artist)
|
154
|
+
|
155
|
+
# dashes for cosmetic reasons
|
156
|
+
title = album + " by " + artist
|
157
|
+
dashes = get_dashes(title)
|
158
|
+
|
159
|
+
# figure out what to show
|
160
|
+
information = [title, "#{dashes}\n\n", "album link: #{album_info.url}", "played #{album_info.playcount} times by a total of #{album_info.listeners} listeners"]
|
161
|
+
|
162
|
+
begin
|
163
|
+
if album_info.tags != [] then information.push("tags: #{tags(album_info.tags)}") end
|
164
|
+
if album_info.wiki.summary != "" then information.push("\nsummary:\n#{album_info.wiki.summary}") end
|
165
|
+
rescue
|
166
|
+
# puts "error"
|
167
|
+
end
|
168
|
+
|
169
|
+
information.each do |i|
|
170
|
+
puts i
|
171
|
+
end
|
172
|
+
elsif command == "song"
|
173
|
+
# song info
|
174
|
+
track, artist = @args[0], @args[1]
|
175
|
+
|
176
|
+
url = "http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=" + @keys.public + "&artist=" + artist + "&track=" + track + "&format=json"
|
177
|
+
if @args[2]
|
178
|
+
album = @args[2]
|
179
|
+
url += "&album=#{album}"
|
180
|
+
end # album name is optional
|
181
|
+
|
182
|
+
song_info = JSON.parse(HTTP.get(url))["track"]
|
183
|
+
|
184
|
+
# dashes for cosmetic reasons
|
185
|
+
title = track + " by " + artist + " from the album " + song_info.album.title
|
186
|
+
dashes = get_dashes(title)
|
187
|
+
|
188
|
+
# figure out what to show
|
189
|
+
information = [title, "#{dashes}\n\n", "song link: #{song_info.url}", "played #{song_info.playcount} times by a total of #{song_info.listeners} listeners"]
|
190
|
+
|
191
|
+
begin
|
192
|
+
if song_info.toptags != [] then information.push("top tags: #{tags(song_info.toptags)}") end
|
193
|
+
if song_info.wiki.summary != "" then information.push("\nsummary:\n#{song_info.wiki.summary}") end
|
194
|
+
rescue
|
195
|
+
# nothing to see here!
|
196
|
+
end
|
197
|
+
|
198
|
+
information.each do |i|
|
199
|
+
puts i
|
200
|
+
end
|
201
|
+
else
|
202
|
+
puts "Huh, Lily didn't recognize that."
|
203
|
+
end
|
204
|
+
end
|
82
205
|
|
83
206
|
def scrobble
|
84
207
|
# last.fm/api/show/track.scrobble
|
@@ -115,8 +238,8 @@ class Lily
|
|
115
238
|
album_length = 0
|
116
239
|
|
117
240
|
# get full length of album in seconds
|
118
|
-
album_info.tracks.track.each do |
|
119
|
-
album_length +=
|
241
|
+
album_info.tracks.track.each do |i|
|
242
|
+
album_length += i.duration.to_i
|
120
243
|
end
|
121
244
|
|
122
245
|
puts "Whole album length: #{album_length} seconds."
|
@@ -127,16 +250,16 @@ class Lily
|
|
127
250
|
puts "Scrobbling your album starting at " + Time.at(time).utc.strftime("%I:%M:%S %p") + " UTC"
|
128
251
|
|
129
252
|
# begin scrobbling
|
130
|
-
album_info.tracks.track.each do |
|
131
|
-
time +=
|
253
|
+
album_info.tracks.track.each do |i|
|
254
|
+
time += i.duration.to_i
|
132
255
|
|
133
256
|
# scrobble track
|
134
257
|
body = self.format_params({
|
135
|
-
"artist" =>
|
258
|
+
"artist" => i.artist.name,
|
136
259
|
"method" => "track.scrobble",
|
137
260
|
"sk" => @lily_json.session_key,
|
138
261
|
"timestamp" => time,
|
139
|
-
"track" =>
|
262
|
+
"track" => i.name,
|
140
263
|
"api_key" => @keys.public,
|
141
264
|
"format" => "json",
|
142
265
|
"album" => album_info.name
|
@@ -147,7 +270,7 @@ class Lily
|
|
147
270
|
|
148
271
|
puts "#{album} by #{artist} has been scrobbled."
|
149
272
|
else
|
150
|
-
puts "
|
273
|
+
puts "Huh, Lily didn't recognize that."
|
151
274
|
end
|
152
275
|
end
|
153
276
|
|
@@ -177,11 +300,10 @@ class Lily
|
|
177
300
|
if @args[1] == nil then album, artist = @args[0], @args[0] else album, artist = @args[0], @args[1] end
|
178
301
|
|
179
302
|
album_info = get_album_info(album, artist)
|
180
|
-
album_length = 0
|
181
303
|
|
182
|
-
album_info.tracks.track.each do |
|
304
|
+
album_info.tracks.track.each do |i|
|
183
305
|
body = self.format_params({
|
184
|
-
"track" =>
|
306
|
+
"track" => i.name,
|
185
307
|
"artist" => artist,
|
186
308
|
"method" => "track.love",
|
187
309
|
"sk" => @lily_json.session_key,
|
@@ -195,7 +317,7 @@ class Lily
|
|
195
317
|
|
196
318
|
puts "#{album} by #{artist} has been loved ♥"
|
197
319
|
else
|
198
|
-
puts "
|
320
|
+
puts "Huh, Lily didn't recognize that."
|
199
321
|
end
|
200
322
|
end
|
201
323
|
|
@@ -225,9 +347,8 @@ class Lily
|
|
225
347
|
if @args[1] == nil then album, artist = @args[0], @args[0] else album, artist = @args[0], @args[1] end
|
226
348
|
|
227
349
|
album_info = get_album_info(album, artist)
|
228
|
-
album_length = 0
|
229
350
|
|
230
|
-
album_info.tracks.track.each do |
|
351
|
+
album_info.tracks.track.each do |i|
|
231
352
|
body = self.format_params({
|
232
353
|
"track" => track.name,
|
233
354
|
"artist" => artist,
|
@@ -243,7 +364,7 @@ class Lily
|
|
243
364
|
|
244
365
|
puts "#{album} by #{artist} has been unloved :("
|
245
366
|
else
|
246
|
-
puts "
|
367
|
+
puts "Huh, Lily didn't recognize that."
|
247
368
|
end
|
248
369
|
end
|
249
370
|
|
@@ -251,12 +372,14 @@ class Lily
|
|
251
372
|
first = @args.shift
|
252
373
|
|
253
374
|
case first
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
375
|
+
when 'scrobble' then self.scrobble
|
376
|
+
when 'init' then self.init
|
377
|
+
when 'love' then self.love
|
378
|
+
when 'unlove' then self.unlove
|
379
|
+
when 'version', '--version' then puts self.version
|
380
|
+
when 'info' then self.info
|
381
|
+
when 'reset' then self.reset
|
382
|
+
else self.help
|
260
383
|
end
|
261
384
|
end
|
262
385
|
|
@@ -265,18 +388,31 @@ class Lily
|
|
265
388
|
Lily, the Last.fm CLI.
|
266
389
|
|
267
390
|
Usage:
|
268
|
-
|
391
|
+
General Commands:
|
392
|
+
lily init [--no-open]
|
269
393
|
lily help
|
270
|
-
lily
|
271
|
-
lily (
|
394
|
+
lily reset
|
395
|
+
lily (version | --version)
|
396
|
+
|
397
|
+
Scrobbling:
|
398
|
+
lily scrobble song (<song> <artist>) [<album>]
|
272
399
|
lily scrobble album (<album> <artist> | <eponymous album>) [--live]
|
400
|
+
|
401
|
+
Loving/Unloving:
|
402
|
+
lily (love | unlove) song (<song> <artist>) [<album>]
|
403
|
+
lily (love | unlove) album (<album> <artist> | <eponymous album>)
|
404
|
+
|
405
|
+
Information:
|
406
|
+
lily info song (<song> <artist>) [<album>]
|
407
|
+
lily info album (<album> <artist> | <eponymous album>)
|
408
|
+
lily info user <username>
|
273
409
|
"""
|
274
410
|
end
|
275
411
|
|
276
412
|
def init
|
277
|
-
auth
|
413
|
+
auth(@args[-1])
|
278
414
|
session_key
|
279
|
-
puts "Initialized ~/.lily.json
|
415
|
+
puts "Initialized Lily successfully at file ~/.lily.json"
|
280
416
|
end
|
281
417
|
|
282
418
|
def version
|
data/lib/lily/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lily
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Trommel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-04-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|