Compare commits
3 Commits
31aede8e95
...
6294649b5a
| Author | SHA1 | Date | |
|---|---|---|---|
| 6294649b5a | |||
| e2f1478fec | |||
| c3ea47b305 |
61
md
61
md
@ -1,8 +1,9 @@
|
||||
#!/bin/sh
|
||||
checkMetadata() {
|
||||
ffprobe "$1" 2>&1 | grep -e artist -e title
|
||||
ffprobe "$1" 2>&1 | grep -ie artist -e title
|
||||
while true; do
|
||||
read -p "correct metadata? [Y] | [n]: " yn
|
||||
printf "correct metadata? [Y] | [n]: "
|
||||
read -r yn < /dev/tty
|
||||
case "$yn" in
|
||||
[Yy]* ) return 0;;
|
||||
[Nn]* ) return 1;;
|
||||
@ -10,28 +11,40 @@ checkMetadata() {
|
||||
esac
|
||||
done
|
||||
}
|
||||
cd ~/Medien/Musik/2020
|
||||
download_dir="$(mktemp -d)"
|
||||
file_name="$(youtube-dl "ytsearch:$1 lyrics" \
|
||||
--extract-audio \
|
||||
--output "$download_dir/%(title)s.%(ext)s" \
|
||||
--metadata-from-title "%(artist)s - %(title)s" \
|
||||
--audio-quality 0 \
|
||||
--audio-format mp3 \
|
||||
--embed-thumbnail \
|
||||
--add-metadata \
|
||||
|awk '$1 == "[ffmpeg]" && $2 == "Destination:" {print substr($0, index($0,$3))}')"
|
||||
r128gain "$file_name" 2> /dev/null
|
||||
temp_dir="$(mktemp -d)"
|
||||
temp_file="$temp_dir/0.mp3"
|
||||
cp "$file_name" "$temp_file"
|
||||
idntag "$temp_file"
|
||||
temp_file=$(echo "$temp_dir"/*)
|
||||
if checkMetadata "$temp_file"; then
|
||||
mv "$temp_file" .
|
||||
elif checkMetadata "$file_name"; then
|
||||
mv "$file_name" .
|
||||
else
|
||||
echo "enter it manually"
|
||||
fi
|
||||
for song in "$@"; do
|
||||
file_name="$(youtube-dl "ytsearch:$song lyrics" \
|
||||
-f bestaudio/best \
|
||||
--output "$download_dir/%(title)s.%(ext)s" \
|
||||
--metadata-from-title "%(artist)s - %(title)s" \
|
||||
--add-metadata \
|
||||
|awk '$1 == "[download]" && $2 == "Destination:" {print substr($0, index($0,$3))}')"
|
||||
case "$(echo "$file_name" | awk -F . '{print $NF}')" in
|
||||
"webm")
|
||||
new_filename="${file_name%.*}".opus
|
||||
mkvextract tracks "$file_name" "0:$new_filename" > /dev/null
|
||||
file_name="$new_filename"
|
||||
;;
|
||||
"m4a")
|
||||
;;
|
||||
*)
|
||||
echo "unsupported file type"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
r128gain "$file_name" 2> /dev/null
|
||||
temp_file="$temp_dir/$(basename "$file_name")"
|
||||
cp "$file_name" "$temp_file"
|
||||
idntag "$temp_file"
|
||||
temp_file=$(echo "$temp_dir"/*)
|
||||
if checkMetadata "$temp_file"; then
|
||||
mv "$temp_file" .
|
||||
elif checkMetadata "$file_name"; then
|
||||
mv "$file_name" .
|
||||
else
|
||||
echo "enter it manually"
|
||||
fi
|
||||
done
|
||||
rm -rf "$temp_dir" "$download_dir"
|
||||
mpc update > /dev/null
|
||||
|
||||
38
pulse-sink-change
Executable file
38
pulse-sink-change
Executable file
@ -0,0 +1,38 @@
|
||||
#!/usr/bin/python3
|
||||
import asyncio
|
||||
import signal
|
||||
from contextlib import suppress
|
||||
import pulsectl_asyncio
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
#import pulsectl
|
||||
#print('Event types:', pulsectl.PulseEventTypeEnum)
|
||||
#print('Event facilities:', pulsectl.PulseEventFacilityEnum)
|
||||
#print('Event masks:', pulsectl.PulseEventMaskEnum)
|
||||
|
||||
last_reload = 0
|
||||
|
||||
async def listen():
|
||||
async with pulsectl_asyncio.PulseAsync('event-printer') as pulse:
|
||||
async for event in pulse.subscribe_events('all'):
|
||||
global last_reload
|
||||
if (event.facility == "sink_input" and event.index == 20 or event.facility == "server" and event.index == -1) and event.t == "change" and time.time() - last_reload >= 2:
|
||||
last_reload = time.time()
|
||||
subprocess.call(["pacmd", ".include", "/etc/pulse/default.pa.d/10-noise-cancellation.pa"])
|
||||
|
||||
async def main():
|
||||
# Run listen() coroutine in task to allow cancelling it
|
||||
listen_task = asyncio.create_task(listen())
|
||||
|
||||
# register signal handlers to cancel listener when program is asked to terminate
|
||||
for sig in (signal.SIGTERM, signal.SIGHUP, signal.SIGINT):
|
||||
loop.add_signal_handler(sig, listen_task.cancel)
|
||||
# Alternatively, the PulseAudio event subscription can be ended by breaking/returning from the `async for` loop
|
||||
|
||||
with suppress(asyncio.CancelledError):
|
||||
await listen_task
|
||||
|
||||
# Run event loop until main_task finishes
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(main())
|
||||
Reference in New Issue
Block a user