lastfm-top 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/COPYING +1 -1
  2. data/bin/lastfm-top +46 -30
  3. metadata +13 -2
data/COPYING CHANGED
@@ -1,7 +1,7 @@
1
1
  DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
2
  Version 2, December 2004
3
3
 
4
- Copyright (C) 2011 James Pearson
4
+ Copyright (C) 2012 James Pearson
5
5
 
6
6
  Everyone is permitted to copy and distribute verbatim or modified
7
7
  copies of this license document, and changing it is allowed as long
@@ -4,6 +4,7 @@
4
4
  # May you share freely, never taking more than you give.
5
5
  # May you find love and love everyone you find.
6
6
 
7
+ require 'englify'
7
8
  require 'json'
8
9
  require 'net/http'
9
10
  require 'optparse'
@@ -15,37 +16,49 @@ API_KEY = 'c7089003368bef3c8d0dd12ceede4978'
15
16
  period = 'overall'
16
17
  statistic = 'artists'
17
18
  limit = 10
19
+ autoTranslate = true
18
20
 
19
- OptionParser.new do |opts|
20
- opts.banner = "Usage: #{$0.split('/').last} [options] [USER]"
21
-
22
- opts.on('-l', '--limit NUM', Integer, 'Number of artists to show. '\
23
- +'0 is all. Defaults to 10.') do |num|
24
- # We should actually restrict the range a bit. Using a really, really
25
- # big number causes the API to return no tracks at all.
26
- limit = num
27
- end
28
-
29
- opts.on('-p', '--period PERIOD', PERIOD_OPTIONS,
30
- "Time period to show. Choices: #{PERIOD_OPTIONS.join(',')}") do |p|
31
- period = p
32
- end
33
-
34
- opts.on('-s', '--statistic STATISTIC', STAT_OPTIONS,
35
- "Statistic to show. Choices: #{STAT_OPTIONS.join(',')}") do |s|
36
- statistic = s
37
- end
38
-
39
- opts.on('-v', '--version', 'Show the installed version of lastfm-top.') do
40
- puts 'lastfm-top 0.1.0'
41
- exit 0
42
- end
43
-
44
- opts.on_tail('-h', '--help', 'Show this help dialog.') do
45
- puts opts
46
- exit 0
47
- end
48
- end.parse!
21
+ begin
22
+ OptionParser.new do |opts|
23
+ opts.banner = "Usage: #{$0.split('/').last} [options] [USER]"
24
+
25
+ opts.on('-l', '--limit NUM', Integer, 'Number of artists to show. '\
26
+ +'0 is all. Defaults to 10.') do |num|
27
+ # We should actually restrict the range a bit. Using a really, really
28
+ # big number causes the API to return no tracks at all.
29
+ limit = num
30
+ end
31
+
32
+ opts.on('--no-translate', "Don't auto-translate foreign artist names.") do
33
+ autoTranslate = false
34
+ end
35
+
36
+ opts.on('-p', '--period PERIOD', PERIOD_OPTIONS,
37
+ "Time period to show. Choices: #{PERIOD_OPTIONS.join(',')}") do |p|
38
+ period = p
39
+ end
40
+
41
+ opts.on('-s', '--statistic STATISTIC', STAT_OPTIONS,
42
+ "Statistic to show. Choices: #{STAT_OPTIONS.join(',')}") do |s|
43
+ statistic = s
44
+ end
45
+
46
+ opts.on('-v', '--version', 'Show the installed version of lastfm-top.') do
47
+ puts 'lastfm-top 0.2.0'
48
+ exit 0
49
+ end
50
+
51
+ opts.on_tail('-h', '--help', 'Show this help dialog.') do
52
+ puts opts
53
+ exit 0
54
+ end
55
+ end.parse!
56
+ rescue OptionParser::InvalidArgument,
57
+ OptionParser::InvalidOption,
58
+ OptionParser::MissingArgument => e
59
+ puts e
60
+ exit 255
61
+ end
49
62
 
50
63
  user = ARGV[-1] || 'xiongchiamiov'
51
64
 
@@ -60,6 +73,9 @@ end
60
73
 
61
74
  stats = results["top#{statistic}"][statistic.chop] # Chop off the 's'
62
75
  stats.each do |stat|
76
+ if autoTranslate && !stat['name'].ascii_only?
77
+ stat['name'] = englify(stat['name'])
78
+ end
63
79
  # This could look a lot nicer. There's also some additional information
64
80
  # available that differs depending on the statistic we're looking at.
65
81
  puts "#{stat['name']} - #{stat['playcount']}"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: lastfm-top
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - xiongchiamiov
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-03-11 00:00:00 -08:00
13
+ date: 2012-08-26 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -24,6 +24,17 @@ dependencies:
24
24
  version: "0"
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: englify
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
27
38
  description: A small script to view top artists, albums and tracks of a Last.fm user.
28
39
  email:
29
40
  - xiong.chiamiov@gmail.com