From ca1543a2eacaefa2fd99fb2c13fe7010e017b7f4 Mon Sep 17 00:00:00 2001 From: elenapan Date: Thu, 19 Sep 2019 09:57:37 +0300 Subject: [PATCH] Added rofi_mpvtube script Former-commit-id: abbce4b7136600abe43cd947757dcf53e319d864 Former-commit-id: f65c50c8c61a38c383cd3871e15c59cf45ee3a79 Former-commit-id: f4874e81086111e4f1cc756b8e34fe98c731fd2c Former-commit-id: f2d7e81118480195d9f8392fcdb170e844095783 --- bin/rofi_mpvtube | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 bin/rofi_mpvtube diff --git a/bin/rofi_mpvtube b/bin/rofi_mpvtube new file mode 100755 index 0000000..450ca8c --- /dev/null +++ b/bin/rofi_mpvtube @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +# ~·~·~·~·~·~·~·~·~·~·~·~·~ +# Author: elenapan @ github +# ~·~·~·~·~·~·~·~·~·~·~·~·~ +# Rofi menu for playing a youtube video, playlist or stream on mpv +# Requirements: +# - youtube-dl +# - mpv +# - notify-send (optionally for notifications) +# +# The playlist file format should be as follows (example): +# Your Playlist @ +# Your Other Playlist @ +# ... +# Electro Swing @https://www.youtube.com/watch?v=d1vQMIisJuc&list=RDd1vQMIisJuc +# ... +# You can also add single videos or live streams to the playlist file. +# It should work as long as the URL is valid. + +# ~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~· +# ~·~·~·~·~·~·~ User configuration ·~·~·~·~·~·~·~· +# ~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~· + +# Playlist file +playlist_file=/home/elena/.config/mpv/mpvtube_playlists +# playlist_file=/path/to/your/mpvtube_playlists + +# Arguments that will be passed to mpv +mpv_args="-shuffle --ytdl-raw-options=yes-playlist= --force-window=immediate" + +# Use this if you only need audio +# mpv_args="--no-video -shuffle" + +# Rofi prompt +rofi_prompt="YouTube ❯" +# ~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~· + + +# Grab the playlist names from the file +get_playlists() { + while read -r LINE + do + playlist_name="$(echo $LINE | cut -d "@" -f 1)" + echo $playlist_name + done < "$playlist_file" +} + +main() { + # Get choice from rofi + choice=$( (get_playlists) | rofi -dmenu -i -fuzzy -p "$rofi_prompt" ) + + # If user has not picked anything, exit + if [[ -z "${choice// }" ]]; then + exit 1 + fi + + # Get URL + linktoplay="$(grep -m 1 "$choice" $playlist_file | cut -d '@' -f 2)" + # If the choice does not exist, exit + if [ ${#linktoplay} -eq "0" ]; then + exit 1 + fi + + # Send notification + notify-send "YouTube - Loading:" "$choice" + + # Spawn mpv + mpv $mpv_args "$linktoplay" +} + +main & + +exit 0 +