mirror of
https://github.com/SqrtMinusOne/lyrics-fetcher.el.git
synced 2025-12-10 17:03:03 +03:00
refator: fix package-lint errors
This commit is contained in:
parent
cbbf6244af
commit
46a2045526
1 changed files with 24 additions and 24 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
;;; lyrics-fetcher-genius.el --- fetch lyrics from genius.com -*- lexical-binding: t -*-
|
;;; lyrics-fetcher-genius.el --- Fetch lyrics from genius.com -*- lexical-binding: t -*-
|
||||||
|
|
||||||
;; Copyright (C) 2021 Korytov Pavel
|
;; Copyright (C) 2021 Korytov Pavel
|
||||||
|
|
||||||
|
|
@ -61,7 +61,7 @@ The flow is as follows:
|
||||||
4. Call CALLBACK with the resulting lyrics string
|
4. Call CALLBACK with the resulting lyrics string
|
||||||
|
|
||||||
TRACK should be EMMS-compatible alist or string, take a look at
|
TRACK should be EMMS-compatible alist or string, take a look at
|
||||||
`lyrics-fetcher--genius-format-query'. If the search is
|
`lyrics-fetcher-genius--format-query'. If the search is
|
||||||
successful, CALLBACK will be called with the result.
|
successful, CALLBACK will be called with the result.
|
||||||
|
|
||||||
If SYNC is non-nil, perform request synchronously and ask the
|
If SYNC is non-nil, perform request synchronously and ask the
|
||||||
|
|
@ -70,23 +70,23 @@ user to pick the matching search result.
|
||||||
When EDIT is non-nil, edit the query in minibuffer before search.
|
When EDIT is non-nil, edit the query in minibuffer before search.
|
||||||
Genius usually struggles to find song if there is extra
|
Genius usually struggles to find song if there is extra
|
||||||
information in the title."
|
information in the title."
|
||||||
(lyrics-fetcher--genius-do-query
|
(lyrics-fetcher-genius--do-query
|
||||||
track
|
track
|
||||||
(lambda (data)
|
(lambda (data)
|
||||||
(lyrics-fetcher--genius-fetch-lyrics
|
(lyrics-fetcher-genius--fetch-lyrics
|
||||||
(lyrics-fetcher--genius-get-data-from-response data 'url sync)
|
(lyrics-fetcher-genius--get-data-from-response data 'url sync)
|
||||||
callback
|
callback
|
||||||
sync))
|
sync))
|
||||||
sync
|
sync
|
||||||
edit))
|
edit))
|
||||||
|
|
||||||
(defun lyrics-fetcher--genius-do-query (track callback &optional sync edit)
|
(defun lyrics-fetcher-genius--do-query (track callback &optional sync edit)
|
||||||
"Perform a song search on genius.com.
|
"Perform a song search on genius.com.
|
||||||
|
|
||||||
Requires `lyrics-fetcher-genius-access-token' to be set.
|
Requires `lyrics-fetcher-genius-access-token' to be set.
|
||||||
|
|
||||||
TRACK should be EMMS-compatible alist or string, take a look at
|
TRACK should be EMMS-compatible alist or string, take a look at
|
||||||
`lyrics-fetcher--genius-format-query'. If the search is
|
`lyrics-fetcher-genius--format-query'. If the search is
|
||||||
successful, CALLBACK will be called with the result.
|
successful, CALLBACK will be called with the result.
|
||||||
|
|
||||||
SYNC determines whether the request is synchronous. The parameter
|
SYNC determines whether the request is synchronous. The parameter
|
||||||
|
|
@ -98,8 +98,8 @@ When EDIT is non-nil, edit the query in minibuffer before search."
|
||||||
(error "Genius client access token not set!"))
|
(error "Genius client access token not set!"))
|
||||||
(message "Sending a query to genius API...")
|
(message "Sending a query to genius API...")
|
||||||
(request "https://api.genius.com/search"
|
(request "https://api.genius.com/search"
|
||||||
:params `(("q" . ,(lyrics-fetcher--genius-maybe-edit-query
|
:params `(("q" . ,(lyrics-fetcher-genius--maybe-edit-query
|
||||||
(lyrics-fetcher--genius-format-query track)
|
(lyrics-fetcher-genius--format-query track)
|
||||||
edit))
|
edit))
|
||||||
("access_token" . ,lyrics-fetcher-genius-access-token))
|
("access_token" . ,lyrics-fetcher-genius-access-token))
|
||||||
:parser 'json-read
|
:parser 'json-read
|
||||||
|
|
@ -111,13 +111,13 @@ When EDIT is non-nil, edit the query in minibuffer before search."
|
||||||
(lambda (&key error-thrown &allow-other-keys)
|
(lambda (&key error-thrown &allow-other-keys)
|
||||||
(message "Error!: %S" error-thrown)))))
|
(message "Error!: %S" error-thrown)))))
|
||||||
|
|
||||||
(defun lyrics-fetcher--genius-maybe-edit-query (query edit)
|
(defun lyrics-fetcher-genius--maybe-edit-query (query edit)
|
||||||
"If EDIT is non-nil, edit QUERY if minibuffer."
|
"If EDIT is non-nil, edit QUERY in minibuffer."
|
||||||
(when edit
|
(when edit
|
||||||
(read-from-minibuffer "Query: " query))
|
(read-from-minibuffer "Query: " query))
|
||||||
query)
|
query)
|
||||||
|
|
||||||
(defun lyrics-fetcher--genius-format-query (track)
|
(defun lyrics-fetcher-genius--format-query (track)
|
||||||
"Format track to genius.com query.
|
"Format track to genius.com query.
|
||||||
|
|
||||||
When `lyrics-fetcher-genius-strip-parens-from-query' is non-nil,
|
When `lyrics-fetcher-genius-strip-parens-from-query' is non-nil,
|
||||||
|
|
@ -141,14 +141,14 @@ contains `info-albumartist' or `info-artist' and `info-title'"
|
||||||
"" query)))
|
"" query)))
|
||||||
query)))
|
query)))
|
||||||
|
|
||||||
(defun lyrics-fetcher--genius-format-song-title (entry)
|
(defun lyrics-fetcher-genius--format-song-title (entry)
|
||||||
"Convert a Genius search ENTRY to a string, which can be used in selection."
|
"Convert a Genius search ENTRY to a string, which can be used in selection."
|
||||||
(let ((result (assoc 'result entry)))
|
(let ((result (assoc 'result entry)))
|
||||||
(format "%-40s [lyrics: %s]"
|
(format "%-40s [lyrics: %s]"
|
||||||
(cdr (assoc 'full_title result))
|
(cdr (assoc 'full_title result))
|
||||||
(cdr (assoc 'lyrics_state result)))))
|
(cdr (assoc 'lyrics_state result)))))
|
||||||
|
|
||||||
(defun lyrics-fetcher--genius-get-data-from-response (data key &optional ask)
|
(defun lyrics-fetcher-genius--get-data-from-response (data key &optional ask)
|
||||||
"Retrieve a song KEY from the Genius response DATA.
|
"Retrieve a song KEY from the Genius response DATA.
|
||||||
|
|
||||||
If ASK is non-nil, prompt the user for a choice, otherwise select the
|
If ASK is non-nil, prompt the user for a choice, otherwise select the
|
||||||
|
|
@ -167,7 +167,7 @@ first song."
|
||||||
(let ((results-songs-for-select
|
(let ((results-songs-for-select
|
||||||
(mapcar
|
(mapcar
|
||||||
(lambda (entry)
|
(lambda (entry)
|
||||||
(cons (lyrics-fetcher--genius-format-song-title entry)
|
(cons (lyrics-fetcher-genius--format-song-title entry)
|
||||||
(assoc key (assoc 'result entry))))
|
(assoc key (assoc 'result entry))))
|
||||||
results-songs)))
|
results-songs)))
|
||||||
(cdr
|
(cdr
|
||||||
|
|
@ -179,7 +179,7 @@ first song."
|
||||||
results-songs-for-select)))
|
results-songs-for-select)))
|
||||||
(assoc key (assoc 'result (car results-songs)))))))
|
(assoc key (assoc 'result (car results-songs)))))))
|
||||||
|
|
||||||
(defun lyrics-fetcher--genius-fetch-lyrics (url callback &optional sync)
|
(defun lyrics-fetcher-genius--fetch-lyrics (url callback &optional sync)
|
||||||
"Fetch lyrics from genius.com page at URL and call CALLBACK with the result.
|
"Fetch lyrics from genius.com page at URL and call CALLBACK with the result.
|
||||||
|
|
||||||
If SYNC is non-nil, the request will be performed synchronously."
|
If SYNC is non-nil, the request will be performed synchronously."
|
||||||
|
|
@ -212,7 +212,7 @@ Requires `lyrics-fetcher-genius-access-token' to be set and
|
||||||
imagemagick's \"convert\" to be available in PATH.
|
imagemagick's \"convert\" to be available in PATH.
|
||||||
|
|
||||||
TRACK should be EMMS-compatible alist or string, take a look at
|
TRACK should be EMMS-compatible alist or string, take a look at
|
||||||
`lyrics-fetcher--genius-format-query'. If the search is successful,
|
`lyrics-fetcher-genius--format-query'. If the search is successful,
|
||||||
CALLBACK will be called with the resulting filename of the large
|
CALLBACK will be called with the resulting filename of the large
|
||||||
cover.
|
cover.
|
||||||
|
|
||||||
|
|
@ -227,35 +227,35 @@ CALLBACK will be called with a path to the resulting file.
|
||||||
If SYNC is non-nil, the user will be prompted for a matching song.
|
If SYNC is non-nil, the user will be prompted for a matching song.
|
||||||
|
|
||||||
When EDIT is non-nil, edit the query in minibuffer before search."
|
When EDIT is non-nil, edit the query in minibuffer before search."
|
||||||
(lyrics-fetcher--genius-do-query
|
(lyrics-fetcher-genius--do-query
|
||||||
track
|
track
|
||||||
(lambda (data)
|
(lambda (data)
|
||||||
(lyrics-fetcher--genius-save-album-picture
|
(lyrics-fetcher-genius--save-album-picture
|
||||||
(lyrics-fetcher--genius-get-data-from-response data 'id sync)
|
(lyrics-fetcher-genius--get-data-from-response data 'id sync)
|
||||||
callback
|
callback
|
||||||
folder))
|
folder))
|
||||||
sync
|
sync
|
||||||
edit))
|
edit))
|
||||||
|
|
||||||
(defun lyrics-fetcher--genius-save-album-picture (id callback folder)
|
(defun lyrics-fetcher-genius--save-album-picture (id callback folder)
|
||||||
"Save an album cover of a song of a given ID.
|
"Save an album cover of a song of a given ID.
|
||||||
|
|
||||||
The file will be saved to FOLDER and will be named
|
The file will be saved to FOLDER and will be named
|
||||||
\"cover_large.<extension>\".
|
\"cover_large.<extension>\".
|
||||||
|
|
||||||
CALLBACK is passed to `lyrics-fetcher--genius-save-album-url'."
|
CALLBACK is passed to `lyrics-fetcher-genius--save-album-url'."
|
||||||
(request
|
(request
|
||||||
(format "https://api.genius.com/songs/%s" id)
|
(format "https://api.genius.com/songs/%s" id)
|
||||||
:parser 'json-read
|
:parser 'json-read
|
||||||
:params `(("access_token" . ,lyrics-fetcher-genius-access-token))
|
:params `(("access_token" . ,lyrics-fetcher-genius-access-token))
|
||||||
:success (cl-function
|
:success (cl-function
|
||||||
(lambda (&key data &allow-other-keys)
|
(lambda (&key data &allow-other-keys)
|
||||||
(lyrics-fetcher--genius-save-album-url data callback folder)))
|
(lyrics-fetcher-genius--save-album-url data callback folder)))
|
||||||
:error (cl-function
|
:error (cl-function
|
||||||
(lambda (&key error-thrown &allow-other-keys)
|
(lambda (&key error-thrown &allow-other-keys)
|
||||||
(message "Error!: %S" error-thrown)))))
|
(message "Error!: %S" error-thrown)))))
|
||||||
|
|
||||||
(defun lyrics-fetcher--genius-save-album-url (data callback folder)
|
(defun lyrics-fetcher-genius--save-album-url (data callback folder)
|
||||||
"Save album cover of DATA to FOLDER.
|
"Save album cover of DATA to FOLDER.
|
||||||
|
|
||||||
DATA should be a response from GET /songs/:id. The file will be saved
|
DATA should be a response from GET /songs/:id. The file will be saved
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue