LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories
User Name
Password
LinuxQuestions.org Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.

Notices


Reply
  Search this Thread
Old 07-15-2015, 04:16 PM   #1
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 573

Rep: Reputation: 264Reputation: 264Reputation: 264
Playing online music videos in terminal (one-liner)


Code:
pvl() { (for i in "$@"; do youtube-dl -q --max-downloads 1 --no-playlist "$i" -o - | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; sleep .5; done); }
This plays video files (youtube, vimeo, etc) isolated to the terminal, without video.

I'm particularly proud of this one since it solved a lot of things I've been stumped about. Plus - it really converges the online video media and cli together.
First off, there is no downloading to a file or any conversion of files. youtube-dl downloads and sends to stdout and is immediately caught by mplayer which then dumps any video elements (-vo null). This also avoids any need for a fifo and avoids costly conversion (ffmpeg -i - -f ogg -vn -)

If you've ever piped to mplayer, you've noticed that you cannot control it. Turns out with some redirection magic (/dev/fd/3 3<&0 </dev/tty), you can!

If you're inclined and have mplayer and youtube-dl installed, try it out.

Code:
Usage:
pvl 'link1' 'link2' 'link3'
http://www.commandlinefu.com/command...os-in-terminal
 
Old 08-18-2015, 10:35 AM   #2
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 1,928

Rep: Reputation: 278Reputation: 278Reputation: 278
If you want to use youtube-dl and mplayer then give this a try. It's
a little more versatile.

Code:
#! /usr/bin/env bash

# Youtube video-audio player and downloader. Requires youtube-dl and one
# of mplayer , mpv, ffplay

[ -d $HOME/Utube ] || mkdir $HOME/Utube
cd $HOME/Utube

PS3="
Select an option.:  "
					
while :; do
  clear
  options="Quit Formats Watch Listen Download"
    select opt in $options; do
      case $opt in
        Quit) clear; exit;;
		
        Formats) read -p "Paste Utube URL:  " form
          youtube-dl -F "$form"
			      	read -p "$Enter to continue.  "
				      break ;;

        Watch) read -p "Paste Utube video URL:  " view	
				      #youtube-dl -q -f 18 "$view" -o - | mpv -
			      	youtube-dl -q -f 18 "$view" -o - | mplayer -
				      #youtube-dl -q -f 18 "$view" -o - | ffplay -
			      	break ;;
			
        Listen) read -p "Paste Utube audio URL:  " aud
				      #youtube-dl -q -f 140 "$aud" -o - | mpv -
			      	youtube-dl -q -f 140 "$aud" -o - | mplayer -
				      #youtube-dl -q -f 140 "$aud" -o - | ffplay -
				      break ;;

        Download) read -p "Paste Utube URL:  " dl
				      read -p "What format number?  Ex: 0 18 22 140:  " fmat
				      num=1
				     	  until [ ! -e ut$num.* ]; do
					        	num=$(($num + 1))
					       done
				      youtube-dl -q -f "$fmat" "$dl" -o ut"$num"."%(ext)s"
				      break ;;
      esac
    done
done
 
  


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
LXer: MOC - Playing Music in the Terminal LXer Syndicated Linux News 0 03-25-2014 12:40 AM
Videos not playing. paulie_linux Linux - Newbie 10 12-08-2013 09:44 AM
Install Codec for playing Music & Videos for the first time in Ubuntu/Linux st_tht Linux - Newbie 11 06-01-2013 09:35 AM
Easy script that update webpage, to show online, skype online, music playing? frenchn00b Debian 1 04-07-2008 03:12 AM
playing two videos at once. Moebius Linux - Software 1 07-09-2003 05:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories

All times are GMT -5. The time now is 09:45 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration