lastfm-tail 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/lastfm-tail +20 -8
  2. metadata +2 -2
data/bin/lastfm-tail CHANGED
@@ -57,7 +57,7 @@ OptionParser.new do |opts|
57
57
  end
58
58
 
59
59
  opts.on('-v', '--version', 'Show the installed version of lastfm-tail.') do
60
- puts 'lastfm-tail 1.1.0'
60
+ puts 'lastfm-tail 1.1.1'
61
61
  exit 0
62
62
  end
63
63
 
@@ -70,23 +70,35 @@ end.parse!
70
70
  username = ARGV[-1] || username
71
71
  lastTimestamp = Time.at(0)
72
72
 
73
+ def print_retry(message)
74
+ $stderr.write "#{message} Trying again in "
75
+ 5.downto 1 do |i|
76
+ $stderr.print "#{i} "
77
+ sleep 1
78
+ end
79
+ $stderr.write "\n"
80
+ end
81
+
73
82
  # The logic here dealing with polling is a bit dirty.
74
83
  begin
75
84
  begin
76
85
  rss = open("http://ws.audioscrobbler.com/2.0/user/#{username}/recenttracks.rss").read()
77
- rescue SocketError, OpenURI::HTTPError, EOFError, Net::HTTPServiceUnavailable
78
- $stderr.write "Network unreachable, trying again in "
79
- 5.downto 1 do |i|
80
- $stderr.print "#{i} "
81
- sleep 1
82
- end
83
- $stderr.write "\n"
86
+ rescue SocketError, OpenURI::HTTPError, EOFError, Errno::ENETDOWN,
87
+ Net::HTTPServiceUnavailable
88
+ print_retry 'Network unreachable.'
84
89
  networkError = true
85
90
  next
86
91
  end
87
92
  networkError = false
93
+
88
94
  xml = XmlSimple.xml_in rss
89
95
  items = xml['channel'][0]['item']
96
+ if items.nil?
97
+ print_retry 'Empty response from server.'
98
+ networkError = true
99
+ next
100
+ end
101
+
90
102
  items.reverse! if reverse
91
103
  items.each_with_index do |item, i|
92
104
  if i == trackLimit
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: lastfm-tail
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.0
5
+ version: 1.1.1
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: 2013-06-21 00:00:00 -07:00
13
+ date: 2013-07-04 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency