LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-18-2012, 11:01 AM   #1
emmeteo
LQ Newbie
 
Registered: May 2012
Posts: 25

Rep: Reputation: Disabled
Composite commands


Hello everyone.
How the title suggests, I wanted to write a command that takes another command as its argument.
In particular, I would like to search for a song by partial name in my music folder and play this file with mplayer, something like that:
f(g(x))= mplayer (find ~/path | grep -i partial_name).
I was wondering what's the general sintax of a composite command.
Thank you very much.
 
Old 11-18-2012, 11:18 AM   #2
oldscratch
LQ Newbie
 
Registered: Apr 2008
Location: South Carolina
Distribution: Red Hat, Scientific Linux, CentOS, and Ubuntu
Posts: 27

Rep: Reputation: 13
An example to do what you want

Try putting your argument command in backticks, something like this:

mplayer `find ~/path -iname partial_name`

Or something like this, if you want to put all matches in a playlist and use the GUI:

mplayer -gui -enqueue `find ~/path -iname "*mp3"` &





Quote:
Originally Posted by emmeteo View Post
Hello everyone.
How the title suggests, I wanted to write a command that takes another command as its argument.
In particular, I would like to search for a song by partial name in my music folder and play this file with mplayer, something like that:
f(g(x))= mplayer (find ~/path | grep -i partial_name).
I was wondering what's the general sintax of a composite command.
Thank you very much.
 
Old 11-18-2012, 11:32 AM   #3
emmeteo
LQ Newbie
 
Registered: May 2012
Posts: 25

Original Poster
Rep: Reputation: Disabled
I'm interested in your first suggestion, but it doesn't work:
this is what I get:


mplayer: Symbol `ff_codec_bmp_tags' has different size in shared object, consider re-linking
MPlayer SVN-r33713-4.6.1 (C) 2000-2011 MPlayer Team
Usage: mplayer [options] [url|path/]filename

Basic options: (complete list in the man page)
...
...
...

* * * SEE THE MAN PAGE FOR DETAILS, FURTHER (ADVANCED) OPTIONS AND KEYS * * *
 
Old 11-18-2012, 11:43 AM   #4
emmeteo
LQ Newbie
 
Registered: May 2012
Posts: 25

Original Poster
Rep: Reputation: Disabled
moreover there is the possibility that the find command will find different files with the same partial name, so I would like to play them in a playlist. so: find all the file with that partial name and play them with mplayer in a playlist, then I will write an alias such that I can do something like:
playnow partial_name
 
Old 11-18-2012, 12:41 PM   #5
emmeteo
LQ Newbie
 
Registered: May 2012
Posts: 25

Original Poster
Rep: Reputation: Disabled
I tried in this way:
mplayer `find ~/Music | grep -i partial_name`.
it tries to play the files but the path and the name of the file itself have been splitted:
this is the full path

/Musica/Porcupine\ Tree/Song\ 01/

but the result is:

Playing Porcupine.
File not found: 'Porcupine'
Failed to open Porcupine.

Playing Tree.
File not found: 'Tree'
Failed to open Tree.

Playing Tree.
File not found: 'Tree'
Failed to open Tree.

Playing Song.
File not found: 'Song'
Failed to open Song.

Playing 01.
File not found: '01'
Failed to open 01.


Any idea? It would be very simple but I don't know the correct sintax. Maybe ti will work with locate command? I'm tring but nothing happens.
Thank you all.
 
Old 11-18-2012, 01:04 PM   #6
emmeteo
LQ Newbie
 
Registered: May 2012
Posts: 25

Original Poster
Rep: Reputation: Disabled
Ok, if someone is interested, i found a partial answer:
find ~/path -iname '*partial_name*' -type f -print0 | xargs -0 mplayer
this works for single files.

but when I find more then one song, mplayer doesen't play, and the option -playlist
find ~/path -iname '*partial_name*' -type f -print0 | xargs -0 mplayer -playlist
is useless.

Last edited by emmeteo; 11-18-2012 at 01:13 PM.
 
Old 11-18-2012, 01:06 PM   #7
oldscratch
LQ Newbie
 
Registered: Apr 2008
Location: South Carolina
Distribution: Red Hat, Scientific Linux, CentOS, and Ubuntu
Posts: 27

Rep: Reputation: 13
You could do it this way:

find ~/path -iname "*partial name*" -exec mplayer {} \;

Of course, if you find names that aren't actually playable by mplayer, its probably going to fail.
 
Old 11-18-2012, 01:27 PM   #8
emmeteo
LQ Newbie
 
Registered: May 2012
Posts: 25

Original Poster
Rep: Reputation: Disabled
Thank you, now it works... finally...

Quote:
Of course, if you find names that aren't actually playable by mplayer, its probably going to fail.
I'm in my music directory, all the file inside it are playable by mplayer.

Since we are here, do you know how to write an alias for this command?
How can I pass the argument from the new command to the "aliased" one?
For example:
alias playnow argument ='find ~/path -iname "*argument*" -exec mplayer {} \;'
I know that isn't the right way.
 
Old 11-18-2012, 01:39 PM   #9
emmeteo
LQ Newbie
 
Registered: May 2012
Posts: 25

Original Poster
Rep: Reputation: Disabled
ok tried this.

alias playnow = find ~/path -iname "*$1*" -exec mplayer {} \;

but there's a mistake somewhere

Last edited by emmeteo; 11-18-2012 at 01:55 PM.
 
Old 11-18-2012, 02:14 PM   #10
emmeteo
LQ Newbie
 
Registered: May 2012
Posts: 25

Original Poster
Rep: Reputation: Disabled
So, this is the solution. I wrote this in my ~/.bashrc file:

play1()
{
find ~/path -iname "*$1*" -exec mplayer {} \;
}
alias playnow=play1

and now it works perfectly. I simply write "playnow something" and the music starts. Enjoy
Thank you all and goodbye.
 
1 members found this post helpful.
Old 11-22-2012, 10:45 AM   #11
emmeteo
LQ Newbie
 
Registered: May 2012
Posts: 25

Original Poster
Rep: Reputation: Disabled
Without editing a new thread, I'll bumb this one, since the topic is the same.
I'm trying to customize mplayer.
I already did this, thanks to oldscratch suggestions:

#search and play song
play1()
{
find ~/Music -iname "*$1*" -exec mplayer {} \;
}
alias playnow='play1'



So when I type in the terminal "playnow partial_name_of_the_song", the song I was searching for starts to play.
Now I would like to do the same but with folders: type the partial name of the music directory I want to listen and obtain mplayer playing that folder. I'm traying in this way:

#search and play by folder
play2()
{
find ~/Music -iname "*$1*" -type d
}
alias band='mplayer -afm mp3lib -shuffle -playlist <(find "play2" -type f|sort -n)'


But it doesn't work. Actually I tried also like this:

find ~/Music -iname "*$1*" -type d -exec cd {} \;

and once moved in that directory, simply type mplayer plus the suitable option to play directories and possible subdirectories. But I noticed that the command cd cannot be the argument of -exec.

I tried in different ways but I still cannot obtain the desired result.
Does someone know how to help me?
Thank you all.

Last edited by emmeteo; 11-22-2012 at 11:00 AM.
 
Old 11-22-2012, 12:02 PM   #12
emmeteo
LQ Newbie
 
Registered: May 2012
Posts: 25

Original Poster
Rep: Reputation: Disabled
I've found the answer.
If someone is interested, here it is:


#search and play by folder
play2()
{
cd "`find ~/Music -iname "*$1*" -type d | sed 1q`" && mplayer -afm mp3lib -shuffle -playlist <(find "play2" -type f|sort -n)
}
alias band='play2'


so you just type "band partial_name_of_the_folder", and the music inside that folder starts.
ciao

Last edited by emmeteo; 11-22-2012 at 12:35 PM.
 
1 members found this post helpful.
Old 11-22-2012, 03:12 PM   #13
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Nicely done. You no longer qualify to post in the newbie forum :-)
I will merely point out that the `backticks` syntax is deprecated, and the preferred method of command substitution is now the $( dollars-parens ) format. The modern method has the advantage of being able to nest multiple command substitutions, and doesn't get mangled by text formatters when publishing.

--- rod.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Enable composite onda_trollet Linux - General 4 12-26-2009 06:32 AM
Composite numbers in C DjPan Programming 9 11-25-2007 01:38 PM
Composite EXT does not work vargadanis Ubuntu 1 12-21-2006 09:28 AM
Trouble with Composite Manager??? rjohnson244 Linux - Software 2 05-20-2005 10:46 PM
Composite Out Stephanie Linux - General 1 08-07-2001 09:41 PM


All times are GMT -5. The time now is 07:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration