lastfm-top 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/COPYING +13 -0
  2. data/README.md +6 -0
  3. data/Rakefile +6 -0
  4. data/bin/lastfm-top +67 -0
  5. metadata +70 -0
data/COPYING ADDED
@@ -0,0 +1,13 @@
1
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
+ Version 2, December 2004
3
+
4
+ Copyright (C) 2011 James Pearson
5
+
6
+ Everyone is permitted to copy and distribute verbatim or modified
7
+ copies of this license document, and changing it is allowed as long
8
+ as the name is changed.
9
+
10
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
+
13
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
@@ -0,0 +1,6 @@
1
+ Similar to [lastfm-tail], lastfm-top is a small command-line utility designed
2
+ for gathering specific frequently-queried information from a user's Last.fm
3
+ profile - in this case, top tracks and artists for various timespans.
4
+
5
+ [lastfm-tail]: https://github.com/xiongchiamiov/lastfm-tail
6
+
@@ -0,0 +1,6 @@
1
+ require 'mg'
2
+ MG.new('lastfm-top.gemspec')
3
+
4
+ require 'fileutils'
5
+ require 'rake/testtask'
6
+
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # May you recognize your weaknesses and share your strengths.
4
+ # May you share freely, never taking more than you give.
5
+ # May you find love and love everyone you find.
6
+
7
+ require 'json'
8
+ require 'net/http'
9
+ require 'optparse'
10
+ require 'uri'
11
+
12
+ PERIOD_OPTIONS = ['7day', '3month', '6month', '12month', 'overall']
13
+ STAT_OPTIONS = ['artists', 'albums', 'tracks']
14
+ API_KEY = 'c7089003368bef3c8d0dd12ceede4978'
15
+ period = 'overall'
16
+ statistic = 'artists'
17
+ limit = 10
18
+
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!
49
+
50
+ user = ARGV[-1] || 'xiongchiamiov'
51
+
52
+ url = URI.parse("http://ws.audioscrobbler.com/2.0/?api_key=#{API_KEY}&format=json&method=user.gettop#{statistic}&user=#{user}&period=#{period}&limit=#{limit}")
53
+ json = Net::HTTP.get_response(url).body
54
+ results = JSON.parse(json)
55
+
56
+ if results['error']
57
+ puts "Uh oh, something went wrong: #{results['message']}"
58
+ exit results['error']
59
+ end
60
+
61
+ stats = results["top#{statistic}"][statistic.chop] # Chop off the 's'
62
+ stats.each do |stat|
63
+ # This could look a lot nicer. There's also some additional information
64
+ # available that differs depending on the statistic we're looking at.
65
+ puts "#{stat['name']} - #{stat['playcount']}"
66
+ end
67
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lastfm-top
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - xiongchiamiov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-03-11 00:00:00 -08:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: json
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: A small script to view top artists, albums and tracks of a Last.fm user.
28
+ email:
29
+ - xiong.chiamiov@gmail.com
30
+ executables:
31
+ - lastfm-top
32
+ extensions: []
33
+
34
+ extra_rdoc_files:
35
+ - README.md
36
+ files:
37
+ - COPYING
38
+ - Rakefile
39
+ - README.md
40
+ - bin/lastfm-top
41
+ has_rdoc: true
42
+ homepage: https://github.com/xiongchiamiov/lastfm-top/
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.5.3
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: View frequently-queried information from a Last.fm profile.
69
+ test_files: []
70
+