aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--emacs/.emacs.d/init/ycp-markup.el2
-rw-r--r--emacs/.emacs.d/init/ycp-web.el4
m---------emacs/.emacs.d/lisp/emacs-hnreader0
-rw-r--r--emacs/.emacs.d/lisp/my/my-media-segment.el12
-rw-r--r--emacs/.emacs.d/lisp/my/my-web.el66
-rw-r--r--emacs/.emacs.d/lisp/my/my-ytdl.el19
-rw-r--r--misc/.config/mpv/mpv.conf2
-rwxr-xr-xmisc/bin/mpvmix.sh22
8 files changed, 113 insertions, 14 deletions
diff --git a/emacs/.emacs.d/init/ycp-markup.el b/emacs/.emacs.d/init/ycp-markup.el
index c5f874f..68b5459 100644
--- a/emacs/.emacs.d/init/ycp-markup.el
+++ b/emacs/.emacs.d/init/ycp-markup.el
@@ -71,7 +71,7 @@
(my-package wiki
(my-keybind wiki-mode-map
"C-'" #'my-wiki-grok-wikipedia)
- (my-setq-from-local wiki-sites)
+ (my-setq-from-local wiki-sites wiki-local-dir)
(wiki-define-site-commands)
(add-to-list 'browse-url-handlers
`(wiki-engine-entry-url-p
diff --git a/emacs/.emacs.d/init/ycp-web.el b/emacs/.emacs.d/init/ycp-web.el
index c43aae6..fd16b10 100644
--- a/emacs/.emacs.d/init/ycp-web.el
+++ b/emacs/.emacs.d/init/ycp-web.el
@@ -187,6 +187,7 @@
(my-override hnreader--print-frontpage-item)
(my-override hnreader--print-comments)
(my-override hnreader--get-title)
+ (my-setq-from-local my-hnreader-save-dir)
(require 'my-web)
(add-to-list 'browse-url-handlers
`(my-hacker-news-url-p
@@ -340,6 +341,7 @@
(my-package fediorg
(:delay 60)
+ (my-setq-from-local fediorg-dir)
(require 'my-web)
(add-to-list 'browse-url-handlers
`(fediorg-post-url-p
@@ -389,6 +391,7 @@
exitter-oauth-consumer-key exitter-oauth-consumer-secret
exitter-access-token exitter-username exitter-password exitter-email
exitter-oauth-token exitter-oauth-token-secret exitter-oauth-token-ctime)
+ (my-setq-from-local exitter-dir)
(setq exitter-debug nil)
(add-to-list 'browse-url-handlers
`(exitter-post-url-p
@@ -398,6 +401,7 @@
(my-package reddio
(:delay 60)
+ (my-setq-from-local reddio-dir)
(add-to-list 'browse-url-handlers
`(reddio-reddit-url-p
. ,(lambda (url &rest _) (reddio-open-url url))))
diff --git a/emacs/.emacs.d/lisp/emacs-hnreader b/emacs/.emacs.d/lisp/emacs-hnreader
-Subproject 8444e177035e236e991f9ea73074c053a45426a
+Subproject a56f67a99a855ca656da1c1985e09f44509e4bb
diff --git a/emacs/.emacs.d/lisp/my/my-media-segment.el b/emacs/.emacs.d/lisp/my/my-media-segment.el
index 9431624..e8ee5cc 100644
--- a/emacs/.emacs.d/lisp/my/my-media-segment.el
+++ b/emacs/.emacs.d/lisp/my/my-media-segment.el
@@ -134,11 +134,7 @@ Uses `my-media-segment-max-inflight' to limit number of inflight tasks."
(interactive (list
(read-file-name "Choose media file: ")
(read-file-name
- "Choose description file (.info.json or .description): "
- ;; nil
- ;; (file-name-with-extension media-file-name ".info.json")
- ;; t
- )))
+ "Choose description file (.info.json or .description): ")))
(let* ((dir (file-name-sans-extension (expand-file-name media-file-name)))
(info (my-get-media-segments info-file-name))
(total (length info))
@@ -187,7 +183,9 @@ Uses `my-media-segment-max-inflight' to limit number of inflight tasks."
(seq-map
(lambda (ch)
(let-alist ch
- (list :title (my-make-filename .title) :start (format "%s" .start_time)
+ ;; .title: ytdl; .tags.titile: .m4b
+ (list :title (my-make-doc-file-name (or .title .tags.title))
+ :start (format "%s" .start_time)
:end (format "%s" .end_time))))
(alist-get 'chapters info))))
@@ -212,7 +210,7 @@ Uses `my-media-segment-max-inflight' to limit number of inflight tasks."
(buffer-substring-no-properties
(point)
(progn (beginning-of-line 2) (point))))))
- (push (list :title (my-make-filename title) :start start :end end) results)
+ (push (list :title (my-make-doc-file-name title) :start start :end end) results)
)
(setq end nil)
(dolist (result results)
diff --git a/emacs/.emacs.d/lisp/my/my-web.el b/emacs/.emacs.d/lisp/my/my-web.el
index 92ef599..87c319f 100644
--- a/emacs/.emacs.d/lisp/my/my-web.el
+++ b/emacs/.emacs.d/lisp/my/my-web.el
@@ -253,5 +253,71 @@ https://emacs.stackexchange.com/questions/40887/in-org-mode-how-do-i-link-to-int
(lambda (_)
(funcall my-url-context-function url)))))
+(defvar my-dw-host "dw.com")
+
+(defun my-dw-parse-article-url (url)
+ "Returns (lang . article-id)"
+ (let* ((urlobj (url-generic-parse-url url))
+ (path (url-filename urlobj))
+ (components (string-split path "/")))
+ `(,(elt components 1) . ,(string-remove-prefix "a-" (elt components 3)))))
+
+(defun my-dw-article-api (url)
+ (pcase-let ((`(,lang . ,id) (my-dw-parse-article-url url)))
+ (my-url-fetch-json
+ (format "https://%s/graph-api/%s/content/article/%s" my-dw-host lang id))))
+
+(defun my-dw-extract (info)
+ "Returns list of (url . file-name) pairs."
+ (let* ((content (alist-get 'content (alist-get 'data info)))
+ (dir (file-name-concat my-audio-incoming-dir
+ (my-make-doc-file-name
+ (alist-get 'title content))))
+ (audios (alist-get 'audios content)))
+ (seq-map
+ (lambda (audio)
+ (let ((url (alist-get 'mp3Src audio)))
+ `(,url
+ .
+ ,(expand-file-name
+ (file-name-concat dir (file-name-with-extension
+ (my-make-doc-file-name
+ (alist-get 'name audio))
+ (file-name-extension url)))))))
+ audios)))
+
+(defun my-dw-download (pairs)
+ "Download list of (url . file-name) pairs with aria2."
+ (let ((file (make-temp-file "/tmp/aria2"))
+ (n (length pairs)))
+ (with-temp-file file
+ (dolist (pair pairs)
+ (insert (car pair) "\n out=" (cdr pair) "\n"))
+ ;; (buffer-string)
+ )
+ (message "Downloading %d files..." n)
+ (set-process-sentinel
+ (start-process "aria2" "*aria2*" "aria2c" "-x" "5" "-d" "/"
+ "-R" "true" "-i" file)
+ (lambda (proc event)
+ (let ((status (process-exit-status proc)))
+ (if (eq status 0)
+ (progn
+ (message "Downloading %d files...Done" n))
+ (message "Downloading %d files...Failed: %s" n event)))))))
+
+(defun my-dw-download-url (url)
+ (interactive "sDW Download URL: ")
+ (my-dw-download (my-dw-extract (my-dw-article-api url))))
+
+(defun my-dw-download-urls (urls)
+ (my-dw-download (seq-mapcat
+ (lambda (url) (my-dw-extract (my-dw-article-api url)))
+ urls)))
+
+(defun my-local-archive-open-url (url)
+ "Open url from local archive."
+ )
+
(provide 'my-web)
;;; my-web.el ends here
diff --git a/emacs/.emacs.d/lisp/my/my-ytdl.el b/emacs/.emacs.d/lisp/my/my-ytdl.el
index 5676101..7cdda43 100644
--- a/emacs/.emacs.d/lisp/my/my-ytdl.el
+++ b/emacs/.emacs.d/lisp/my/my-ytdl.el
@@ -76,12 +76,19 @@
('audio my-ytdl-audio-download-dir)
('music my-ytdl-music-download-dir)
(_ (error "Unsupported type: %s" type)))
- (apply 'my-start-process-with-torsocks
- (append
- (list no-tor (format "ytdl-%s" urls) (format "*ytdl-%s*" urls)
- my-ytdl-program)
- (if (eq type 'video) my-ytdl-video-args my-ytdl-audio-args)
- (split-string urls)))))
+ (set-process-sentinel
+ (apply 'my-start-process-with-torsocks
+ (append
+ (list no-tor (format "ytdl-%s" urls) (format "*ytdl-%s*" urls)
+ my-ytdl-program)
+ (if (eq type 'video) my-ytdl-video-args my-ytdl-audio-args)
+ (split-string urls)))
+ (lambda (proc event)
+ (let ((status (process-exit-status proc)))
+ (if (eq status 0)
+ (progn
+ (message "ytdl-%s %s: DONE" type urls))
+ (message "ytdl-%s %s FAILED: %s" type urls event)))))))
(defun my-ytdl-video-info (url)
"Given a video URL, return an alist of its properties."
diff --git a/misc/.config/mpv/mpv.conf b/misc/.config/mpv/mpv.conf
index 3b49398..b6b1beb 100644
--- a/misc/.config/mpv/mpv.conf
+++ b/misc/.config/mpv/mpv.conf
@@ -7,6 +7,8 @@ script-opts=ytdl_hook-ytdl_path=/usr/bin/yt-dlp
ytdl-format="bestvideo[height<=?720]+bestaudio/best"
osc=no
stop-screensaver = "yes"
+# play audio with ui
+# profile=pseudo-gui
[emacsconf-talks]
# Positioning
diff --git a/misc/bin/mpvmix.sh b/misc/bin/mpvmix.sh
new file mode 100755
index 0000000..8bc0ac8
--- /dev/null
+++ b/misc/bin/mpvmix.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# Randomly play media segments from a list of files with start and end
+# time line format:
+# 1:00//1:05//~/file.mp4
+
+f="$1"
+n=$(cat "$f" | wc -l)
+while true; do
+ while read -r line; do
+ echo "$line"
+ regex='([0-9:]+)//([0-9:]+)//(.+)'
+ [[ "$line" =~ $regex ]] || continue
+ start=${BASH_REMATCH[1]}
+ end=${BASH_REMATCH[2]}
+ media=${BASH_REMATCH[3]}
+ media="${media/#~/${HOME}}"
+ # echo "start: $start; end: $end; file: $media"
+ mpv --start=$start --end=$end "$media"
+ done <<<$(shuf -n $n "$f")
+ sleep 1
+done