ruby-ampache 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
data/bin/ruby-ampache CHANGED
@@ -66,6 +66,11 @@ def print_albums(albums)
66
66
  end
67
67
 
68
68
  def print_artists(artists)
69
+ if artists.empty?
70
+ reset_token
71
+ say("token exausted, please retry")
72
+ artists = @ar.artists
73
+ end
69
74
  choose do |menu|
70
75
  menu.prompt = "Choose an artists or abort (1)"
71
76
  menu.choice(HighLine.new.color "ABORT", :red)
@@ -75,6 +80,11 @@ def print_artists(artists)
75
80
  end
76
81
  end
77
82
 
83
+ # try to reset token if it's not valid
84
+ def reset_token
85
+ @ar.token = @ar.getAuthToken(@ar.user,@ar.psw)
86
+ end
87
+
78
88
  def credits
79
89
  s = <<STR
80
90
  Ruby-Ampache: Ultra-simple, low-featured command line Ampache player
@@ -89,20 +99,23 @@ Usage: pick your choice from the menu.
89
99
  Songs are queued up into mplayer playlist
90
100
 
91
101
  STR
92
- return s
102
+ return s
93
103
  end
94
- ar =AmpacheRuby.new(ar_config.get_value('AMPACHE_HOST'),ar_config.get_value('AMPACHE_USER'), ar_config.get_value('AMPACHE_USER_PSW'))
95
- @pl = AmpachePlaylist.new
96
104
 
105
+ # MAIN
106
+ @ar =AmpacheRuby.new(ar_config.get_value('AMPACHE_HOST'),ar_config.get_value('AMPACHE_USER'), ar_config.get_value('AMPACHE_USER_PSW'))
107
+ @pl = AmpachePlaylist.new
97
108
 
98
109
  while true
99
110
  choose do |menu|
100
111
  menu.prompt = "pick your choice!"
101
112
  menu.choice("now playing") { say(HighLine.new.color(@pl.nowPlaying, :red)) }
102
113
  menu.choice("skip this song") { @pl.next; say(HighLine.new.color(@pl.nowPlaying, :red)) }
103
- menu.choice("add another album") { print_artists(ar.artists); say(HighLine.new.color(@pl.nowPlaying, :red)) }
114
+ menu.choice("add another album to playlist") { print_artists(@ar.artists); say(HighLine.new.color(@pl.nowPlaying, :red)) }
115
+ menu.choice("look for an artist") { print_artists(@ar.artists(ask("Artist name?"))); say(HighLine.new.color(@pl.nowPlaying, :red)) }
104
116
  menu.choice("stop playing") { @pl.stop }
105
117
  menu.choice("about ruby-ampache") { say(HighLine.new.color credits, :red) }
106
118
  menu.choice("quit") { @pl.stop; exit}
107
119
  end
108
120
  end
121
+
data/lib/lib-ampache.rb CHANGED
@@ -5,6 +5,17 @@ require 'digest/sha2'
5
5
 
6
6
  require File.join(File.dirname(__FILE__),'lib-ampache')
7
7
 
8
+ =begin
9
+ Class is initialized with Hostname, user and password
10
+ An auth token is requested on class initialization
11
+
12
+ To get the artist list from database you can
13
+ call the method artists(nil) and you'll get an array
14
+ of AmpacheArtists.
15
+
16
+ To get albums from an artist you can issue
17
+ artist_instance.albums or ampache_ruby.instance.albums(artist_instance)
18
+ =end
8
19
  class AmpacheRuby
9
20
 
10
21
 
@@ -19,7 +30,8 @@ class AmpacheRuby
19
30
  end
20
31
 
21
32
  attr_accessor :host, :path, :user, :psw, :token, :playlist
22
-
33
+
34
+ # tryies to obtain an auth token
23
35
  def getAuthToken(user,psw)
24
36
  action= "handshake"
25
37
  # auth string
@@ -32,7 +44,8 @@ class AmpacheRuby
32
44
 
33
45
  return doc.at("auth").content
34
46
  end
35
-
47
+
48
+ # generic api method call
36
49
  def callApiMethod( method, args={})
37
50
  args['auth'] ||= token if token
38
51
  url = path + "/server/xml.server.php?action=#{method}&#{args.keys.collect { |k| "#{k}=#{args[k]}"}.join('&')}"
@@ -40,7 +53,8 @@ class AmpacheRuby
40
53
  return Nokogiri::XML(response.body)
41
54
  end
42
55
 
43
-
56
+ # retrive artists lists from database,
57
+ # name is an optional filter
44
58
  def artists(name = nil)
45
59
  args = {}
46
60
  args = { 'filter' => name.to_s } if name # artist search
data/lib/lib-classes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'open4'
2
+ require 'timeout'
2
3
  class AmpacheArtist
3
4
 
4
5
  # include play module
@@ -66,7 +67,13 @@ class AmpachePlaylist
66
67
  mplayer_options = "-slave -quiet"
67
68
  mplayer = "#{options[:path]} #{mplayer_options} \"#{song.url}\""
68
69
  @pid,@stdin,@stdout,@stderr = Open4.popen4(mplayer)
69
- until @stdout.gets.inspect =~ /playback/ do
70
+ begin
71
+ t = Timeout::timeout(3) do
72
+ until @stdout.gets.inspect =~ /playback/ do
73
+ end
74
+ end
75
+ rescue Timeout::Error
76
+ puts "err on reading data"
70
77
  end
71
78
  else
72
79
  begin
@@ -95,7 +102,6 @@ class AmpachePlaylist
95
102
  def next
96
103
  begin
97
104
  @stdin.puts "pt_step 1 1" if @pid
98
- sleep 2 #XXX sleep time .. we can't be too fast on remote playing
99
105
  rescue Errno::EPIPE
100
106
  puts "playlist is over"
101
107
  @pid = nil
@@ -106,11 +112,26 @@ class AmpachePlaylist
106
112
  return "Not playing man!" unless @pid
107
113
  begin
108
114
  s= ''
109
- #s+= get("file_name")
110
- s+= get("meta_title")
111
- s+= get("meta_artist")
112
- s+= get("meta_album")
113
- return s.chomp
115
+ @tim = 0
116
+ begin
117
+ t = Timeout::timeout(3) do
118
+ #s+= get("file_name")
119
+ s+= get("meta_title")
120
+ s+= get("meta_artist")
121
+ s+= get("meta_album")
122
+ s.chomp!
123
+ end
124
+ @tim = 0
125
+ return s
126
+ rescue Timeout::Error
127
+ @tim += 1
128
+ if (@tim > 3 )
129
+ @tim = 0
130
+ return "err"
131
+ else
132
+ return nowPlaying
133
+ end
134
+ end
114
135
  rescue Errno::EPIPE
115
136
  return "playlist is over"
116
137
  @pid = nil
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-ampache
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - ghedmat
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-27 00:00:00 +02:00
18
+ date: 2010-09-28 00:00:00 +02:00
19
19
  default_executable: ruby-ampache
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency