# Zenity or YAD, for quick adding url to mpv-music list

**URL:** https://forum.maboxlinux.org/t/zenity-or-yad-for-quick-adding-url-to-mpv-music-list/2126
**Category:** Scripts, Tutorials & Tips
**Created:** [December 23, 2024, 9:22pm UTC](https://forum.maboxlinux.org/t/zenity-or-yad-for-quick-adding-url-to-mpv-music-list/2126 "2024-12-23T21:22:46Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![muzqs](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/muzqs/32/3702_2.png) [@muzqs](https://forum.maboxlinux.org/u/muzqs)
#### Post date: [December 23, 2024, 9:22pm UTC](https://forum.maboxlinux.org/t/zenity-or-yad-for-quick-adding-url-to-mpv-music-list/2126/1 "2024-12-23T21:22:46Z")

</div>

Another simple stupid script to quickly add url to mpv mb-music list.  
Sort url’s out afterwards.

Add this (or similar) at the end of the `yt_music_list.csv` file

```auto
UNSORTED,-

```

`script.sh`

```auto
#!/bin/bash

# File to append to
CSV_FILE="$HOME/.config/mabox/mb-music/yt_music_list.csv"

# Create the file if it doesn't exist
touch "$CSV_FILE"

# Get URL from user input (using zenity)
URL=$(zenity --entry --title="QUICK Add Youtube Url 
to radio-mpv list" --text="fill in like this: 
Band titel,<paste url here>" )

# Check if the user canceled the input
if [-z "$URL"]; then
    exit 0
fi

# Check for video or audio extensions
if true ; then
    # Get the current date and time
    DATE=$(date "+%Y-%m-%d %H:%M:%S")
    # Append to CSV file
    echo "$URL" >> "$CSV_FILE"
    zenity --info --title="URL Added" --text="The URL was added to $CSV_FILE."
else
    # Show an error message if the URL does not match
    zenity --error --title="Invalid URL" --text="The URL does not have a valid video or audio file extension."
fi

```

 ![Mabox_20241223-22-13-23](https://forum.maboxlinux.org/uploads/default/original/2X/e/e7f643488b6268c105246441b5a759dfdea934f4.png)

* * *

#### An impression on Vimeo.

[https://vimeo.com/1041822264?share=copy](https://vimeo.com/1041822264?share=copy)

🐦

---

<div class="post-metadata">

### Author: ![napcok](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/napcok/32/410_2.png) [@napcok](https://forum.maboxlinux.org/u/napcok)
#### Post date: [December 23, 2024, 11:00pm UTC](https://forum.maboxlinux.org/t/zenity-or-yad-for-quick-adding-url-to-mpv-music-list/2126/2 "2024-12-23T23:00:30Z")

</div>

Zenity is ok, … but YAD is great (Zenity on steroids) 😉

[https://yad-guide.ingk.se/](https://yad-guide.ingk.se/)

> **[GitHub - v1cont/yad: Yet Another Dialog](https://github.com/v1cont/yad/)**
>
> Yet Another Dialog

---

<div class="post-metadata">

### Author: ![muzqs](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/muzqs/32/3702_2.png) [@muzqs](https://forum.maboxlinux.org/u/muzqs)
#### Post date: [December 24, 2024, 9:29am UTC](https://forum.maboxlinux.org/t/zenity-or-yad-for-quick-adding-url-to-mpv-music-list/2126/3 "2024-12-24T09:29:38Z")

</div>

It was a spontanius action. It liked the idea of quick adding the urls.  
But i will have a look at yad 😉

---

<div class="post-metadata">

### Author: ![napcok](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/napcok/32/410_2.png) [@napcok](https://forum.maboxlinux.org/u/napcok)
#### Post date: [December 24, 2024, 9:43am UTC](https://forum.maboxlinux.org/t/zenity-or-yad-for-quick-adding-url-to-mpv-music-list/2126/4 "2024-12-24T09:43:33Z")

</div>

> [@muzqs](#):
>
> It liked the idea of quick adding the urls.

It is already there…

 ![Mabox_20241224-10-32-43](https://forum.maboxlinux.org/uploads/default/original/2X/1/1ff3d4815ae3ad0ce53fc699fe35573330c8231d.avif)

Alt + PgUP, Alt + PgDOWN to move lines up or down quickly.

---

<div class="post-metadata">

### Author: ![muzqs](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/muzqs/32/3702_2.png) [@muzqs](https://forum.maboxlinux.org/u/muzqs)
#### Post date: [December 24, 2024, 10:00am UTC](https://forum.maboxlinux.org/t/zenity-or-yad-for-quick-adding-url-to-mpv-music-list/2126/5 "2024-12-24T10:00:53Z")

</div>

I am aware of the geany method,  
Thats fine for fine-tuning. Reoganising list.  
And absolutly enough 😉

But sometimes i am to restles 🌀 to copy paste lines and comma’s with geany  
I can be in a flow of collecting new streams, and like to add them easie and quick.

Some streams don’t work and so i can quickly test first if everything is fine.  
I stop using Invidious links. They not always stream.

🐦

---

<div class="post-metadata">

### Author: ![muzqs](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/muzqs/32/3702_2.png) [@muzqs](https://forum.maboxlinux.org/u/muzqs)
#### Post date: [December 24, 2024, 11:49am UTC](https://forum.maboxlinux.org/t/zenity-or-yad-for-quick-adding-url-to-mpv-music-list/2126/6 "2024-12-24T11:49:42Z")

</div>

Yad version: To quickly add url to mb-music mpv list cvs.

- Create hotkey for quick launch.
- Copy url and launch script. Url should be pasted in field automaticly.

 ![Mabox_20241224-12-42-46](https://forum.maboxlinux.org/uploads/default/original/2X/4/48916435f85e1fe191bea846f30241bcaec89b9c.png) ![Mabox_20241224-12-47-14](https://forum.maboxlinux.org/uploads/default/original/2X/2/212aa0d971fc5e35f7d380d313ef2ac9e7f3ba81.png)

Script.sh

```auto
#!/bin/bash

# File to append to
CSV_FILE="$HOME/.config/mabox/mb-music/yt_music_list.csv"

# Create the file if it doesn't exist
touch "$CSV_FILE"

# Get clipboard content (requires xclip)
CLIPBOARD=$(xclip -o -selection clipboard)

# Check if clipboard is empty or does not contain a valid URL
if [[-z "$CLIPBOARD" || ! "$CLIPBOARD" =~ ^https?://]]; then

            yad --warning --title="Clipboard Invalid" \
                --window-icon="media-tape"\
                --image="dialog-error"\
                --text="The clipboard does not contain a valid URL. 
Please copy a URL and try again."
    exit 1
fi

# Get artist, title, and URL from user input using yad
ENTRY=$(yad --form --title="Add Stream to Mabox mpv List." \
    --window-icon="media-tape"\
    --image="document-save"\
    --text="Please provide the following details to add stream to the list : \n\n\
Only fill in Category to start new one:"\
            --field="URL :":TEXT "$CLIPBOARD" \
            --field="Artist :":TEXT \
            --field="Title :":TEXT \
            --field="Category :":TEXT )

# Check if the user canceled the input
if [-z "$ENTRY"]; then
    exit 0
fi

# Split the input into variables
URL=$(echo "$ENTRY" | cut -d '|' -f 1)
ARTIST=$(echo "$ENTRY" | cut -d '|' -f 2)
TITLE=$(echo "$ENTRY" | cut -d '|' -f 3)
CATEGORY=$(echo "$ENTRY" | cut -d '|' -f 4)

# Validate the input
if [-z "$ARTIST"] || [-z "$TITLE"] || [-z "$URL"] ; then
    yad --error --title="Invalid Input" --text="All fields must be filled."
    exit 1
fi

# Append to CSV file

if [-z "$CATEGORY"] ; then
echo "$ARTIST - $TITLE,$URL" >> "$CSV_FILE"
notify-send -i media-tape -t 50000 "$ARTIST - $TITLE" "Added to the playlist"
else
echo "$CATEGORY,-" >> "$CSV_FILE"
echo "$ARTIST - $TITLE,$URL" >> "$CSV_FILE"
notify-send -i media-tape -t 50000 "$ARTIST - $TITLE" "Added To $CATEGORY"
fi

```

🐦

Edit:

- replaced icons

Edit 2 : small changes

- A bit better flow
