LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   LinuxQuestions.org Member Success Stories (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/)
-   -   Playing online music videos in terminal (one-liner) (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/playing-online-music-videos-in-terminal-one-liner-4175548091/)

Sefyir 07-15-2015 04:16 PM

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

teckk 08-18-2015 10:35 AM

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



All times are GMT -5. The time now is 10:54 PM.