-
Notifications
You must be signed in to change notification settings - Fork 0
/
ytpg-gui.sh
107 lines (86 loc) · 2.92 KB
/
ytpg-gui.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
# Function to append video URLs to the array
add_video_urls() {
local video_urls=$1
all_video_urls+=("$video_urls")
}
# Function to generate the playlist
generate_playlist() {
# Array to store all video URLs
all_video_urls=()
# Iterate over each playlist ID
for playlist_id in "${playlist_ids[@]}"; do
# Use youtube-dl to fetch video URLs from the playlist
video_urls=$(yt-dlp --get-url --flat-playlist "https://www.youtube.com/playlist?list=$playlist_id")
# Append video URLs to the array
add_video_urls "$video_urls"
done
# Iterate over each channel ID
for channel_id in "${channel_ids[@]}"; do
# Use youtube-dl to fetch video URLs from the channel
video_urls=$(yt-dlp --get-url --flat-playlist "https://www.youtube.com/channel/$channel_id/videos")
# Append video URLs to the array
add_video_urls "$video_urls"
done
# Append live stream URLs to the array
add_video_urls "${live_stream_urls[@]}"
# Combine all video URLs into a single string
combined_video_urls=$(printf "%s\n" "${all_video_urls[@]}")
# Shuffle the video URLs if enabled
if [ "$shuffle_enabled" = true ]; then
shuffled_urls=$(echo "$combined_video_urls" | shuf)
else
shuffled_urls="$combined_video_urls"
fi
# Create or overwrite the playlist file
if [ "$overwrite_playlist" = true ]; then
echo "#EXTM3U" > "$playlist_file"
fi
# Write video URLs to the playlist file
echo "$shuffled_urls" >> "$playlist_file"
# Show dialog message when playlist is built
zenity --info --text="Playlist has been built!" --title="Playlist Built"
}
# GUI elements
playlist_ids=""
channel_ids=""
live_stream_urls=""
shuffle_enabled=""
overwrite_playlist=""
# Function to show the GUI and capture user input
show_gui() {
# Show the GUI elements and capture user input
input=$(zenity --forms --title="YouTube Playlist Generator" --text="Enter YouTube Playlist, Channel, and Live Stream Details" \
--add-entry="Playlist IDs:" \
--add-entry="Channel IDs:" \
--add-entry="Live Stream URLs:" \
--add-combo="Shuffle Playlist:" --combo-values="Yes|No" \
--add-combo="Existing Playlist:" --combo-values="Add to Playlist|Overwrite Playlist" \
--separator="|"
)
# Handle Cancel button or window close event
if [ $? -ne 0 ]; then
exit 0
fi
IFS='|' read -r playlist_ids channel_ids live_stream_urls shuffle_enabled overwrite_playlist <<< "$input"
playlist_ids=($playlist_ids)
channel_ids=($channel_ids)
live_stream_urls=($live_stream_urls)
# Convert combo box values to boolean variables
if [ "$shuffle_enabled" = "Yes" ]; then
shuffle_enabled=true
else
shuffle_enabled=false
fi
if [ "$overwrite_playlist" = "Overwrite Playlist" ]; then
overwrite_playlist=true
else
overwrite_playlist=false
fi
}
# Show the GUI and capture user input
show_gui
# Set the playlist file path
playlist_file="$HOME/playlist.m3u"
# Generate the playlist
generate_playlist