Repository navigation
Expand file tree
/
Copy pathplay.sh
More file actions
680 lines (559 loc) 路 19.3 KB
/
Copy pathplay.sh
File metadata and controls
680 lines (559 loc) 路 19.3 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
#!/usr/bin/env bash
# ============================================================
# play.sh - Video Forensics / Analysis Toolkit
# ============================================================
# ---------- Colors ----------
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
WHITE='\033[1;37m'
GRAY='\033[0;90m'
RESET='\033[0m'
# ---------- Paths / Configuration ----------
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
YTDLP_LOCAL="${SCRIPT_DIR}/yt-dlp_linux"
YTDLP_SYSTEM="/usr/local/bin/yt-dlp"
YTDLP_URL="https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux"
# ============================================================
# Display Helpers
# ============================================================
header() {
clear
echo -e "${CYAN}"
echo "============================================================"
echo " VIDEO TOOLKIT"
echo "============================================================"
echo -e "${RESET}"
}
pause_menu() {
echo
read -rp "Press ENTER to continue..."
}
# ============================================================
# Help
# ============================================================
show_help() {
header
echo -e "${WHITE}Usage:${RESET}"
echo
echo " $0"
echo " Open the video toolkit menu."
echo
echo " $0 <video_file>"
echo " Open the video toolkit for a specific video."
echo
echo " $0 --yt-dlp"
echo " $0 -y"
echo " Open the yt-dlp toolkit."
echo
echo " $0 --help"
echo " $0 -h"
echo " Show this help menu."
echo
echo -e "${WHITE}Video Toolkit:${RESET}"
echo
echo -e " ${CYAN}1${RESET}) Play video"
echo -e " ${CYAN}2${RESET}) Convert video to MP4"
echo -e " ${CYAN}3${RESET}) Extract video frames"
echo -e " ${CYAN}4${RESET}) Extract audio as MP3"
echo -e " ${CYAN}5${RESET}) Rotate video 90 degrees"
echo -e " ${CYAN}6${RESET}) Show video information"
echo -e " ${CYAN}7${RESET}) yt-dlp tools"
echo -e " ${CYAN}8${RESET}) Exit"
echo
echo -e "${WHITE}yt-dlp Toolkit:${RESET}"
echo
echo -e " ${CYAN}1${RESET}) List available video/audio formats"
echo -e " ${CYAN}2${RESET}) List available subtitles/captions"
echo -e " ${CYAN}3${RESET}) Download English auto-generated subtitles"
echo -e " ${CYAN}4${RESET}) Download latest yt-dlp Linux binary"
echo -e " ${CYAN}5${RESET}) Install yt-dlp to /usr/local/bin/"
echo -e " ${CYAN}6${RESET}) Show installed yt-dlp version"
echo -e " ${CYAN}7${RESET}) Return"
echo
echo -e "${WHITE}Dependencies:${RESET}"
echo
echo " Video toolkit:"
echo " ffmpeg"
echo " ffplay"
echo " ffprobe"
echo
echo " yt-dlp download:"
echo " curl or wget"
echo
echo -e "${WHITE}Examples:${RESET}"
echo
echo " $0"
echo " $0 evidence.mp4"
echo " $0 recording.webm"
echo " $0 --yt-dlp"
echo " $0 --help"
echo
}
# ============================================================
# Dependency Checks
# ============================================================
check_video_dependencies() {
local cmd
for cmd in ffmpeg ffplay ffprobe; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo -e "${RED}[ERROR]${RESET} $cmd is not installed."
return 1
fi
done
return 0
}
# ============================================================
# yt-dlp Functions
# ============================================================
find_ytdlp() {
if [[ -x "$YTDLP_LOCAL" ]]; then
printf '%s\n' "$YTDLP_LOCAL"
return 0
fi
if [[ -x "$YTDLP_SYSTEM" ]]; then
printf '%s\n' "$YTDLP_SYSTEM"
return 0
fi
if command -v yt-dlp >/dev/null 2>&1; then
command -v yt-dlp
return 0
fi
return 1
}
download_ytdlp() {
local temp_file
echo -e "${GREEN}[+] Downloading latest yt-dlp Linux binary...${RESET}"
echo
echo -e " Source: ${CYAN}${YTDLP_URL}${RESET}"
echo
temp_file="$(mktemp "${TMPDIR:-/tmp}/yt-dlp_linux.XXXXXX")" || {
echo -e "${RED}[!] Could not create temporary file.${RESET}"
return 1
}
if command -v curl >/dev/null 2>&1; then
echo -e "${GREEN}[+] Using curl...${RESET}"
if ! curl -fL --progress-bar "$YTDLP_URL" -o "$temp_file"; then
echo -e "${RED}[!] Failed to download yt-dlp.${RESET}"
rm -f "$temp_file"
return 1
fi
elif command -v wget >/dev/null 2>&1; then
echo -e "${GREEN}[+] Using wget...${RESET}"
if ! wget --show-progress "$YTDLP_URL" -O "$temp_file"; then
echo -e "${RED}[!] Failed to download yt-dlp.${RESET}"
rm -f "$temp_file"
return 1
fi
else
echo -e "${RED}[ERROR] Neither curl nor wget is installed.${RESET}"
rm -f "$temp_file"
return 1
fi
chmod +x "$temp_file"
if [[ ! -x "$temp_file" ]]; then
echo -e "${RED}[!] Downloaded file could not be made executable.${RESET}"
rm -f "$temp_file"
return 1
fi
if ! mv -f "$temp_file" "$YTDLP_LOCAL"; then
echo -e "${RED}[!] Could not move yt-dlp into:${RESET} $YTDLP_LOCAL"
rm -f "$temp_file"
return 1
fi
echo
echo -e "${GREEN}[+] yt-dlp downloaded successfully.${RESET}"
echo -e " Location: ${CYAN}${YTDLP_LOCAL}${RESET}"
echo -e " Version: ${CYAN}$("$YTDLP_LOCAL" --version)${RESET}"
return 0
}
ensure_ytdlp() {
local ytdlp
ytdlp="$(find_ytdlp)" || true
if [[ -n "$ytdlp" ]]; then
printf '%s\n' "$ytdlp"
return 0
fi
echo -e "${YELLOW}[!] yt-dlp is not installed.${RESET}" >&2
echo >&2
read -rp "Download the latest Linux binary now? [Y/n]: " download
if [[ "$download" =~ ^[Nn]$ ]]; then
return 1
fi
if download_ytdlp >&2; then
printf '%s\n' "$YTDLP_LOCAL"
return 0
fi
return 1
}
install_ytdlp_systemwide() {
local ytdlp
echo -e "${GREEN}[+] Installing yt-dlp system-wide...${RESET}"
echo -e " Destination: ${CYAN}${YTDLP_SYSTEM}${RESET}"
echo
ytdlp="$(find_ytdlp)" || true
if [[ -z "$ytdlp" ]]; then
echo -e "${YELLOW}[!] yt-dlp is not currently installed.${RESET}"
read -rp "Download the latest binary first? [Y/n]: " download_first
if [[ "$download_first" =~ ^[Nn]$ ]]; then
echo -e "${YELLOW}[!] Installation cancelled.${RESET}"
return 1
fi
if ! download_ytdlp; then
return 1
fi
ytdlp="$YTDLP_LOCAL"
fi
echo
echo -e "${YELLOW}[!] sudo privileges are required.${RESET}"
echo
if sudo install -m 0755 "$ytdlp" "$YTDLP_SYSTEM"; then
echo
echo -e "${GREEN}[+] yt-dlp installed successfully.${RESET}"
echo -e " Location: ${CYAN}${YTDLP_SYSTEM}${RESET}"
echo -e " Version: ${CYAN}$("$YTDLP_SYSTEM" --version)${RESET}"
return 0
fi
echo -e "${RED}[!] Failed to install yt-dlp system-wide.${RESET}"
return 1
}
# ============================================================
# yt-dlp Menu
# ============================================================
ytdlp_menu() {
while true; do
clear
echo -e "${CYAN}"
echo "============================================================"
echo " yt-dlp TOOLS"
echo "============================================================"
echo -e "${RESET}"
echo -e " ${CYAN}1${RESET}) List available video/audio formats"
echo -e " ${CYAN}2${RESET}) List available subtitles/captions"
echo -e " ${CYAN}3${RESET}) Download English auto-generated subtitles"
echo -e " ${CYAN}4${RESET}) Download latest yt-dlp Linux binary"
echo -e " ${CYAN}5${RESET}) Install yt-dlp to /usr/local/bin/"
echo -e " ${CYAN}6${RESET}) Show installed yt-dlp version"
echo -e " ${CYAN}7${RESET}) Return"
echo
echo -e "${YELLOW}------------------------------------------------------------${RESET}"
read -rp "Choose an option [1-7]: " choice
echo
case "$choice" in
1)
local ytdlp url
ytdlp="$(ensure_ytdlp)" || {
pause_menu
continue
}
read -rp "Enter video URL: " url
if [[ -z "$url" ]]; then
echo -e "${RED}[!] No URL provided.${RESET}"
pause_menu
continue
fi
echo
echo -e "${GREEN}[+] Available formats:${RESET}"
echo
"$ytdlp" -F "$url"
pause_menu
;;
2)
local ytdlp url
ytdlp="$(ensure_ytdlp)" || {
pause_menu
continue
}
read -rp "Enter video URL: " url
if [[ -z "$url" ]]; then
echo -e "${RED}[!] No URL provided.${RESET}"
pause_menu
continue
fi
echo
echo -e "${GREEN}[+] Available subtitles/captions:${RESET}"
echo
"$ytdlp" --list-subs "$url"
pause_menu
;;
3)
local ytdlp url
ytdlp="$(ensure_ytdlp)" || {
pause_menu
continue
}
read -rp "Enter video URL: " url
if [[ -z "$url" ]]; then
echo -e "${RED}[!] No URL provided.${RESET}"
pause_menu
continue
fi
echo
echo -e "${GREEN}[+] Downloading English auto-generated subtitles...${RESET}"
echo
if "$ytdlp" \
--write-auto-subs \
--sub-langs "en" \
--convert-subs srt \
"$url"; then
echo
echo -e "${GREEN}[+] Subtitle download complete.${RESET}"
else
echo
echo -e "${RED}[!] Subtitle download failed.${RESET}"
fi
pause_menu
;;
4)
download_ytdlp
pause_menu
;;
5)
install_ytdlp_systemwide
pause_menu
;;
6)
local ytdlp
ytdlp="$(find_ytdlp)" || true
if [[ -z "$ytdlp" ]]; then
echo -e "${YELLOW}[!] yt-dlp is not currently installed.${RESET}"
else
echo -e "${GREEN}[+] yt-dlp executable:${RESET}"
echo -e " ${CYAN}${ytdlp}${RESET}"
echo
echo -e "${GREEN}[+] Version:${RESET}"
"$ytdlp" --version
fi
pause_menu
;;
7)
return
;;
*)
echo -e "${RED}[!] Invalid selection.${RESET}"
sleep 1
;;
esac
done
}
# ============================================================
# Video Toolkit
# ============================================================
video_toolkit() {
local video="$1"
local filename name extension
if [[ ! -f "$video" ]]; then
echo -e "${RED}[ERROR]${RESET} File not found: $video"
return 1
fi
if ! check_video_dependencies; then
return 1
fi
filename="$(basename "$video")"
name="${filename%.*}"
extension="${filename##*.}"
while true; do
header
echo -e "${GREEN}Input:${RESET} $filename"
echo -e "${GREEN}Format:${RESET} $extension"
echo
echo -e "${YELLOW}------------------------------------------------------------${RESET}"
echo -e "${WHITE}Select an operation:${RESET}"
echo
echo -e " ${CYAN}1${RESET}) Play video"
echo -e " ${CYAN}2${RESET}) Convert video to MP4"
echo -e " ${CYAN}3${RESET}) Extract video frames"
echo -e " ${CYAN}4${RESET}) Extract audio as MP3"
echo -e " ${CYAN}5${RESET}) Rotate video 90 degrees"
echo -e " ${CYAN}6${RESET}) Show video information"
echo -e " ${CYAN}7${RESET}) yt-dlp tools"
echo -e " ${CYAN}8${RESET}) Exit"
echo
echo -e "${YELLOW}------------------------------------------------------------${RESET}"
read -rp "Choose an option [1-8]: " choice
echo
case "$choice" in
1)
echo -e "${GREEN}[+] Playing:${RESET} $video"
echo
ffplay "$video"
pause_menu
;;
2)
local output="${name}.mp4"
echo -e "${GREEN}[+] Converting:${RESET}"
echo -e " $video ${CYAN}->${RESET} $output"
echo
if [[ -e "$output" ]]; then
read -rp "$output already exists. Overwrite? [y/N]: " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
echo -e "${YELLOW}[!] Conversion cancelled.${RESET}"
pause_menu
continue
fi
fi
if ffmpeg -i "$video" -vcodec mpeg4 "$output"; then
echo
echo -e "${GREEN}[+] Conversion complete:${RESET} $output"
else
echo
echo -e "${RED}[!] Conversion failed.${RESET}"
fi
pause_menu
;;
3)
local frame_dir="${name}_frames"
local frame_count
echo -e "${GREEN}[+] Frame extraction${RESET}"
echo
echo "This will extract 10 frames per second."
echo
echo -e "Frames will be stored in:"
echo -e " ${CYAN}${frame_dir}/${RESET}"
echo
if [[ -d "$frame_dir" ]]; then
echo -e "${YELLOW}[!] Directory already exists:${RESET} $frame_dir"
read -rp "Use this directory? [Y/n]: " use_existing
if [[ "$use_existing" =~ ^[Nn]$ ]]; then
echo -e "${YELLOW}[!] Frame extraction cancelled.${RESET}"
pause_menu
continue
fi
else
read -rp "Create this directory? [Y/n]: " create_dir
if [[ "$create_dir" =~ ^[Nn]$ ]]; then
echo -e "${YELLOW}[!] Frame extraction cancelled.${RESET}"
pause_menu
continue
fi
mkdir -p "$frame_dir" || {
echo -e "${RED}[!] Could not create directory.${RESET}"
pause_menu
continue
}
fi
echo
echo -e "${GREEN}[+] Extracting frames...${RESET}"
echo
if ffmpeg -y \
-i "$video" \
-map 0:v:0 \
-an \
-vf fps=10 \
"$frame_dir/img%06d.bmp"; then
frame_count="$(find "$frame_dir" -type f -name '*.bmp' | wc -l)"
echo
echo -e "${GREEN}[+] Frame extraction complete.${RESET}"
echo -e " Frames created: ${WHITE}${frame_count}${RESET}"
echo -e " Location: ${CYAN}${frame_dir}/${RESET}"
else
echo
echo -e "${RED}[!] Frame extraction failed.${RESET}"
fi
pause_menu
;;
4)
local output="${name}.mp3"
echo -e "${GREEN}[+] Extracting audio:${RESET}"
echo -e " $video ${CYAN}->${RESET} $output"
echo
if [[ -e "$output" ]]; then
read -rp "$output already exists. Overwrite? [y/N]: " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
echo -e "${YELLOW}[!] Audio extraction cancelled.${RESET}"
pause_menu
continue
fi
fi
if ffmpeg -i "$video" \
-vn \
-ac 2 \
-ar 44100 \
-b:a 320k \
-f mp3 \
"$output"; then
echo
echo -e "${GREEN}[+] Audio extraction complete:${RESET} $output"
else
echo
echo -e "${RED}[!] Audio extraction failed.${RESET}"
fi
pause_menu
;;
5)
local output="${name}_rotated.mp4"
echo -e "${GREEN}[+] Rotating video 90 degrees:${RESET}"
echo -e " $video ${CYAN}->${RESET} $output"
echo
if [[ -e "$output" ]]; then
read -rp "$output already exists. Overwrite? [y/N]: " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
echo -e "${YELLOW}[!] Rotation cancelled.${RESET}"
pause_menu
continue
fi
fi
if ffmpeg -i "$video" -vf transpose=0 "$output"; then
echo
echo -e "${GREEN}[+] Rotation complete:${RESET} $output"
else
echo
echo -e "${RED}[!] Rotation failed.${RESET}"
fi
pause_menu
;;
6)
echo -e "${GREEN}[+] Video information${RESET}"
echo
ffprobe "$video"
pause_menu
;;
7)
ytdlp_menu
;;
8)
echo -e "${CYAN}Exiting video toolkit.${RESET}"
return 0
;;
*)
echo -e "${RED}[!] Invalid selection.${RESET}"
sleep 1
;;
esac
done
}
# ============================================================
# Program Entry Point
# ============================================================
case "${1:-}" in
-h|--help|help)
show_help
;;
-y|--yt-dlp)
ytdlp_menu
;;
"")
# No argument now behaves like --help.
show_help
;;
-*)
echo -e "${RED}[ERROR]${RESET} Unknown option: $1"
echo
echo "Run:"
echo " $0 --help"
exit 1
;;
*)
if [[ $# -ne 1 ]]; then
echo -e "${RED}[ERROR]${RESET} Too many arguments."
echo
echo "Run:"
echo " $0 --help"
exit 1
fi
video_toolkit "$1"
;;
esac