Is this feasible
Hello all,
I am considering an attempt to make some kind of bash script which can fetch a random entry from a playlist, invoke xine to play the entry from the play list and set a volume level accordingly. To do this, I would need to make a list of entries which would have a parameter, separated by a comma at the begining of each row, which represents a playback volume. The list would need a row count at the beginning of the file too, perhaps. That of course is the easy bit. I have thought this through a little bit and I think I would need a script to perform the following tasks - Script to read first row of list which will set a variable representing the row count. - Script to choose a random number between 1 and the "row count" found in the list. - Script to use the random number to find a row number in the list and fetch the data from that row - Script then sets a variable representing the volume - Script sets a variable representing the path to a file to be played - Script invokes xine by way of xine -f -g -S --session 0,volume=<$VOL>,mrl=<$PATH> Not being all that familiar with BASH scripts, I was wondering if this idea was a little too ambitious or not. Can this actually be achieved with a BASH script I guess is what I am wondering? Regards, Greenie |
Definately not hard. Might think about chars encountered in paths and filenames and the separator you use.
|
That's totally doable. You only need one script, not the 6 you list. Random numbers, or at least random enough for your purposes, are trivial.
Code:
$ let foo=$RANDOM Code:
$ let foo=$RANDOM%100 |
Why does:
Code:
echo $[($RANDOM % 10) + 1] random_script.sh: 5: Syntax error: "(" unexpected ??? I got the example from: http://linuxtechsupport.blogspot.com...om-number.html |
This works:
echo $(($(($RANDOM % 10)) + 1)) I'm sure there's a more elegant notation somewhere.... |
Quote:
I get: Code:
random_script.sh: 5: arithmetic expression: syntax error: "( % 10) + 1" |
Works here....
Try using cut and paste to avoid typos? Also, test things like this in pieces. For example, does this work? echo $(($((4567 % 10)) + 1)) This? echo $((4567 % 10)) |
Quote:
That works, but if I replace the 4567 with $RANDOM, I then get: random_script.sh: 5: arithmetic expression: syntax error: "( % 10) + 1" BTW, I always copy+paste, re-typing is too slow, easier to copy+paste. |
If I do:
Code:
echo $RANDOM But this doesn't: Code:
number=$RANDOM |
What shell are you using?
Code:
mike@continuity:~$ echo $0 |
user@edgy:~$ echo $0
bash user@edgy:~$ |
Hmmmm. Try
Code:
mike@continuity:~$ bash --version |
Quote:
Code:
echo $(( (RANDOM % 10) + 1)) |
Quote:
Moving ahead of schedule slightly here's a quick idea for creating a dirlisting with sequence number, volume, filename: Code:
createListing() { [ -d "$1" ] || exit 1; SEP=' '; N=0; VOL=90; find "$1" -type f -iname \*.avi \ |
As arizonagroovejet mentioned earlier, there's no point have a row count, just use wc to count the number of lines.
Do you need a seperate volume level for each file? Won't one do? If the files have different volumes, you could normalize them. If you do need seperate volumes, you could read the file into two arrays, one for filenames one for volumes, then pick one to play. E.g. Code:
#/bin/sh If you want a limited number of plays, how do want to do it? Just play N files or do you want to play them all? I.e. if you play files at random, it's obviously unlikely you'd play them all without repeating any. If you want to make sure the're all played, you'll have to keep track of what's been played. You could remove a file from the list once it's played, then when the list is empty, it's finished. E.g. Code:
while [[ -n "$files" ]]; do |
All times are GMT -5. The time now is 05:27 AM. |