-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamx_download
More file actions
69 lines (53 loc) · 3.19 KB
/
Copy pathamx_download
File metadata and controls
69 lines (53 loc) · 3.19 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
# ====================================================
# AMX_Manager Copyright(C) 2018 Furkan Türkal
# This program comes with ABSOLUTELY NO WARRANTY; This is free software,
# and you are welcome to redistribute it under certain conditions; See
# file LICENSE, which is part of this source code package, for details.
# ====================================================
#!/bin/bash
# Ref: https://github.com/metinUr/dotfiles/blob/master/opt/bin/dsong
# Ref: https://stackoverflow.com/a/47097185
# Check for required applications
command -v notify-send >/dev/null 2>&1 || { echo >&2 "AMX_Download: I require 'notify-send' but it's not installed! Aborting."; exit 1; }
command -v wmctrl >/dev/null 2>&1 || { echo >&2 "AMX_Download: I require 'wmctrl' but it's not installed! Aborting."; exit 1; }
command -v xdotool >/dev/null 2>&1 || { echo >&2 "AMX_Download: I require 'xdotool' but it's not installed! Aborting."; exit 1; }
command -v xclip >/dev/null 2>&1 || { echo >&2 "AMX_Download: I require 'xclip' but it's not installed! Aborting."; exit 1; }
command -v jq >/dev/null 2>&1 || { echo >&2 "AMX_Download: I require 'jq' but it's not installed! Aborting."; exit 1; }
command -v youtube-dl >/dev/null 2>&1 || { echo >&2 "AMX_Download: I require 'youtube-dl' but it's not installed! Aborting."; exit 1; }
main() {
case "$1" in
youtube-music)
id=$(wmctrl -l | grep -oP "(?<=)(0x\w+)(?=.*Chromium)")
if [ -z "$id" ]
then
notify-send -a 'AMX_Download' -u low "Chromium couldn't have found!"
else
xdotool windowactivate $id
xdotool key --window $id "CTRL+l"
xdotool key --window $id "CTRL+c"
URL=`xclip -o -selection clipboard`
if [[ $URL == https://www.youtube.com/watch?v=* ]] ;
then
notify-send -a 'AMX_Download' -u low -t 1500 "YouTube: Metadata is checking before download..."
youtube-dl --simulate --skip-download --print-json -x $URL > metadata
isMusic=$(jq -e '.categories | contains(["Music"])' metadata)
if [[ "$isMusic" == "false" ]];
then
notify-send -a 'AMX_Download' -u low -t 2000 "YouTube: Category is not Music!"
else
notify-send -a 'AMX_Download' -u low -t 1500 "YouTube: Music download is being started..."
youtube-dl -o "~/Music/%(title)s.%(ext)s" --no-part --no-mtime --xattrs --add-metadata --print-json --no-warnings --format m4a --audio-format best --audio-quality=320k -x $URL > data
title=$(jq -r ".title" data)
notify-send -a 'AMX_Download' -u low -t 2000 "YouTube: Download finished!" "'$title'"
fi
else
notify-send -a 'AMX_Download' -u low "YouTube: Given link must be a YouTube video!"
fi
fi
;;
*)
printf "amx_download <command>\n"
printf " youtube-music\n"
esac
}
main "$@"