feat(emms): done

This commit is contained in:
Pavel Korytov 2021-09-08 18:54:52 +03:00
parent bd595b9a5f
commit a12fb94232
3 changed files with 33 additions and 33 deletions

View file

@ -1,9 +1,9 @@
+++
title = "My EMMS and elfeed setup"
author = ["Pavel Korytov"]
date = 2021-09-03
date = 2021-09-08
tags = ["emacs", "emms", "elfeed"]
draft = true
draft = false
+++
## Intro {#intro}
@ -12,13 +12,13 @@ draft = true
This is the current state of my quest to live in Emacs, at least in part of reading RSS and music.
Even before I lost my mind about customizing obscure keyboard-driven software, I tried Inoreader, self-hosted FreshRSS and then newsboat from the RSS side and ncmpcpp+MPD from the audio player side. At some point I got curious about whether I can do the same in Emacs.
Even before I lost my mind about customizing obscure keyboard-driven software, I tried Inoreader, self-hosted FreshRSS, and then newsboat from the RSS side and ncmpcpp+MPD from the audio player side. At some point, I got curious about whether I can do the same in Emacs.
The respective emacs packages, elfeed and EMMS, proved somewhat tricky to set up, i.e. I had to figure out the source code in both cases. I even submitted a small patch to EMMS to make it parse my MPD library correctly.
But in the end, only extensive customization capacities of Emacs enabled me to make a setup where these parts nicely come together and do give or take exactly what I want. However, this means there are a lot of degrees of freedom involved, so I'll try to cover the important parts and link to the original sources whereever possible.
But in the end, only extensive customization capacities of Emacs enabled me to make a setup where these parts nicely come together and do more or less exactly what I want. However, this means there are a lot of degrees of freedom involved, so Ill try to cover the important parts and link to the original sources wherever possible.
I'd call it "workflow", but the "work" part does not quite catch the point here.
Id call it “workflow”, but the “work” part does not quite catch the point here.
## MPD {#mpd}
@ -27,9 +27,9 @@ So, we have to start somewhere.
[MPD](https://www.musicpd.org/) is a server for playing music, although it is usually hosted on the local machine, i.e. the one on which you intend to listen to music. There is [bunch of clients](https://www.musicpd.org/clients/) available (take a look at [ncmpcpp](https://github.com/ncmpcpp/ncmpcpp) is you like terminal-based apps), but here our point of interest is its integration with EMMS.
While EMMS is capable of playing music without it, MPD has an advantantage of being independent of Emacs. That means it won't close if Emacs crashes and it can be controlled more easily with other means.
While EMMS is capable of playing music without it, MPD has the advantage of being independent of Emacs. That means it won't close if Emacs crashes and it can be controlled more easily with other means.
MPD configuration is a pretty easy process. First, install mpd and [mpc](https://www.musicpd.org/clients/mpc/) (a minimal MPD CLI client) from your distribution's package repository. After doing that, you'd have to create a config file at the location `~/.config/mpd/mpd.conf`. Mine looks something like this:
MPD configuration is a pretty easy process. First, install MPD and [mpc](https://www.musicpd.org/clients/mpc/) (a minimal MPD CLI client) from your distribution's package repository. After doing that, you'd have to create a config file at the location `~/.config/mpd/mpd.conf`. Mine looks something like this:
```vim
music_directory "~/Music"
@ -72,14 +72,14 @@ Take a look at [the official documentation](https://mpd.readthedocs.io/en/stable
The next question after we've set up MPD is how to organize the music directory.
MPD itself is not too concerned about the structure of your `music_directory`, because it uses audio tags to classify the files. However, if you want to have album covers in EMMS, you need to have one folder per one album. Otherwise and in other respects the structure can be arbitrary.
MPD itself is not too concerned about the structure of your `music_directory`, because it uses audio tags to classify the files. However, if you want to have album covers in EMMS, you need to have one folder per one album. Otherwise and in other respects, the structure can be arbitrary.
So we need to tag the audio files. My favorite audio-tagging software is [MusicBrainz Picard](https://picard.musicbrainz.org/), which can set tags automatially even if the file has no metadata at all, and move the file automatically according to the configuration. The aforementioned ncmpcpp also has a decent tag editor; finally there is a simple [mutagen-based CLI tool](https://mutagen.readthedocs.io/en/latest/man/mid3v2.html).
So we need to tag the audio files. My favorite audio-tagging software is [MusicBrainz Picard](https://picard.musicbrainz.org/), which can set tags automatically even if the file has no metadata at all, and move the file automatically according to the configuration. The aforementioned ncmpcpp also has a decent tag editor; finally, there is a simple [mutagen-based CLI tool](https://mutagen.readthedocs.io/en/latest/man/mid3v2.html).
## EMMS {#emms}
[EMMS](https://www.gnu.org/software/emms/) is the Emacs Multimedia System, a package that can get play things from various sources using various players. It is a part of Emacs, which means you can use the built-in version, but the git version has a few useful patches, so I advise to use the latter.
[EMMS](https://www.gnu.org/software/emms/) is the Emacs Multimedia System, a package that can get play stuff from various sources using various players. It is a part of Emacs, which means you can use the built-in version, but the git version has a few useful patches, so I advise using the latter.
Install it however you usually install packages in Emacs; I use use-package + straight:
@ -93,7 +93,7 @@ Install it however you usually install packages in Emacs; I use use-package + st
Now we have to configure EMMS. The following expressions have to be executed after EMMS is loaded, which means we can add them to the `:config` section of the `use-package` expression above.
First, EMMS exposes a handy function which loads all the stable EMMS features. You can take a look at its source and pick the features you need or load everything like this:
First, EMMS exposes a handy function that loads all the stable EMMS features. You can take a look at its source and pick the features you need or load everything like this:
```emacs-lisp
(require 'emms-setup)
@ -123,7 +123,7 @@ Now we can connect EMMS to MPD. For some reason, executing this function stops t
(emms-player-mpd-connect)
```
The last thing we may want is to link clearing EMMS playlist to clearing MPD playlist. I'm not sure how this interacts with MPD's own playlists because I don't use them, so you may need to watch out here if you do.
The last thing we may want is to link EMMS playlist clearing to MPD playlist clearing. I'm not sure how this interacts with MPD's own playlists because I don't use them, so you may need to watch out here if you do.
```emacs-lisp
(add-hook 'emms-playlist-cleared-hook 'emms-player-mpd-clear)
@ -132,20 +132,20 @@ The last thing we may want is to link clearing EMMS playlist to clearing MPD pla
### Usage {#usage}
One rough edge of EMMS & MPD integration is that EMMS and MPD have their separate libraries and playlists.
One rough edge of EMMS & MPD integration is that EMMS and MPD have separate libraries and playlists.
So, first we have to populate the MPD library with `M-x emms-player-mpd-update-all`. This operation is executed asyncronoulsly by MPD and may take a few minutes for the first run. The subsequent runs are much faster. You can do the same by invoking `mpc update` from the command line.
So, first we have to populate the MPD library with `M-x emms-player-mpd-update-all`. This operation is executed asynchronously by MPD and may take a few minutes for the first run. The subsequent runs are much faster. You can do the same by invoking `mpc update` from the command line.
Second, we have to populate the EMMS library (cache) from the MPD library. To do that, run `M-x emms-cache-set-all-from-mpd`. If something went wrong with EMMS cache, you always can clean it with `M-x emms-cache-reset`.
Second, we have to populate the EMMS library (cache) from the MPD library. To do that, run `M-x emms-cache-set-all-from-mpd`. If something went wrong with the EMMS cache, you always can clean it with `M-x emms-cache-reset`.
After this is done, we can finally play music! To do that, run `M-x emms-browser`. The left window should have the EMMS browser buffer with the loaded library, the right one should countain (as for now empty) playlist.
After this is done, we can finally play music! To do that, run `M-x emms-browser`. The left window should have the EMMS browser buffer with the loaded library, the right one should contain (as for now empty) playlist.
In the browser we can use the following commands to add elements to the playlist:
- `M-x emms-browser-toggle-subitems` (`<tab>` in evil, `SPC` in vanilla) to open/close the element under cursor
- `M-x emms-browser-add-tracks` (`RET` in both styles) to add the element under the cursor to the playlist
Now, we have a few tracks in the EMMS playlist, but they are not in MPD playlist yet.
Now, we have a few tracks in the EMMS playlist, but they are not in the MPD playlist yet.
In the EMMS playlist buffer, `M-x emms-playlist-mode-play-smart` (`RET`) will sync the playlists and start playing the song under the cursor. Also, use
@ -159,9 +159,9 @@ Take a look at the [EMMS manual](https://www.gnu.org/software/emms/manual/) for
One feature of ncmpcpp I was missing here is fetching lyrics, so I've written a small package to do just that.
Debugging the package turned out to be quite funny, because apparently, there is no way around parsing HTML with this task. So I've chosen genius.com as the source, but the site turned out to provide different versions of itself (with different DOMs!) to different users.
Debugging the package turned out to be quite funny because apparently, there is no way around parsing HTML with this task. So I've chosen genius.com as the source, but the site turned out to provide different versions of itself (with different DOMs!) to different users.
At any rate, I've processed the cases I found, and it seems to be working, at least for me. To use the package, [get the api key](https://genius.com/api-clients/new) from Genius and install it:
At any rate, I've processed the cases I found, and it seems to be working, at least for me. To use the package, [get the API key](https://genius.com/api-clients/new) from Genius and install it:
```emacs-lisp
(use-package lyrics-fetcher
@ -172,7 +172,7 @@ At any rate, I've processed the cases I found, and it seems to be working, at le
(password-store-get "My_Online/APIs/genius.com")))
```
To fetch lyrics for the current playing EMMS song, run `M-x lyrics-fetcher-show-lyrics`. Or run `M-x lyrics-fetcher-emms-browser-show-at-point` to fetch data for the current point in EMMS browser. See [the package homepage](https://github.com/SqrtMinusOne/lyrics-fetcher.el) for more information.
To fetch lyrics for the current playing EMMS song, run `M-x lyrics-fetcher-show-lyrics`. Or run `M-x lyrics-fetcher-emms-browser-show-at-point` to fetch data for the current point in the EMMS browser. See [the package homepage](https://github.com/SqrtMinusOne/lyrics-fetcher.el) for more information.
### Album covers {#album-covers}
@ -181,7 +181,7 @@ I've mentioned above that EMMS supports displaying album covers.
For this to work, it is necessary to have one album per one folder. By default the cover image should be saved to images named `cover_small` (100x100 recommended), `cover_medium` (200x200 recommended) and `cover_large`. The small version is to be displayed in the EMMS browser, the medium one in the playlist.
It's not required for images be exactly of these sizes, but they definitely should be of one size across different albums to look nice in the interface.
It's not required for images to be exactly of these sizes, but they definitely should be of one size across different albums to look nice in the interface.
You can resize images with ImageMagick with commands like this:
@ -195,7 +195,7 @@ convert cover.jpg -resize 200x200^ -gravity Center -extent 200x200 cover_medium.
## MPV and YouTube {#mpv-and-youtube}
[MPV](https://mpv.io/) is a nice extensible media player, which integrates with [youtube-dl](https://github.com/ytdl-org/youtube-dl) and is controllable by EMMS, so it fits quite nicely in this setup.
[MPV](https://mpv.io/) is an extensible media player, which integrates with [youtube-dl](https://github.com/ytdl-org/youtube-dl) and is controllable by EMMS, thus quite fitting for this setup.
### MPV and youtube-dl {#mpv-and-youtube-dl}
@ -205,10 +205,10 @@ First, install both `mpv` and `youtube-dl` from your distribution's package repo
Then we can add another player to the list:
```emacs-lisp
(add-to-list 'emms-player-list 'emms-player-mpv)
(add-to-list 'emms-player-list 'emms-player-mpv t)
```
EMMS determines which player to use by a regexp. `emms-player-mpd` sets the default regexp from MPD's diagnostic output, so that regex opens basically everything, including videos, https links, etc. That is fine if MPD is the only player in EMMS, but as we want to use MPV as well, we need to override the regexes.
EMMS determines which player to use by a regexp. `emms-player-mpd` sets the default regexp from MPD's diagnostic output so that regex opens basically everything, including videos, HTTPS links, etc. That is fine if MPD is the only player in EMMS, but as we want to use MPV as well, we need to override the regexes.
MPD regexp can look like this:
@ -280,13 +280,13 @@ All the added URLs stay in the EMMS cache after being played. We probably don't
### Where to get URLs? {#where-to-get-urls}
So, we are able to watch YouTube videos by URLs, but where to get URLs from? A natual solution is to use [elfeed](https://github.com/skeeto/elfeed) and RSS feeds.
So, we are able to watch YouTube videos by URLs, but where to get URLs from? A natural solution is to use [elfeed](https://github.com/skeeto/elfeed) and RSS feeds.
I've tried a bunch of options to get feeds for YouTube channels. The first one is [Invidious](https://api.invidious.io/), a FOSS YouTube frontend. The problem here is that various instances I tried weren't particularly stable (at least when I was using them) and hosting the thing by myself would be an overkill. And switching instances is causing duplicate entries in the Elfeed DB.
I've tried a bunch of options to get feeds for YouTube channels. The first one is [Invidious](https://api.invidious.io/), a FOSS YouTube frontend. The problem here is that various instances I tried weren't particularly stable (at least when I was using them) and hosting the thing by myself would be overkill. And switching instances is causing duplicate entries in the Elfeed DB.
The second option is to use YouTube's own RSS. The feed URL looks like `https://www.youtube.com/feeds/videos.xml?channel_id=<CHANNEL_ID>=`. [Here are](https://stackoverflow.com/questions/14366648/how-can-i-get-a-channel-id-from-youtube) a couple of options of figuring out `CHANNEL_ID` in case it's not easily available. The problem with YouTube RSS is that it uses fields which are not supported by elfeed, so the feed entry lacks a preview and description.
The second option is to use YouTube's own RSS. The feed URL looks like `https://www.youtube.com/feeds/videos.xml?channel_id=<CHANNEL_ID>=`. [Here are](https://stackoverflow.com/questions/14366648/how-can-i-get-a-channel-id-from-youtube) a couple of options of figuring out `CHANNEL_ID` in case it's not easily available. The problem with YouTube RSS is that it uses fields that are not supported by elfeed, so the feed entry lacks a preview and description.
As mine workaround, I've written a small [web-server](https://github.com/SqrtMinusOne/yt-rss) which converts a RSS feed from YouTube to an elfeed-compatible Atom feed. It doesn't do much, so you can just download the thing and launch it:
As my workaround, I've written a small [web-server](https://github.com/SqrtMinusOne/yt-rss) which converts an RSS feed from YouTube to an elfeed-compatible Atom feed. It doesn't do much, so you can just download the thing and launch it:
```bash
git clone https://github.com/SqrtMinusOne/yt-rss.git
@ -304,7 +304,7 @@ http://localhost:8000/<channel_id>?token=<token>
where `<token>` is set in `.env` file to the default value of `12345`.
### <span class="org-todo todo TODO">TODO</span> Elfeed {#elfeed}
### Elfeed {#elfeed}
[Elfeed](https://github.com/skeeto/elfeed) is an Emacs Atom & RSS reader. It's a pretty popular package with lots of information written over the years, so I'll cover just my particular setup.
@ -342,7 +342,7 @@ So, however you've got URLs for YouTube channels, put them into elfeed.
To fetch the feeds, open elfeed with `M-x elfeed` and run `M-x elfeed-search-fetch` in the search buffer. And as usual, take a look at [the package documentation](https://github.com/skeeto/elfeed) for more information.
To help navigating through the long list of entries, I've made the following function to narrow the search buffer to the feed of the entry under cursor:
To help with navigating through the long list of entries, I've made the following function to narrow the search buffer to the feed of the entry under cursor:
```emacs-lisp
(defun my/elfeed-search-filter-source (entry)
@ -393,7 +393,7 @@ The easiest way to put the URL to the playlist is to define a new source for EMM
Because `define-emms-source` is an EMMS macro, the code block above has to be evaluated with EMMS loaded. E.g. you can wrap it into `(with-eval-after-load 'emms ...)` or put in the `:config` section.
The macro defines a bunch of functions to work with source, which we can use in another function:
The macro defines a bunch of functions to work with the source, which we can use in another function:
```emacs-lisp
(defun my/elfeed-add-emms-youtube ()

View file

@ -172,14 +172,14 @@ convert cover.jpg -resize 200x200^ -gravity Center -extent 200x200 cover_medium.
=lyrics-fetcher= can (try to) do this automatically by downloading the cover from genius.com with =M-x lyrics-fetcher-emms-browser-fetch-covers-at-point= in EMMS browser.
* MPV and YouTube
[[https://mpv.io/][MPV]] is a nice extensible media player, which integrates with [[https://github.com/ytdl-org/youtube-dl][youtube-dl]] and is controllable by EMMS, so it fits quite nicely in this setup.
[[https://mpv.io/][MPV]] is an extensible media player, which integrates with [[https://github.com/ytdl-org/youtube-dl][youtube-dl]] and is controllable by EMMS, thus quite fitting for this setup.
** MPV and youtube-dl
First, install both =mpv= and =youtube-dl= from your distribution's package repository.
Then we can add another player to the list:
#+begin_src emacs-lisp
(add-to-list 'emms-player-list 'emms-player-mpv)
(add-to-list 'emms-player-list 'emms-player-mpv t)
#+end_src
EMMS determines which player to use by a regexp. =emms-player-mpd= sets the default regexp from MPD's diagnostic output so that regex opens basically everything, including videos, HTTPS links, etc. That is fine if MPD is the only player in EMMS, but as we want to use MPV as well, we need to override the regexes.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 637 KiB

After

Width:  |  Height:  |  Size: 928 KiB