Pretty code
This commit is contained in:
parent
15b2ecf652
commit
6d12908ab8
@ -50,19 +50,19 @@
|
||||
(defun livie--channel-query (uid n sort)
|
||||
"Query youtube for UID videos, return the Nth page of results, sorted bv SORT."
|
||||
(let ((videos (livie--API-call (concat "channels/videos/" uid)
|
||||
`(("page" ,n)
|
||||
("sort_by" ,sort)
|
||||
("fields" ,livie-default-video-query-fields)))))
|
||||
`(("page" ,n)
|
||||
("sort_by" ,sort)
|
||||
("fields" ,livie-default-video-query-fields)))))
|
||||
(dotimes (i (length videos))
|
||||
(let ((v (aref videos i)))
|
||||
(aset videos i
|
||||
(livie-video--create :title (assoc-default 'title v)
|
||||
:author (assoc-default 'author v)
|
||||
:authorId (assoc-default 'authorId v)
|
||||
:length (assoc-default 'lengthSeconds v)
|
||||
:id (assoc-default 'videoId v)
|
||||
:views (assoc-default 'viewCount v)
|
||||
:published (assoc-default 'published v)))))
|
||||
:author (assoc-default 'author v)
|
||||
:authorId (assoc-default 'authorId v)
|
||||
:length (assoc-default 'lengthSeconds v)
|
||||
:id (assoc-default 'videoId v)
|
||||
:views (assoc-default 'viewCount v)
|
||||
:published (assoc-default 'published v)))))
|
||||
videos))
|
||||
|
||||
(defun livie-channel ()
|
||||
|
@ -105,7 +105,7 @@
|
||||
(defun livie-playlist--query (playlistID page)
|
||||
"Query Invidious for videos from PLAYLISTID on PAGE."
|
||||
(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)))))
|
||||
|
||||
(defun livie--quit-playlist-buffer ()
|
||||
|
50
livie.el
50
livie.el
@ -59,16 +59,16 @@
|
||||
:group 'livie)
|
||||
|
||||
(defvar livie--insert-functions '((video . livie--insert-video)
|
||||
(playlist . livie--insert-playlist)
|
||||
(channel . livie--insert-channel)))
|
||||
(playlist . livie--insert-playlist)
|
||||
(channel . livie--insert-channel)))
|
||||
|
||||
(defvar livie--default-action-functions '((video . livie--default-video-action)
|
||||
(playlist . livie--default-playlist-action)
|
||||
(channel . livie--default-channel-action))
|
||||
(playlist . livie--default-playlist-action)
|
||||
(channel . livie--default-channel-action))
|
||||
"Functions to call on an entry. To modify an action, set the appropiate variable instead.")
|
||||
|
||||
(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.")
|
||||
|
||||
(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."
|
||||
(interactive)
|
||||
(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))
|
||||
(livie--draw-buffer))
|
||||
|
||||
@ -392,7 +392,7 @@ too long)."
|
||||
(interactive)
|
||||
(when (> livie-current-page 1)
|
||||
(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))
|
||||
(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.
|
||||
(cl-defstruct (livie-channel (:constructor livie-channel--create)
|
||||
(:copier nil))
|
||||
(:copier nil))
|
||||
"Information about a Youtube channel."
|
||||
(author "" :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))
|
||||
|
||||
(cl-defstruct (livie-playlist (:constructor livie-playlist--create)
|
||||
(:copier nil))
|
||||
(:copier nil))
|
||||
"Information about a Youtube playlist."
|
||||
(title "" :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))))
|
||||
|
||||
(defun livie--query (string n)
|
||||
"Query youtube for STRING, return the Nth page of results."
|
||||
(let ((results (livie--API-call "search" `(("q" ,string)
|
||||
("sort_by" ,(symbol-name livie-sort-criterion))
|
||||
("type" ,livie-type-of-results)
|
||||
("page" ,n)
|
||||
("fields" ,(pcase livie-type-of-results
|
||||
("video" livie-default-video-query-fields)
|
||||
("playlist" livie-default-playlist-query-fields)
|
||||
("channel" livie-default-channel-query-fields)
|
||||
;; I mean, it does get the job done... fix later.
|
||||
("all" (concat livie-default-channel-query-fields
|
||||
","
|
||||
livie-default-playlist-query-fields
|
||||
","
|
||||
livie-default-video-query-fields))))))))
|
||||
results))
|
||||
"Query youtube for STRING, return the Nth page of results."
|
||||
(let ((results (livie--API-call "search" `(("q" ,string)
|
||||
("sort_by" ,(symbol-name livie-sort-criterion))
|
||||
("type" ,livie-type-of-results)
|
||||
("page" ,n)
|
||||
("fields" ,(pcase livie-type-of-results
|
||||
("video" livie-default-video-query-fields)
|
||||
("playlist" livie-default-playlist-query-fields)
|
||||
("channel" livie-default-channel-query-fields)
|
||||
;; I mean, it does get the job done... fix later.
|
||||
("all" (concat livie-default-channel-query-fields
|
||||
","
|
||||
livie-default-playlist-query-fields
|
||||
","
|
||||
livie-default-video-query-fields))))))))
|
||||
results))
|
||||
|
||||
(defun livie--process-results (results &optional type)
|
||||
"Process RESULTS and turn them into objects, is TYPE is not given, get it from RESULTS."
|
||||
|
Loading…
x
Reference in New Issue
Block a user