LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 07-19-2015, 11:49 PM   #1
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
Bash one liner '[1]+ Stopped'


I've made up a one liner to play youtube videos but am stumped why it wants to go into Stopped

Code:
pyt() { youtube-dl -q --max-downloads 1 --no-playlist 'https://www.youtube.com/watch?v='$(curl -s 'https://www.youtube.com/results?search_query='$(echo $1 | tr ' ' +) | grep -oe '"[[:alnum:]]\{11\}"' | sed -n 3p | cut -b 2-12) -o - | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; }
Some output

Code:
pyt() { youtube-dl -q --max-downloads 1 --no-playlist 'https://www.youtube.com/watch?v='$(curl 'https://www.youtube.com/results?search_query='$(echo $1 | tr ' ' +) | grep -oe '"[[:alnum:]]\{11\}"' | sed -n 3p | cut -b 2-12) -o - | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; }
+ pyt() { youtube-dl -q --max-downloads 1 --no-playlist 'https://www.youtube.com/watch?v='$(curl 'https://www.youtube.com/results?search_query='$(echo $1 | tr ' ' +) | grep -oe '"[[:alnum:]]\{11\}"' | sed -n 3p | cut -b 2-12) -o - | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; }

pyt 'Nightmare on Wax - You Wish'
+ pyt 'Nightmare on Wax - You Wish'
+ mplayer -vo null /dev/fd/3
curl 'https://www.youtube.com/results?search_query='$(echo $1 | tr ' ' +) | grep -oe '"[[:alnum:]]\{11\}"' | sed -n 3p | cut -b 2-12
++ grep --colour=auto -oe '"[[:alnum:]]\{11\}"'
++ sed -n 3p
echo $1 | tr ' ' +
++ cut -b 2-12
+++ echo Nightmare on Wax - You Wish
+++ tr ' ' +
++ curl 'https://www.youtube.com/results?search_query=Nightmare+on+Wax+-+You+Wish'
   Total     Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:MPlayer 1.1-4.8 (C) 2000-2012 MPlayer Team
-- --:--:-- --:--:--     0
[1]+  Stopped                 youtube-dl -q --max-downloads 1 --no-playlist 'https://www.youtube.com/watch?v='$(curl 'https://www.youtube.com/results?search_query='$(echo $1 | tr ' ' +) | grep -oe '"[[:alnum:]]\{11\}"' | sed -n 3p | cut -b 2-12) -o - | mplayer -vo null /dev/fd/3 3<&0 < /dev/tty

fg
+ fg
youtube-dl -q --max-downloads 1 --no-playlist 'https://www.youtube.com/watch?v='$(curl 'https://www.youtube.com/results?search_query='$(echo $1 | tr ' ' +) | grep -oe '"[[:alnum:]]\{11\}"' | sed -n 3p | cut -b 2-12) -o - | mplayer -vo null /dev/fd/3 3<&0 < /dev/tty

Playing /dev/fd/3.
100  158k    0  158k    0     0    905      0 --:--:--  0:02:59 --:--:--   905
+ youtube-dl -q --max-downloads 1 --no-playlist 'https://www.youtube.com/watch?v=6Ew85HKMcyg' -o -

It looks like curl is stopping it. However, once I type fg, it starts going again and runs successfully. Normally, it's a misplaced & causing the problem but I'm stumped here.
Any ideas?

Last edited by Sefyir; 07-20-2015 at 12:12 AM.
 
Old 07-20-2015, 12:05 AM   #2
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Original Poster
Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
I "fixed" it with a workaround by moving the $() part behind the command setting it into its own variable.

Code:
pyt() { id=$(curl 'https://www.youtube.com/results?search_query='$(echo "$1" | tr ' ' +) | grep -o '"[[:alnum:]]\{11\}"' | sed -n 3p | cut -b 2-12); youtube-dl -q --max-downloads 1 --no-playlist 'https://www.youtube.com/watch?v='"$id" -o - | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; }
I guess there's some limitation in bash with too many pipes and sub-processes.

Last edited by Sefyir; 07-20-2015 at 12:08 AM.
 
Old 07-21-2015, 08:09 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
no limits on pipes or sub-processes (other than what ulimit -a would show).

I think you have a grouping error... between the quotes and the ). Normally, I would have also expected a syntax error as the sequence "-o -" makes it outside the subprocess handling all the rest...

It is possible that is also what remained attached to the terminal and caused the block as the previous commands would not have interpreted the "-o -"... and bash never saw it due to the sequence being blocked.

Removing the $( and ) would then have allowed bash to properly interpret the command sequence... and the "-o -" would have been handled.

Last edited by jpollard; 07-21-2015 at 08:11 AM.
 
Old 07-21-2015, 12:09 PM   #4
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Original Poster
Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
Quote:
Originally Posted by jpollard View Post
no limits on pipes or sub-processes (other than what ulimit -a would show).

I think you have a grouping error... between the quotes and the ). Normally, I would have also expected a syntax error as the sequence "-o -" makes it outside the subprocess handling all the rest...

It is possible that is also what remained attached to the terminal and caused the block as the previous commands would not have interpreted the "-o -"... and bash never saw it due to the sequence being blocked.

Removing the $( and ) would then have allowed bash to properly interpret the command sequence... and the "-o -" would have been handled.
Thank you for looking at this.
The expected result of
Code:
youtube-dl -q --max-downloads 1 --no-playlist 'https://www.youtube.com/watch?v='$(curl 'https://www.youtube.com/results?search_query='$(echo $1 | tr ' ' +) | grep -oe '"[[:alnum:]]\{11\}"' | sed -n 3p | cut -b 2-12) -o -
should translate to
youtube-dl -q --max-downloads 1 --no-playlist https://www.youtube.com/watch?v=Sy8iUI_ayuo -o -
This is supposed to pipe into mplayer. youtube-dl uses -o for output template and specifying - as stdout is supported. So it's not part of the subproccess but rather of the overall youtube-dl command.
I ended up placing the -o - behind the $() part - but this did not change anything.
Code:
pyt() { youtube-dl -q --max-downloads 1 --no-playlist -o - 'https://www.youtube.com/watch?v='$(curl -s 'https://www.youtube.com/results?search_query='$(echo $1 | tr ' ' +) | grep -oe '"[[:alnum:]]\{11\}"' | sed -n 3p | cut -b 2-12) | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; }
Quote:
I think you have a grouping error... between the quotes and the )
Unfortunately I've got a lot of quotes and closing parenthesis.. I'm not sure where you're indicating.
 
  


Reply



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
LXer: Add EXIF Metadata to Photos with a Bash One-Liner LXer Syndicated Linux News 0 05-14-2014 11:31 AM
bash script one liner cbtshare Linux - Newbie 3 01-23-2014 05:26 PM
[SOLVED] bash script problem -- pass complex *one-liner* to a variable RandyTech Linux - Newbie 12 01-27-2013 05:01 PM
LXer: bash one-liner, Get GPS location and street Address LXer Syndicated Linux News 2 08-05-2010 03:14 PM
paste, cut one liner conversation from bash to csh bioinformatics_guy Linux - Newbie 2 09-02-2009 10:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:10 AM.

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
Open Source Consulting | Domain Registration