rwdaddresses 0.97 → 0.98
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.txt +5 -0
- data/code/superant.com.rwdtinkerbackwindow/controlclient.rb +25 -26
- data/code/superant.com.rwdtinkerbackwindow/helptexthashtinkerwin2.rb +25 -4
- data/code/superant.com.rwdtinkerbackwindow/installapplet.rb +1 -0
- data/code/superant.com.rwdtinkerbackwindow/installgemapplet.rb +20 -0
- data/code/superant.com.rwdtinkerbackwindow/installremotegem.rb +19 -0
- data/code/superant.com.rwdtinkerbackwindow/listgemdirs.rb +12 -0
- data/code/superant.com.rwdtinkerbackwindow/listgemzips.rb +54 -0
- data/code/superant.com.rwdtinkerbackwindow/listzips.rb +22 -7
- data/code/superant.com.rwdtinkerbackwindow/openhelpwindowtinkerwin2.rb +3 -0
- data/code/superant.com.rwdtinkerbackwindow/remotegemlist.rb +24 -0
- data/code/superant.com.rwdtinkerbackwindow/saveconfigurationrecord.rb +1 -1
- data/code/superant.com.rwdtinkerbackwindow/viewgemappletcontents.rb +21 -0
- data/configuration/rwdaddressesversion.cnf +1 -1
- data/configuration/rwdtinker.cnf +3 -6
- data/configuration/rwdtinkerversion.cnf +1 -1
- data/configuration/tinkerwin2variables.cnf +7 -3
- data/extras/cmdline_parse +47 -0
- data/extras/config_file +69 -0
- data/extras/errorMsg +19 -0
- data/extras/makePlaylist +34 -0
- data/extras/mp3controld +289 -0
- data/extras/playlist +186 -0
- data/extras/plugins/Network +237 -0
- data/extras/showHelp +18 -0
- data/gui/00coreguibegin/applicationguitop.rwd +1 -1
- data/gui/frontwindow0/superant.com.rwdaddresses/11viewnamedata.rwd +3 -1
- data/gui/frontwindow0/superant.com.rwdaddresses/13listnamerecordfiles.rwd +7 -1
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/40rwdlistzips.rwd +11 -11
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/45installremotezip.rwd +44 -0
- data/init.rb +22 -35
- data/installed/rwdviewlogo-0.4.inf +4 -0
- data/names/elektra.jpg +0 -0
- data/names/elektra.nam +7 -0
- data/rwd_files/HowTo_Addresses.txt +5 -0
- data/rwd_files/HowTo_Tinker.txt +19 -0
- data/rwd_files/contacttmp.jpg +0 -0
- metadata +27 -21
- data/installed/addressessample1.inf +0 -5
- data/lang/alanguagehashbegin.rb +0 -4
- data/lang/languagehash.rb +0 -4
- data/lang/templangfile.rb +0 -16
- data/lang/vlanguagehashend.rb +0 -6
- data/lang/wlocallangstart.rb +0 -5
- data/lang/xlocallangfile.rb +0 -16
- data/lang/zlocallangend.rb +0 -2
- data/tests/rwdtinkertestEN.rb +0 -163
- data/tests/test.result +0 -32
- data/tests/totranslate.lang +0 -93
- data/zips/rwdaschedule-0.921.zip +0 -0
- data/zips/rwdcalc-0.4.zip +0 -0
data/extras/mp3controld
ADDED
@@ -0,0 +1,289 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# --- MP3 Control ---
|
4
|
+
#
|
5
|
+
# Author: Magnus Engstr�m
|
6
|
+
# Email: magnus@gisab.se
|
7
|
+
# File: mp3controld
|
8
|
+
#
|
9
|
+
# Description
|
10
|
+
# -----------
|
11
|
+
# An application which manages
|
12
|
+
# mp3 songs on the poor users
|
13
|
+
# computer.
|
14
|
+
# -------------------------
|
15
|
+
|
16
|
+
# --- External files ---
|
17
|
+
# Change directory to find all functions
|
18
|
+
#Dir::chdir("/usr/lib/mp3control")
|
19
|
+
|
20
|
+
load "extras/config_file" # Handles the mp3controld.conf configuration file
|
21
|
+
load "extras/cmdline_parse" # Provides the Commandline::parse which returns an hash of the commandline
|
22
|
+
load "extras/showHelp" # Hmmm... guess what? This function shows the help message =)
|
23
|
+
load "extras/errorMsg" # Outputs error messages to the admin
|
24
|
+
load "extras/playlist" # Core playlist functionality
|
25
|
+
|
26
|
+
# --- MP3Control - the main class ---
|
27
|
+
class MP3Control
|
28
|
+
# --- Core functions ---
|
29
|
+
# initialize() reads the config files and daemonizes!
|
30
|
+
def initialize()
|
31
|
+
# Parse the commandline
|
32
|
+
$commandline = Commandline::parse()
|
33
|
+
|
34
|
+
# Display help if the commandline sucks
|
35
|
+
if($commandline == -1)
|
36
|
+
showHelp()
|
37
|
+
Kernel::exit(-1)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Make this class instance a background daemon
|
41
|
+
daemonize() if($commandline["--daemon"] != 'no' && $commandline["-D"] != 'no')
|
42
|
+
|
43
|
+
# Read the configuration file
|
44
|
+
configfile = ( $commandline["--configfile"] ? $commandline["--configfile"] : 'configuration/mp3controld.conf' ) # Use the --configfile if supplied, else use the default /etc/mp3controld/mp3controld.conf
|
45
|
+
$configFile = ConfigFile::parse(configfile) # Create an new config file object
|
46
|
+
errorMsg("Configuration file #{configfile} isn't readable or doesn't exist!", 137) if($configFile == -1)
|
47
|
+
|
48
|
+
# Find the default playlist (or use the user supplied one from the commandline)
|
49
|
+
defaultPlaylist = $configFile.getParam("programConfig", "defaultPlaylist")
|
50
|
+
defaultPlaylist = $commandline["--playlist"] if($commandline["--playlist"])
|
51
|
+
if( $configFile.getParam(defaultPlaylist, 'listFile').type == String) # Make sure the listFile contains a value
|
52
|
+
if(FileTest.readable_real?( $configFile.getParam(defaultPlaylist, 'listFile') )) # Make sure this file is readable
|
53
|
+
# Cool. Everything looks alright. Lets create a playlist!
|
54
|
+
errorMsg("Loading playlist '#{defaultPlaylist}' from #{$configFile.getParam(defaultPlaylist, 'listFile')}...") if($commandline['--verbose'] == 'on')
|
55
|
+
$current_playlist = Playlist::create_from_file($configFile.getParam(defaultPlaylist, 'listFile'))
|
56
|
+
$current_playlist_name = defaultPlaylist
|
57
|
+
|
58
|
+
# Errorhandling
|
59
|
+
errorMsg("Playlist creation from #{$current_playlist.filename} failed.", 1) if($current_playlist == -1) # Quit and complain if it didn't work
|
60
|
+
errorMsg("Playlist #{defaultPlaylist} (#{$current_playlist.filename}) doesn't contain any entries.", 1) if($current_playlist.length() < 1)
|
61
|
+
errorMsg("Playlist '#{defaultPlaylist}' loaded successfully.") if($commandline["--verbose"] == 'on')
|
62
|
+
|
63
|
+
# Fix wrap/repeat and shuffle the playlist if the configfile says so
|
64
|
+
$current_playlist.wrap = true if($configFile.getParam(defaultPlaylist, 'repeat') == 'true')
|
65
|
+
$current_playlist.shuffle() if($configFile.getParam(defaultPlaylist, 'random') == 'true')
|
66
|
+
$current_playlist.goto(0) # Rewind the playlist
|
67
|
+
else
|
68
|
+
errorMsg("The default playlist doesn't appear to exist, or has the wrong permissions. That's not good.", 1)
|
69
|
+
end
|
70
|
+
else # listFile returns other than string, that's baaaaad
|
71
|
+
errorMsg("the listFile value for '#{defaultPlaylist}' doesn't appear to exist in your #{$configFile.filename}. That's not good.", 1)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Check for the existence of our mpg123 instance
|
75
|
+
errorMsg("Trying to find the mp3 player...") if($commandline["--verbose"] == 'on')
|
76
|
+
@mpg123 = $configFile.getParam('programConfig', 'application') # Get the application name, path, and possible arguments
|
77
|
+
mpg123_application = @mpg123.scan(/^\S+/)
|
78
|
+
if(mpg123_application.type == Array)
|
79
|
+
mpg123_application = mpg123_application[0]
|
80
|
+
else
|
81
|
+
errorMsg("Please check your ProgramConfig/application setting in the configuration file. It seems weird.", 1)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Do some nice errorhandling
|
85
|
+
if( !FileTest::executable_real?(mpg123_application) )
|
86
|
+
errorMsg("#{mpg123_application} doesn't appear to exist. Please do something about it (no, not \"touch #{mpg123_application}\"! Stupid!).", 1)
|
87
|
+
else
|
88
|
+
errorMsg("Found #{mpg123_application}!") if($commandline["--verbose"] == 'on')
|
89
|
+
end
|
90
|
+
|
91
|
+
# Open an instance of mpg123, our high-performance mp3 player
|
92
|
+
@@mpg123 = IO::popen("#{@mpg123} -R -", 'r+')
|
93
|
+
|
94
|
+
# Start all plugins
|
95
|
+
load_plugins()
|
96
|
+
|
97
|
+
# Start the mp3 player
|
98
|
+
mpg123_control()
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
# mpg123_control() gets the input from the mpg123 process and handles it hopefully correctly :)
|
103
|
+
def mpg123_control()
|
104
|
+
|
105
|
+
# Initialize class variables
|
106
|
+
@@stopped = false
|
107
|
+
|
108
|
+
# Start playing if the configfile says so
|
109
|
+
if( $configFile.getParam('programConfig', 'playOnStartup') == 'true' )
|
110
|
+
MP3Control::play()
|
111
|
+
else
|
112
|
+
puts("Dont want to play!")
|
113
|
+
end
|
114
|
+
|
115
|
+
# The infinite 5 second loop =)
|
116
|
+
while(true)
|
117
|
+
begin
|
118
|
+
input = @@mpg123.readline.chop()
|
119
|
+
rescue EOFError
|
120
|
+
errorMsg("mpg123 error! Probably just a file that didn't exist (#{$current_playlist.song_info["filename"]}).")
|
121
|
+
@@mpg123 = IO::popen("#{@mpg123} -R -", 'r+') # Just start it again...
|
122
|
+
MP3Control::next_song() # Next song, so it doesn't die again...
|
123
|
+
end
|
124
|
+
|
125
|
+
# Song stopped
|
126
|
+
MP3Control::next_song() if(input == '@P 0' && @@stopped != true) # Change to the next song if current song stops and the user didn't told it to
|
127
|
+
@@stopped = false if(input == '@P 0' && @@stopped == true) # Reset the stop-flag if the user ordered the stop
|
128
|
+
|
129
|
+
# Time left
|
130
|
+
if(input[0,2] == '@F')
|
131
|
+
input =~ /^@F\s+\S+\s+\S+\s+(\S+)\s+(\S+)$/
|
132
|
+
@@time = $1
|
133
|
+
@@timeleft = $2
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# start() creates a new instance. Just like .new, but a nicer name.
|
140
|
+
def MP3Control::start()
|
141
|
+
MP3Control::new()
|
142
|
+
end
|
143
|
+
|
144
|
+
# daemonize() daemonizes this process. Cool =)
|
145
|
+
def daemonize()
|
146
|
+
if(child_pid = fork) # Parent code
|
147
|
+
puts("PID #{child_pid}")
|
148
|
+
Kernel::exit(0) # We dont want this parent process any more. Too bad.
|
149
|
+
end
|
150
|
+
|
151
|
+
# Child code. And child wants to be free from parent
|
152
|
+
Process.setsid()
|
153
|
+
end
|
154
|
+
|
155
|
+
# load_plugins() loads all plugins that can be found in the plugins directory
|
156
|
+
def load_plugins()
|
157
|
+
Dir::entries('extras/plugins/').each { |plugin|
|
158
|
+
# Try to load every plugin except all files that begins with a dot
|
159
|
+
if(plugin[0].chr() != '.')
|
160
|
+
retval = 0
|
161
|
+
# Do some errorhandling
|
162
|
+
begin
|
163
|
+
load("extras/plugins/#{plugin}") # Load the files
|
164
|
+
errorMsg("Loaded plugin '#{plugin}'") if($commandline['--verbose'] == 'no')
|
165
|
+
rescue SyntaxError
|
166
|
+
errorMsg("Plugin '#{plugin}' has syntax errors.")
|
167
|
+
end
|
168
|
+
|
169
|
+
# Run the plugin in a separate thread
|
170
|
+
# Try to start the class with the same name as the plugin
|
171
|
+
eval("
|
172
|
+
Thread::new() {
|
173
|
+
start_again = true
|
174
|
+
while(start_again)
|
175
|
+
puts(\"Plugin starting...\")
|
176
|
+
begin
|
177
|
+
retval = #{plugin}::start()
|
178
|
+
rescue
|
179
|
+
error = $!
|
180
|
+
puts(error)
|
181
|
+
puts(error.backtrace)
|
182
|
+
puts(\"Error in plugin #{plugin}! Waiting for 5 seconds before attempting to start again...\")
|
183
|
+
sleep(5)
|
184
|
+
end
|
185
|
+
if(retval == -1)
|
186
|
+
errorMsg(\"Plugin 'plugins/#{plugin}' failed to load...\")
|
187
|
+
start_again = false
|
188
|
+
end
|
189
|
+
end
|
190
|
+
}
|
191
|
+
")
|
192
|
+
|
193
|
+
end
|
194
|
+
}
|
195
|
+
end
|
196
|
+
|
197
|
+
# exit_mpg123() terminates the current mpg123 session
|
198
|
+
def MP3Control::exit_mpg123()
|
199
|
+
#system("kill `pidof mpg123`") # Yes, I know this isn't a nice way to do it in, please fix this and send me a patch :)
|
200
|
+
end
|
201
|
+
|
202
|
+
# mpg123_command() sends a command to mpg123
|
203
|
+
def MP3Control::mpg123_command(command)
|
204
|
+
errorMsg("mpg123 command: '#{command}'") if($commandline['--verbose'] == 'on')
|
205
|
+
@@mpg123.write("#{command}\n")
|
206
|
+
@@mpg123.flush()
|
207
|
+
end
|
208
|
+
|
209
|
+
|
210
|
+
# --- play functions ---
|
211
|
+
# play() plays the current index of the current playlist
|
212
|
+
def MP3Control::play()
|
213
|
+
@@stopped = false
|
214
|
+
mpg123_command("LOAD #{$current_playlist.song_info["filename"]}")
|
215
|
+
end
|
216
|
+
|
217
|
+
# stop() stops playing
|
218
|
+
def MP3Control::stop()
|
219
|
+
mpg123_command("PAUSE")
|
220
|
+
@@stopped = true # Set the stop-status to true
|
221
|
+
end
|
222
|
+
|
223
|
+
# pause() pauses playing
|
224
|
+
def MP3Control::pause()
|
225
|
+
@@stopped = false
|
226
|
+
mpg123_command("PAUSE")
|
227
|
+
end
|
228
|
+
|
229
|
+
# next_song() loads the next song. Yay...
|
230
|
+
def MP3Control::next_song()
|
231
|
+
retval = $current_playlist.next()
|
232
|
+
if(retval == -1)
|
233
|
+
errorMsg("Error while changing to the next song.") # Tell him/her
|
234
|
+
else
|
235
|
+
MP3Control::play() if(@@stopped == false)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
# prev_song() loads the previous song. Yay...
|
240
|
+
def MP3Control::prev_song()
|
241
|
+
retval = $current_playlist.prev()
|
242
|
+
if(retval == -1)
|
243
|
+
errorMsg("Error while changing to the previous song.") # Tell him/her
|
244
|
+
else
|
245
|
+
MP3Control::play() if(@@stopped == false)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
# forward(sec) jumps sec seconds forward
|
250
|
+
def MP3Control::forward(sec)
|
251
|
+
mpg123_command("JUMP +#{sec*38}")
|
252
|
+
end
|
253
|
+
|
254
|
+
# backward(sec) jumps sec seconds backward
|
255
|
+
def MP3Control::backward(sec)
|
256
|
+
mpg123_command("JUMP -#{sec*38}")
|
257
|
+
end
|
258
|
+
|
259
|
+
|
260
|
+
# --- Misc functions ---
|
261
|
+
# getTime() - Get the current song time information. getTime(true) for time left
|
262
|
+
def MP3Control::getTime(whichTime = 'elapsed')
|
263
|
+
case whichTime
|
264
|
+
when 'elapsed'
|
265
|
+
parsed = Time::at(@@time.to_i)
|
266
|
+
when 'left'
|
267
|
+
parsed = Time::at(@@timeleft.to_i)
|
268
|
+
when 'total'
|
269
|
+
parsed = Time::at( (@@time.to_f + @@timeleft.to_f).to_i )
|
270
|
+
end
|
271
|
+
|
272
|
+
hour = (parsed.hour - 1).to_s
|
273
|
+
min = parsed.min.to_s
|
274
|
+
sec = parsed.sec.to_s
|
275
|
+
|
276
|
+
hour = "0#{hour}" if(hour.length == 1)
|
277
|
+
min = "0#{min}" if(min.length == 1)
|
278
|
+
sec = "0#{sec}" if(sec.length == 1)
|
279
|
+
|
280
|
+
hour = (hour == '00' ? '' : "#{hour}:")
|
281
|
+
|
282
|
+
# Return the now formatted time
|
283
|
+
"#{hour}#{min}:#{sec}"
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|
287
|
+
|
288
|
+
# Create an instance of the MP3Control class and start the application
|
289
|
+
MP3Control::start()
|
data/extras/playlist
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
#!ruby
|
2
|
+
|
3
|
+
# --- Playlist class ---
|
4
|
+
#
|
5
|
+
# Author: Magnus Engstr�m
|
6
|
+
# Email: magnus@gisab.se
|
7
|
+
# File: playlist
|
8
|
+
#
|
9
|
+
# Description
|
10
|
+
# -----------
|
11
|
+
# The Playlist class handles everything a playlist should be able to manage.
|
12
|
+
# Shuffle it, unshuffle it, wrap it if desired, add new songs, find songs and
|
13
|
+
# so on. Cool huh? :)
|
14
|
+
# ----------------------
|
15
|
+
|
16
|
+
class Playlist
|
17
|
+
# create_from_file() creates a playlist from a file and returns either a Playlist instance or -1 in case of error
|
18
|
+
# This function should be used instead of the ::new, because this one
|
19
|
+
# returns -1 on file read errors, which the ::new doesn't.
|
20
|
+
def Playlist::create_from_file(filename)
|
21
|
+
# Check that the file is readable
|
22
|
+
if(FileTest::readable_real?(filename))
|
23
|
+
new(filename) # Return the Playlist class instance
|
24
|
+
else
|
25
|
+
-1 # Return -1 on error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# initialize reads the playlist from a file and returns the Playlist instance
|
30
|
+
def initialize(filename)
|
31
|
+
|
32
|
+
@filename = filename # Store the filename for later use
|
33
|
+
@playlist = Array::new() # This hash contains the whole playlist
|
34
|
+
@index = 0 # Playlist's current position
|
35
|
+
@wrap = false # Don't repeat the list as default
|
36
|
+
|
37
|
+
# Parse these fields, separated with double pipes (||) (songname, artist, album, year, comment, tracknum, genre_id, genre)
|
38
|
+
File::foreach(filename) { |line| # Iterate through every line in the file
|
39
|
+
foo = line.split(/\|\|/)
|
40
|
+
@playlist << { "filename" => foo[0], "songname" => foo[1], "artist" => foo[2], "album" => foo[3], "year" => foo[4], "comment" => foo[5], "tracknum" => foo[6], "genre_id" => foo[7], "genre" => foo[8] } # Add a hash to the @playlist array with all values found in the playlist file
|
41
|
+
}
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def insert(song, placement = 0)
|
46
|
+
# Check song information
|
47
|
+
return -1 if(song.type != Hash)
|
48
|
+
song = { "filename" => song["filename"], "songname" => song["songname"], "artist" => song["artist"], "album" => song["album"], "year" => song["year"], "comment" => song["comment"], "tracknum" => song["tracknum"], "genre_id" => song["genre_id"], "genre" => song["genre"] }
|
49
|
+
|
50
|
+
# Check minimum and maximum values
|
51
|
+
placement = 0 if(placement < 0)
|
52
|
+
placement = @playlist.length() if(placement > @playlist.length() )
|
53
|
+
|
54
|
+
# Retrieve the two parts of the split playlist
|
55
|
+
first = @playlist[0...placement]
|
56
|
+
second = @playlist[placement...@playlist.length()]
|
57
|
+
|
58
|
+
# Put it together again
|
59
|
+
@playlist = Array::new()
|
60
|
+
@playlist = first
|
61
|
+
@playlist << song
|
62
|
+
@playlist.concat(second)
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def remove(placement = 0)
|
67
|
+
# Check boundaries
|
68
|
+
placement = 0 if(placement < 0)
|
69
|
+
placement = @playlist.length()-1 if( placement >= @playlist.length() )
|
70
|
+
|
71
|
+
# Delete the item
|
72
|
+
@playlist.delete_at(placement)
|
73
|
+
end
|
74
|
+
|
75
|
+
def find(search_string, case_insensitive = false, fields = ["songname", "filename"])
|
76
|
+
case_insensitive = nil if(case_insensitive == false)
|
77
|
+
|
78
|
+
results = Array::new()
|
79
|
+
regex = Regexp::new(search_string, case_insensitive) # The regex that will be matched
|
80
|
+
|
81
|
+
# Iterate through the playlist to find one or more matching songs
|
82
|
+
@playlist.length().times { |index|
|
83
|
+
# Iterate through the user supplied list of fields to be searched
|
84
|
+
fields.each { |field|
|
85
|
+
# Make sure this is a hash, so we don't go and crash, or make someone's dog sick :)
|
86
|
+
if(@playlist[index].type == Hash)
|
87
|
+
results << index if( regex.match(@playlist[index][field]) && !(results.include?(index)) ) # If it matches, and if it doesn't already is in the results. We don't want duplicates :)
|
88
|
+
end
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
results # Return the results
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
def shuffle()
|
97
|
+
# Iterate through the playlist
|
98
|
+
( 0...@playlist.length() ).each { |i|
|
99
|
+
j = rand @playlist.length() # Grab a random value between 0 and @playlist.length()
|
100
|
+
|
101
|
+
# Maintain index
|
102
|
+
if(@index == j)
|
103
|
+
@index = i
|
104
|
+
elsif(@index == i)
|
105
|
+
@index = j
|
106
|
+
end
|
107
|
+
|
108
|
+
@playlist[i], @playlist[j] = @playlist[j], @playlist[i]
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
def re_read()
|
113
|
+
# Maintain index
|
114
|
+
current_filename = @playlist[@index]["filename"]
|
115
|
+
|
116
|
+
# Create a new playlist array
|
117
|
+
@playlist = Array::new()
|
118
|
+
@index = 0
|
119
|
+
foo_index = 0 # Just to keep the count while adding all songs to the @playlist
|
120
|
+
|
121
|
+
# Parse these fields, separated with double pipes (||) (songname, artist, album, year, comment, tracknum, genre_id, genre)
|
122
|
+
# Iterate through every line in the file
|
123
|
+
File::foreach(@filename) { |line|
|
124
|
+
foo = line.split(/\|\|/) # Separate the fields with double pipes (||)
|
125
|
+
@playlist << { "filename" => foo[0], "songname" => foo[1], "artist" => foo[2], "album" => foo[3], "year" => foo[4], "comment" => foo[5], "tracknum" => foo[6], "genre_id" => foo[7], "genre" => foo[8] } # Add a hash to the @playlist array with all values found in the playlist file
|
126
|
+
|
127
|
+
# Maintain index
|
128
|
+
@index = foo_index if(foo[0] == current_filename)
|
129
|
+
foo_index += 1
|
130
|
+
}
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
def next()
|
135
|
+
# Increase the counter and return -1 if the playlist went to far, and wrap isn't true
|
136
|
+
@index += 1
|
137
|
+
if( @index >= @playlist.length() )
|
138
|
+
if(@wrap)
|
139
|
+
@index = 0
|
140
|
+
else
|
141
|
+
@index -= 1
|
142
|
+
-1 # Return an error
|
143
|
+
end
|
144
|
+
else
|
145
|
+
@index
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def prev()
|
150
|
+
# Decrease the counter and return -1 if the playlist went to far, and wrap isn't true
|
151
|
+
@index -= 1
|
152
|
+
if( @index < 0 )
|
153
|
+
if(@wrap)
|
154
|
+
@index = @playlist.length() -1
|
155
|
+
else
|
156
|
+
@index += 1
|
157
|
+
-1 # Return an error
|
158
|
+
end
|
159
|
+
else
|
160
|
+
@index
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def song_info(index = @index)
|
165
|
+
@playlist[index]
|
166
|
+
end
|
167
|
+
|
168
|
+
def goto(index = 0)
|
169
|
+
if( index >= 0 && index < @playlist.length() )
|
170
|
+
@index = index
|
171
|
+
else
|
172
|
+
return -1
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def length()
|
177
|
+
@playlist.length()
|
178
|
+
end
|
179
|
+
|
180
|
+
def each()
|
181
|
+
@playlist.each { |song| yield(song) }
|
182
|
+
end
|
183
|
+
|
184
|
+
attr_reader :wrap, :index, :filename
|
185
|
+
attr_writer :wrap
|
186
|
+
end
|