Advertisement
metalx1000

Playing Youtube Videos with MPV

Sep 11th, 2022
1,454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.66 KB | Source Code | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2022  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. dir="$HOME/.fbk"
  21. history_file="$dir/ytplay.hst"
  22. mkdir -p "$dir"
  23.  
  24. function add2history(){
  25.   echo ": $(date +%s):0;$0 '$url'" >> $HOME/.zsh_history
  26.   title="$(youtube-dl --skip-download --print-json --no-warnings "$url"|jq .title)"
  27.   echo "$(date +%s)|$title|$url" >> $history_file
  28.   notify-send -t 3000 --icon=video-television "Playing Video" "$title\n$url";
  29. }
  30.  
  31. function viewhistory(){
  32.   cat "$history_file"|\
  33.     grep "http"|\
  34.     fzf|\
  35.     sort -r|\
  36.     cut -d\| -f3
  37. }
  38.  
  39. [[ "$1" == "history" ]] && url="$(viewhistory)"
  40.  
  41. [[ $url != *"http"* ]] && url="$(xclip -selection "clipboard" -o)"
  42. [[ $url != *"http"* ]] && exit 1
  43.  
  44. notify-send -t 1000 --icon=video-television "Loading Video" "$url";
  45. add2history "$url" &
  46.  
  47. mpv --ytdl-format=22 --fs "$url" ||\
  48.   mpv --ytdl-format=18 --fs "$url" ||\
  49.   mpv --fs "$url"
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement