lastfm-tail 1.0.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 +17 -0
  3. data/Rakefile +6 -0
  4. data/bin/lastfm-tail +74 -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.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ A small script, inspired by the Unix `tail` utility, for viewing
2
+ recently-scrobbled tracks on [Last.fm](http://last.fm).
3
+
4
+ # Options
5
+
6
+ Usage: lastfm-tail [options] [USER]
7
+ -f, --follow Don't exit after retrieving data, but
8
+ poll Last.fm for new tracks. Polling
9
+ frequency is controlled by the `-F`
10
+ option. Implies -r.
11
+ -F, --frequency NUM Poll Last.fm every NUM seconds. Defaults
12
+ to 5. Implies `-f`.
13
+ -n, --number NUM List NUM tracks.
14
+ -r, --reverse List tracks from oldest to newest.
15
+ -v, --version Show the installed version of lastfm-tail.
16
+ -h, --help Show this help dialog.
17
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "mg"
2
+ MG.new("lastfm-tail.gemspec")
3
+
4
+ require 'fileutils'
5
+ require 'rake/testtask'
6
+
data/bin/lastfm-tail ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'date'
4
+ require 'open-uri'
5
+ require 'optparse'
6
+ require 'xmlsimple'
7
+
8
+ trackLimit = 10
9
+ pollFrequency = nil
10
+ reverse = false
11
+ OptionParser.new do |opts|
12
+ opts.banner = "Usage: #{$0} [options] [USER]"
13
+
14
+ opts.on('-f', '--follow', "Don't exit after retrieving data, but poll "\
15
+ +"Last.fm for new tracks. Polling frequency "\
16
+ +"is controlled by the `-F` option. Implies -r.") do
17
+ pollFrequency = 5 # Magic number
18
+ reverse = true
19
+ end
20
+
21
+ opts.on('-F', '--frequency NUM', Integer, 'Poll Last.fm every NUM seconds. '\
22
+ +'Defaults to 5. Implies `-f`. ') do |num|
23
+ pollFrequency = num
24
+ end
25
+
26
+ opts.on('-n', '--number NUM', Integer, 'List NUM tracks.') do |num|
27
+ if num > 10
28
+ puts 'Last.fm only provides the 10 latest tracks; sorry!'
29
+ exit 1
30
+ end
31
+
32
+ trackLimit = num
33
+ end
34
+
35
+ opts.on('-r', '--reverse', 'List tracks from oldest to newest.') do
36
+ reverse = true
37
+ end
38
+
39
+ opts.on('-v', '--version', 'Show the installed version of lastfm-tail.') do
40
+ puts 'lastfm-tail 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
+ username = ARGV[-1] || 'xiongchiamiov'
51
+ lastTimestamp = Time.at(0)
52
+
53
+ # The logic here dealing with polling is a bit dirty.
54
+ begin
55
+ rss = open("http://ws.audioscrobbler.com/2.0/user/#{username}/recenttracks.rss").read()
56
+ xml = XmlSimple.xml_in rss
57
+ items = xml['channel'][0]['item']
58
+ items.reverse! if reverse
59
+ items.each_with_index do |item, i|
60
+ if i == trackLimit
61
+ break
62
+ end
63
+
64
+ timestamp = Time.parse item['pubDate'][0]
65
+ # Is this an older item that's overlapping?
66
+ if !pollFrequency.nil? && lastTimestamp >= timestamp
67
+ next
68
+ end
69
+
70
+ puts item['title']
71
+ lastTimestamp = timestamp
72
+ end
73
+ end while !pollFrequency.nil? && sleep(pollFrequency)
74
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lastfm-tail
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - xiongchiamiov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-12-29 00:00:00 -08:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: xml-simple
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, inspired by the Unix tail utility, for viewing recently-scrobbled tracks on Last.fm.
28
+ email:
29
+ - xiong.chiamiov@gmail.com
30
+ executables:
31
+ - lastfm-tail
32
+ extensions: []
33
+
34
+ extra_rdoc_files:
35
+ - README.md
36
+ files:
37
+ - COPYING
38
+ - Rakefile
39
+ - README.md
40
+ - bin/lastfm-tail
41
+ has_rdoc: true
42
+ homepage: https://github.com/xiongchiamiov/lastfm-tail/
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 recently-scrobbled tracks from Last.fm.
69
+ test_files: []
70
+