[Translated]How to manage your music library from the command line on Linux

This commit is contained in:
geekpi 2014-05-04 11:37:51 +08:00
parent 85660b4860
commit 15e1671ed0
2 changed files with 157 additions and 161 deletions

View File

@ -1,161 +0,0 @@
Translating-------geekpi
How to manage your music library from the command line on Linux
================================================================================
The command line in Linux is probably one of the scariest experience for a newcomer there is. I remember spending hours back in the day trying to decode an error message in my terminal. However, it was completely worth it. If I had to pick only one reason for a newcomer to learn to deal with the command line properly today, it would probably be for the possibility to manage a music library entirely from the terminal. The software I prefer to do this is [cmus][1], short for "C* MUsic Player" as it is written entirely in C.
cmus is a powerful music file manager with a built-in audio player. Using its ncurses based terminal interface, you can browse your music library, and play music from playlists or queues, all from the command line.
### Install cmus on Linux ###
First, you will need to set up and install cmus as follows.
On Ubuntu, Debian or Linux Mint:
$ sudo apt-get install cmus
On Fedora, first [enable RPM Fusion repository][2], and then run:
$ sudo yum install cmus
On CentOS, first [enable Repoforge repository][3], and then run:
$ sudo yum install cmus
On Archlinux:
$ sudo pacman -S cmus
After installation, you can launch cmus simply by typing:
$ cmus
### Import [Music Files][4] to cmus ###
The first thing to do is to import your music files into your library. This process will immediately reveal two things: that the shortcuts are inspired by vim's, and that cmus is incredibly fast. I have successfully imported over a thousand songs in less than twenty seconds! Try that with iTunes or any graphical music library software, and you will have time to make a peanut butter sandwich before it's done.
To import music files on cmus, type the following vim-like command on cmus.
:a /path/to/your/music/folder
So on Xubuntu I did:
:a /home/adrien/Music/
Then all the music files in that folder appeared sorted by artist and album instantly.
![](https://farm6.staticflickr.com/5522/14021555743_b3c545702e_z.jpg)
### Quick Start ###
Before starting anything, you might want to memorize the basic shortcuts to start playing your music. That is the only downside to cmus. Unless you change them, the default shortcuts are not very intuitive, and you have to learn them. In short:
- **x** to play or replay a track
- **c** to pause
- **b** to play the next track
- **z** to play the previous track
- **s** to activate the shuffle
With that, you should be ready to start!
### Basic Usage ###
The interface of cmus is composed of seven tabs, that you access by hitting the appropriate number. For example, the startup screen is the "tree" tab that you can access at any time by hitting 1. This tab is pretty intuitive to use: navigate though the artist on the left panel with the up and down keys, press space to see the albums for a particular artist, use the tab key to switch to right panel with the individual songs, and finally the return key to play a song.
![](https://farm8.staticflickr.com/7174/13998349312_74c4586d17_z.jpg)
As you can see, the bottom banner displays the name of the artist, the album, and the title of the song currently playing, as well as the timing and the volume.
The second tab is similar to the first as it just displays the list of all the songs sorted by artist.
![](https://farm8.staticflickr.com/7080/13998371701_be03208c2f_z.jpg)
However, the third tab is much more interesting as it displays the current playlist. To add a song from the tree view or the sorted list view to the playlist just type "y" over the selected song. Once you created the perfect playlist, save it with the command.
:save /path/to/playlist
and load it with:
:load /path/to/playlist
![](https://farm8.staticflickr.com/7385/13978441446_2c10f35507_z.jpg)
The fourth tab displays the queue. The difference between the queue and a playlist is that once a song is played from the queue, it is then removed. To add a song to the queue, do it like adding it to the playlist, but instead use the shortcut: "e"
![](https://farm8.staticflickr.com/7201/14001984094_58719269c3_z.jpg)
The fifth tab is pretty interesting too as it is a lightweight file explorer. It can be pretty useful to read a musical file somewhere on your computer without adding it to your library. The navigation is pretty standard: move with the up and down keys, and return to enter a folder or select a file.
![](https://farm6.staticflickr.com/5217/14001984224_785aac0ddb_z.jpg)
The sixth tab is the library filters used to dynamically create a playlist. Just as it sounds, filters actually go through your library, and only display the tracks corresponding to some criteria defined. I will go through defining your own filters later on, but cmus already comes with a few ones. To try one, just use:
:filter [name of the filter]
So for example:
:filter classical
It will hide all the tracks from your library, except the ones containing "Classical" in their genre tag.
![](https://farm8.staticflickr.com/7245/14001543625_a508ec9304_z.jpg)
Finally, last but not least, the seventh tab is the settings. In there you can define your own shortcuts and commands. I will give an example in the next section.
![](https://farm6.staticflickr.com/5079/13998371761_df1f9b7fae_z.jpg)
### Advanced Usage ###
As promised, now that you are more familiar with the interface, I shall give you more tips to enhance your experience.
To search for anything in any tab, just use the same shortcut as in vim
/[keyword]
and:
n
to look for the next occurrence of the keyword.
To create your own filters, use the syntax:
:fset [name of the new filter]=[expression]
For example, you can find all the old rock track with:
:fset oldies=genre="Rock"&date<1970
To learn more about the expressions you can use, I invite you to dig a bit in the doc and the included filters.
To activate the replaygain for all the tracks, use the command:
:set replaygain=1
To change a shortcut to a different key, go to the settings tab and find the current binding expression. Say for example that I want to change the play shortcut from "x" to "w", I will then scroll until the line that says:
common x player-play
Then hit enter, and change the expression to:
:bind -f common w player-stop
To conclude, I really like cmus. There is a lot more to it than the reach of this post, so you should really read the [manual page][5] when you are ready. In short, cmus is fast, easy to learn, and respects your files. If you like the idea of managing your music library from the command line, but were not convinced by cmus, I invite you to take a shot at some alternatives like MOC and PyTone which are just as good.
What do you think of cmus? Do you like it or prefer a (non)GUI alternative? Let us know in the comments.
--------------------------------------------------------------------------------
via: http://xmodulo.com/2014/04/manage-music-library-command-line-linux.html
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:https://cmus.github.io/
[2]:http://xmodulo.com/2013/06/how-to-install-rpm-fusion-on-fedora.html
[3]:http://xmodulo.com/2013/01/how-to-set-up-rpmforge-repoforge-repository-on-centos.html
[4]:http://xmodulo.com/go/mp3
[5]:https://github.com/cmus/cmus/blob/master/Doc/cmus.txt

View File

@ -0,0 +1,157 @@
如何在Linux的命令行中管理你的音乐库
================================================================================
linux下的命令行可能是对于新手而言最恐怖的经历了。我记得花费数天的时间来尝试解码终端中错误信息。然而这是完全值得的。如果我如今让我说只说一个让新手学习学习命令行的原因那可能是完全可以在命令行中管理音乐库。我喜欢用的软件是[cmus][1],是"C* MUsic Player"(C音乐播放器)的简写由于它完全由C写成。
cmus是一个强力的内置音频播放器的音乐文件管理器。使用它基于ncurses的命令行界面你可以浏览你的音乐库并从播放列表或队列中播放音乐这一切都在命令行下。
### Linux上安装cmus ###
首先你需要如下设置并安装cmus。
在Ubuntu, Debian 或者Linux Mint中:
$ sudo apt-get install cmus
在Fedora上首先[启用RPM Fusion仓库][2],接着运行:
$ sudo yum install cmus
在CentOS上首先[启用Repoforge仓库][3],接着运行:
$ sudo yum install cmus
在Archlinux上:
$ sudo pacman -S cmus
安装完之后在命令行下如下输入就可运行cums:
$ cmus
### 导入 [音乐文件][4] 到 cmus ###
第一件要做的事情是导入你的音乐文件到你的库中。这个过程马上揭露了两件事情快捷方式是受到了vim的启发还有cmus运行的很快。我已经在20秒之内成功地导入了超过1000首歌 在iTunes或者其他任何图形音乐库软件下试一下你就会有足够的时间来做一份花生酱三明治。
要在cmus下面导入音乐输入下面的像vim一样的命令。
:a /path/to/your/music/folder
在我的Xubuntu上我这么做:
:a /home/adrien/Music/
接下来这个目录下所有的音乐文件会立马按照艺术家或者专辑的方式排列显示。
![](https://farm6.staticflickr.com/5522/14021555743_b3c545702e_z.jpg)
### 快速入门 ###
在开始前你可能希望记住一些基本快捷方式来开始播放你的音乐。这是cmus的唯一缺点。除非你改变它们否则默认的快捷方式并不直观并且你不得不学习它们。简而言之:
- **x** 播放或重播音乐
- **c** 暂停
- **b** 播放下一首音乐
- **z** 播放前一首音乐
- **s** 激活随机播放
掌握完后,你应该已经准备好开始了!
### 基本使用 ###
cmus的界面由7个标签组成你可以按下适当的数字键来访问。比如启动页面是一个树形标签界面你随时可以通过按下1来访问。这个标签可以很直观地来使用通过上下键来导航位于左侧面板的艺术家按下空格就可以看到特定艺术家的专辑使用tab键来切换到右侧面板来选择独立的歌曲最后按下回车键来播放音乐。
![](https://farm8.staticflickr.com/7174/13998349312_74c4586d17_z.jpg)
如你所见,底部显示了艺术家的名字,专辑,和正在播放歌曲的标题,还有时间和音量。
第二个标签与第一个刚才显示的类似,显示了按照艺术家排列的歌曲列表。
![](https://farm8.staticflickr.com/7080/13998371701_be03208c2f_z.jpg)
然而,第三个标签更加有趣,因为他显示了目前的播放列表。要在树形视图或者列表视图下增加一首歌曲,只要在选中的歌曲上输入'y'。一旦创建完成后,用命令行保存下来。
:save /path/to/playlist
用下面命令加载:
:load /path/to/playlist
![](https://farm8.staticflickr.com/7385/13978441446_2c10f35507_z.jpg)
第四个标签显示的是队列。队列与播放列表的一点不同是,一旦歌曲是按队列播放的,播放结束后就会被移出队列。要把一首歌加入队列,就像把它加到播放列表一样,但是使用快捷方式:"e"
![](https://farm8.staticflickr.com/7201/14001984094_58719269c3_z.jpg)
第五个标签也同样很有趣,因为它是一个轻量级的文件浏览器。当你在你的电脑中查找一首歌曲而不必加入到库中的时候很有用。导航方式也非常标准:用向上或者向下键,回车键用来进入文件夹或者选中一个文件。
![](https://farm6.staticflickr.com/5217/14001984224_785aac0ddb_z.jpg)
第六标签是一个库过滤器用来动态创建播放列表。如它听上去的那样过滤器会遍历你的库并且只显示符合相关规则定义的音乐。之后我会描述定义你自己的过滤器但是cmus已经自带了一些。要试一下只要使用:
:filter [name of the filter]
比如:
:filter classical
除了"Classical"标签的音乐,它会隐藏你库中所有的音乐。
![](https://farm8.staticflickr.com/7245/14001543625_a508ec9304_z.jpg)
最后但同样重要的,第七个标签是设置。在这里,你可以定义你的快捷方式和命令。我会在下一部分给你一些例子。
![](https://farm6.staticflickr.com/5079/13998371761_df1f9b7fae_z.jpg)
### 高级用法 ###
正如承诺那样,你现在已经更加熟悉界面了,我会给你一些贴士来增强你的体验。
要在标签中搜索任何东西只要如vim那样使用相同的快捷方式
/[keyword]
还有:
n
来搜索下一处关键字。
要创建一个你的过滤器,使用语法:
:fset [name of the new filter]=[expression]
比如,你可以找到所有的老的摇滚音乐:
:fset oldies=genre="Rock"&date<1970
要了解更多关于你可以使用的表达式,我邀请你更多地在文档中挖掘已有的过滤器。
要激活重新播放所有的音乐,使用如下命令:
:set replaygain=1
要改变快捷方式到不同的键上,进入设置标签并找出现有的绑定表达式。举个例子来说,我想要将播放快捷方式从"x"改到"w",我会翻到下面的行:
common x player-play
接着按下回车,并改成下面的表达式
:bind -f common w player-stop
总的来说我真的喜欢cmus。它还有许多本篇中没有提到的技巧因此在你准备好后应该认真要读一下[man帮组手册][5]。简而言之cmus是一款快速易于学习尊重你的文件的软件。如果你喜欢从命令行下管理音乐库的想法但是还没对cmus深信不疑我邀请你先试一下一些替代品如MOC和PyTone它们同样也很棒。
你认为cmus怎么样你喜欢它么或者作为GUI的替代品让我在评论区知道你们的想法。
--------------------------------------------------------------------------------
via: http://xmodulo.com/2014/04/manage-music-library-command-line-linux.html
译者:[geekpi](https://github.com/geekpi) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:https://cmus.github.io/
[2]:http://xmodulo.com/2013/06/how-to-install-rpm-fusion-on-fedora.html
[3]:http://xmodulo.com/2013/01/how-to-set-up-rpmforge-repoforge-repository-on-centos.html
[4]:http://xmodulo.com/go/mp3
[5]:https://github.com/cmus/cmus/blob/master/Doc/cmus.txt