Compare commits
9 Commits
a2a5261ca4
...
86c42fba7a
| Author | SHA1 | Date |
|---|---|---|
|
|
86c42fba7a | 3 years ago |
|
|
980b6d5d0d | 3 years ago |
|
|
caf0570284 | 3 years ago |
|
|
0c11e2672d | 3 years ago |
|
|
c417a7872f | 3 years ago |
|
|
8b3920deb5 | 3 years ago |
|
|
10e98e71af | 3 years ago |
|
|
4fbf0bdd04 | 3 years ago |
|
|
9b2a7dda0e | 4 years ago |
13 changed files with 175 additions and 12 deletions
@ -0,0 +1,61 @@ |
|||
#!/usr/bin/env python3 |
|||
""" |
|||
A simple script to pipe URIs through yt-dlp and mpd |
|||
|
|||
Credit: https://gist.github.com/phaer/86bdcc3fb59cd3fcd9534bfe84d9fe5f |
|||
""" |
|||
import sys |
|||
import mpd |
|||
import yt_dlp |
|||
|
|||
mpd_host = ('localhost', 6600) |
|||
ydl_opts = { |
|||
'format': 'bestaudio/audio', |
|||
'quiet': True, |
|||
} |
|||
|
|||
if __name__ == '__main__': |
|||
if len(sys.argv) != 2: |
|||
print("usage: {} <url>".format(sys.argv[0]), file=sys.stderr) |
|||
sys.exit(1) |
|||
|
|||
source_url = sys.argv[1] |
|||
client = mpd.MPDClient() |
|||
|
|||
with yt_dlp.YoutubeDL(ydl_opts) as ydl: |
|||
try: |
|||
info = ydl.extract_info(source_url, process=False, download=False) |
|||
except yt_dlp.utils.DownloadError: |
|||
# Don't print anything, yt-dlp is already on it |
|||
sys.exit(1) |
|||
|
|||
if info.get("_type") is not None and info.get("_type") == "playlist": |
|||
print("Queuing playlists not supported yet.", file=sys.stderr) |
|||
sys.exit(1) |
|||
|
|||
info = ydl.process_ie_result(info, download=False) |
|||
url = info.get('url') |
|||
title = info.get('title') |
|||
source = info.get('extractor_key') |
|||
|
|||
# This info is only available for songs |
|||
# that have been tagged as such on youtube |
|||
artist = info.get('artist') |
|||
|
|||
if not (url and title and source): |
|||
print("youtube-dl error.", file=sys.stderr) |
|||
sys.exit(1) |
|||
|
|||
client.connect(*mpd_host) |
|||
|
|||
# Get current playing song index and then append the stream just after |
|||
# This is analogous to `mpc insert <song>` |
|||
pos = int(client.status()["song"]) |
|||
song_id = client.addid(url, pos + 1) |
|||
|
|||
client.addtagid(song_id, 'title', title) |
|||
client.addtagid(song_id, 'album', source) |
|||
if artist is not None: |
|||
client.addtagid(song_id, 'artist', artist) |
|||
|
|||
client.disconnect() |
|||
@ -0,0 +1,42 @@ |
|||
#!/bin/sh |
|||
|
|||
set -euo pipefail |
|||
|
|||
text="$(cat)" |
|||
|
|||
# Extract only the text/html part of the multipart email |
|||
# TODO parse actual encoding instead of defaulting to iso-8859-1 |
|||
mailto="$(printf "%s" "$text" \ |
|||
| awk ' |
|||
boundary { |
|||
if ($0 ~ boundary) { |
|||
boundary = ""; |
|||
next |
|||
} |
|||
print $0 |
|||
} |
|||
|
|||
/Content-Type: text\/html;/ { |
|||
boundary=line |
|||
} |
|||
|
|||
{ |
|||
line=$0 |
|||
}' \ |
|||
| qprint -d \ |
|||
| iconv -f iso-8859-1 -t utf-8 \ |
|||
| grep -Eo '<a href="mailto:.*?</a>')" |
|||
|
|||
to="$(printf "%s" "$mailto" | sed -En 's/.*mailto:(.*?)\?subject=.*/\1/p')" |
|||
subject="$(printf "%s" "$mailto" | sed -En 's/.*\?subject=(.*?)" .*/\1/p')" |
|||
# TODO extract original To: to emulate use_envelope_from |
|||
|
|||
datadir="${XDG_DATA_HOME:-"$HOME/.local/share"}/neomutt" |
|||
mkdir -p "$datadir" |
|||
|
|||
format_str="unmy_hdr To: Subject: |
|||
my_hdr To: \"%s\" |
|||
my_hdr Subject: \"%s\" |
|||
echo \`rm \"%s\"\`" |
|||
|
|||
printf "$format_str" "$to" "$subject" "$datadir/info.rc" > "$datadir/info.rc" |
|||
@ -1,3 +1,40 @@ |
|||
text/html; unshare -n -r w3m -I %{charset} -T text/html; copiousoutput; |
|||
image/*; mutt_bgrun /usr/bin/feh -. %s; test=test -n "$DISPLAY" |
|||
application/pdf; mutt_bgrun /usr/bin/zathura %s; test=test -n "$DISPLAY" |
|||
|
|||
# Fichiers LibreOffice, Word, Excel et PowerPoint |
|||
application/vnd.openxmlformats-officedocument.wordprocessingml.document; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
application/vnd.openxmlformats-officedocument.wordprocessingml.template; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
application/vnd.openxmlformats-officedocument.spreadsheetml.template; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
application/vnd.openxmlformats-officedocument.presentationml.presentation; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
|
|||
application/msword; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
application/vnd.msword; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
|
|||
application/excel; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
application/msexcel; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
application/x-excel; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
application/x-msexcel; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
application/vnd.ms-excel; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
application/ms-Excel; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
|
|||
application/vnd.ms-powerpoint; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
application/x-mspowerpoint; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
application/ppt; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
|
|||
application/rtf; mutt_bgrun libreoffice --nologo '%s'; test=test -n "$DISPLAY" |
|||
|
|||
# # MS documents to txt |
|||
# application/msword; tika -t %s | less; |
|||
# application/vnd.msword; tika -t %s | less; |
|||
# application/excel; tika %s | less; |
|||
# application/msexcel; tika %s | less; |
|||
# application/x-excel; tika %s | less; |
|||
# application/x-msexcel; tika %s | less; |
|||
# application/vnd.ms-excel; tika %s | less; |
|||
# application/ms-Excel; tika %s | less; |
|||
# application/vnd.ms-powerpoint; tika %s | w3m -dump -T text/html | less; |
|||
# application/x-mspowerpoint; tika %s | w3m -dump -T text/html | less; |
|||
# application/ppt; tika %s | w3m -dump -T text/html | less; |
|||
# application/rtf; tika %s | w3m -dump -T text/html | less; |
|||
|
|||
Loading…
Reference in new issue