Pretty code

This commit is contained in:
Jesús 2021-01-17 15:28:32 -05:00
parent 15b2ecf652
commit 6d12908ab8
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766
3 changed files with 35 additions and 35 deletions

View File

@ -50,19 +50,19 @@
(defun livie--channel-query (uid n sort) (defun livie--channel-query (uid n sort)
"Query youtube for UID videos, return the Nth page of results, sorted bv SORT." "Query youtube for UID videos, return the Nth page of results, sorted bv SORT."
(let ((videos (livie--API-call (concat "channels/videos/" uid) (let ((videos (livie--API-call (concat "channels/videos/" uid)
`(("page" ,n) `(("page" ,n)
("sort_by" ,sort) ("sort_by" ,sort)
("fields" ,livie-default-video-query-fields))))) ("fields" ,livie-default-video-query-fields)))))
(dotimes (i (length videos)) (dotimes (i (length videos))
(let ((v (aref videos i))) (let ((v (aref videos i)))
(aset videos i (aset videos i
(livie-video--create :title (assoc-default 'title v) (livie-video--create :title (assoc-default 'title v)
:author (assoc-default 'author v) :author (assoc-default 'author v)
:authorId (assoc-default 'authorId v) :authorId (assoc-default 'authorId v)
:length (assoc-default 'lengthSeconds v) :length (assoc-default 'lengthSeconds v)
:id (assoc-default 'videoId v) :id (assoc-default 'videoId v)
:views (assoc-default 'viewCount v) :views (assoc-default 'viewCount v)
:published (assoc-default 'published v))))) :published (assoc-default 'published v)))))
videos)) videos))
(defun livie-channel () (defun livie-channel ()

View File

@ -105,7 +105,7 @@
(defun livie-playlist--query (playlistID page) (defun livie-playlist--query (playlistID page)
"Query Invidious for videos from PLAYLISTID on PAGE." "Query Invidious for videos from PLAYLISTID on PAGE."
(let* ((results (livie--API-call (concat "playlists/" livie-playlistId) '(("fields" "videos") (let* ((results (livie--API-call (concat "playlists/" livie-playlistId) '(("fields" "videos")
("page" ,livie-current-page))))) ("page" ,livie-current-page)))))
(setf livie-videos (livie--process-playlist-videos (assoc-default 'videos results))))) (setf livie-videos (livie--process-playlist-videos (assoc-default 'videos results)))))
(defun livie--quit-playlist-buffer () (defun livie--quit-playlist-buffer ()

View File

@ -59,16 +59,16 @@
:group 'livie) :group 'livie)
(defvar livie--insert-functions '((video . livie--insert-video) (defvar livie--insert-functions '((video . livie--insert-video)
(playlist . livie--insert-playlist) (playlist . livie--insert-playlist)
(channel . livie--insert-channel))) (channel . livie--insert-channel)))
(defvar livie--default-action-functions '((video . livie--default-video-action) (defvar livie--default-action-functions '((video . livie--default-video-action)
(playlist . livie--default-playlist-action) (playlist . livie--default-playlist-action)
(channel . livie--default-channel-action)) (channel . livie--default-channel-action))
"Functions to call on an entry. To modify an action, set the appropiate variable instead.") "Functions to call on an entry. To modify an action, set the appropiate variable instead.")
(defvar livie--default-video-action #'(lambda () (defvar livie--default-video-action #'(lambda ()
(message (livie-video-title (livie-get-current-video)))) (message (livie-video-title (livie-get-current-video))))
"Action to open a video. By default it just prints the title to the minibuffer.") "Action to open a video. By default it just prints the title to the minibuffer.")
(defvar livie--default-playlist-action #'livie--open-playlist (defvar livie--default-playlist-action #'livie--open-playlist
@ -383,7 +383,7 @@ too long)."
"Switch to the next page of the current search. Redraw the buffer." "Switch to the next page of the current search. Redraw the buffer."
(interactive) (interactive)
(setf livie-videos (livie--process-results (livie--query livie-search-term (setf livie-videos (livie--process-results (livie--query livie-search-term
(1+ livie-current-page)))) (1+ livie-current-page))))
(setf livie-current-page (1+ livie-current-page)) (setf livie-current-page (1+ livie-current-page))
(livie--draw-buffer)) (livie--draw-buffer))
@ -392,7 +392,7 @@ too long)."
(interactive) (interactive)
(when (> livie-current-page 1) (when (> livie-current-page 1)
(setf livie-videos (livie--process-results (livie--query livie-search-term (setf livie-videos (livie--process-results (livie--query livie-search-term
(1- livie-current-page)))) (1- livie-current-page))))
(setf livie-current-page (1- livie-current-page)) (setf livie-current-page (1- livie-current-page))
(livie--draw-buffer))) (livie--draw-buffer)))
@ -533,7 +533,7 @@ If ARG is given, format it as a Invidious RSS feed."
;; Maybe type should be part of the struct. ;; Maybe type should be part of the struct.
(cl-defstruct (livie-channel (:constructor livie-channel--create) (cl-defstruct (livie-channel (:constructor livie-channel--create)
(:copier nil)) (:copier nil))
"Information about a Youtube channel." "Information about a Youtube channel."
(author "" :read-only t) (author "" :read-only t)
(authorId "" :read-only t) (authorId "" :read-only t)
@ -541,7 +541,7 @@ If ARG is given, format it as a Invidious RSS feed."
(videoCount 0 :read-only t)) (videoCount 0 :read-only t))
(cl-defstruct (livie-playlist (:constructor livie-playlist--create) (cl-defstruct (livie-playlist (:constructor livie-playlist--create)
(:copier nil)) (:copier nil))
"Information about a Youtube playlist." "Information about a Youtube playlist."
(title "" :read-only t) (title "" :read-only t)
(playlistId "" :read-only t) (playlistId "" :read-only t)
@ -567,22 +567,22 @@ zero exit code otherwise the request body is parsed by `json-read' and returned.
(json-read)))) (json-read))))
(defun livie--query (string n) (defun livie--query (string n)
"Query youtube for STRING, return the Nth page of results." "Query youtube for STRING, return the Nth page of results."
(let ((results (livie--API-call "search" `(("q" ,string) (let ((results (livie--API-call "search" `(("q" ,string)
("sort_by" ,(symbol-name livie-sort-criterion)) ("sort_by" ,(symbol-name livie-sort-criterion))
("type" ,livie-type-of-results) ("type" ,livie-type-of-results)
("page" ,n) ("page" ,n)
("fields" ,(pcase livie-type-of-results ("fields" ,(pcase livie-type-of-results
("video" livie-default-video-query-fields) ("video" livie-default-video-query-fields)
("playlist" livie-default-playlist-query-fields) ("playlist" livie-default-playlist-query-fields)
("channel" livie-default-channel-query-fields) ("channel" livie-default-channel-query-fields)
;; I mean, it does get the job done... fix later. ;; I mean, it does get the job done... fix later.
("all" (concat livie-default-channel-query-fields ("all" (concat livie-default-channel-query-fields
"," ","
livie-default-playlist-query-fields livie-default-playlist-query-fields
"," ","
livie-default-video-query-fields)))))))) livie-default-video-query-fields))))))))
results)) results))
(defun livie--process-results (results &optional type) (defun livie--process-results (results &optional type)
"Process RESULTS and turn them into objects, is TYPE is not given, get it from RESULTS." "Process RESULTS and turn them into objects, is TYPE is not given, get it from RESULTS."