diff --git a/README.org b/README.org index e1e03e9..5e438ed 100644 --- a/README.org +++ b/README.org @@ -10,7 +10,8 @@ Set up an account at [[https://www.opensubtitles.com/en/home][opensubtitles.com] =opensub-languages= variable. To run, call ~M-x opensub~, provide a query string such as *matrix* or *office s04e13*. Select the relevant file among the -options, and it will be downloaded to =opensub-download-directory=. See example: +options, and it will be downloaded to =opensub-download-directory=. Columns include subtitle name, language, score and +movie/show name. See example: [[./image.png]] diff --git a/image.png b/image.png index 63ab703..2c23818 100644 Binary files a/image.png and b/image.png differ diff --git a/opensub.el b/opensub.el index 2f08abc..7f6e9d4 100644 --- a/opensub.el +++ b/opensub.el @@ -53,6 +53,10 @@ "Languages to search for; 2 letter codes." :type '(repeat string)) +(defcustom opensub-column-width 72 + "Width of the column in the completion list." + :type 'integer) + (defvar opensub--json-fn (if (version<= "27.1" emacs-version) (lambda () (json-parse-buffer :object-type 'alist)) @@ -81,19 +85,30 @@ clean-query))) (opensub--curl url))) +(defun opensub--annotation (cand) + (let* ((rest (cdr (assoc cand minibuffer-completion-table)))) + (concat " " + (propertize (alist-get 'language rest) 'face 'success) " " + (propertize (string-pad (alist-get 'rating rest) 4) 'face 'warning) " " + (propertize (alist-get 'full_name rest))))) + (defun opensub--get-file-id (results) "Given query RESULTS, return the file id of user-selected item." (let* ((items (alist-get 'data results)) + (completion-extra-properties (list :annotation-function 'opensub--annotation)) (options (cl-mapcar (lambda (item) - (concat - (let-alist item .attributes.language) ": " - (let-alist item .attributes.release))) + `(,(substring (string-pad (let-alist item .attributes.release) + opensub-column-width ? ) + 0 opensub-column-width) + . ((language . ,(let-alist item .attributes.language)) + (rating . ,(number-to-string (let-alist item .attributes.ratings))) + (year . ,(number-to-string (let-alist item .attributes.feature_details.year))) + (full_name . ,(let-alist item .attributes.feature_details.movie_name))))) items)) - (option (completing-read "Select: " options)) + (option (string-trim-right (completing-read "Select: " options))) (item (cl-find-if (lambda (x) - (string-suffix-p (let-alist x .attributes.release) - option)) + (string-search option (let-alist x .attributes.release))) items))) (alist-get 'file_id (aref (let-alist item .attributes.files) 0))))