python音乐管理命令行工具beets的使用(音频转码,标签管理,web音乐播放器,音乐数据库)

音乐管理命令行工具beets的使用(音频转码,标签管理,web音乐播放器,音乐数据库)

01.功能介绍

github上有的功能介绍,谷歌翻译一下贴过来

  • 提取或计算您可能需要的所有元数据:专辑封面,歌词,流派,节奏,ReplayGain级别或声学指纹。
  • 从MusicBrainz,Discogs和Beatport获取元数据。 或者使用歌曲的文件名或其声学指纹来猜测元数据。
  • 将音频转码为您喜欢的任何格式。
  • 检查您的音乐库中是否有重复的曲目和专辑,或者缺少曲目的专辑。
  • 清理其他不那么出色的工具留下的粗糙标签。
  • 从文件的元数据嵌入和提取专辑封面。
  • 通过Web浏览器以图形方式浏览音乐库,并在任何支持HTML5音频的浏览器中播放。
  • 从命令行分析音乐文件的元数据。
  • 使用会说MPD协议并具有多种惊人接口的音乐播放器来聆听您的音乐库。

02.安装

这是基于python开发的软件,可以使用pip包管理器来安装。

pip install beets

然后可以查看帮助文档
beet -h

beet.exe
Usage:
  beet COMMAND [ARGS...]
  beet help COMMAND

Options:
  --format-item=FORMAT_ITEM
                        print with custom format
  --format-album=FORMAT_ALBUM
                        print with custom format
  -l LIBRARY, --library=LIBRARY
                        library database file to use
  -d DIRECTORY, --directory=DIRECTORY
                        destination music directory
  -v, --verbose         log more details (use twice for even more)
  -c CONFIG, --config=CONFIG
                        path to configuration file
  -h, --help            show this help message and exit

Commands:
  config            show or edit the user configuration
  fields            show fields available for queries and format strings
  help (?)          give detailed help on a specific sub-command
  import (imp, im)  import new music
  list (ls)         query the library
  modify (mod)      change metadata fields
  move (mv)         move or copy items
  remove (rm)       remove matching items from the library
  stats             show statistics about the library or a query
  update (upd, up)  update the library
  version           output version information
  write             write tag information to files

可以去看官方的帮助文档 https://beets.readthedocs.io/en/stable/index.html

官网 https://beets.io/

03.快速上手

001.首先进行一些基础的配置

输入下面的命令找到配置文件的位置

beet config -p

我是win10系统,显示的地址是这样的C:\Users\yonghuming\AppData\Roaming\beets\config.yaml

输入下面的命令会打开默认编辑器编辑配置文件,会根据$editor变量确定你的默认编辑器

beet config -e

我这边没有设置默认编辑器,所以直接用notepad打开那个文件。

一开始配置文件是空的,需要你加上一点东西。

首先是指定你的音乐文件夹的目录

directory: C:/MySQMusic
library: C:/MySQMusic/musiclibrary.db

这个软件的默认设定会假定你要创建一个新的有组织的音乐库,当你使用import命令时会把对象清理干净(加标签,标签纠错之类)后复制到你的音乐库文件夹里面。

如果你不要复制,而是移动文件,加入下面的一条

import:
    move: yes

如果你想保持现在的目录结构(这个应该是最常用的,这样就能兼容我原来按歌单建的文件夹了),只纠正标签,那么在import下面加上copy: no

ps:它默认的目录结构是歌手》专辑》歌这样子,对于我这种听歌从来不按专辑,哪首好听就把哪首加歌单的人来说没什么意义

如果你想保持原来的标签不修改,文件名也不重命名,那么在import后面加上write:no

这样就是既不拷贝,也不修改,只是把歌曲信息录入数据库而已。

然后这个软件自动修改标签后,修改之前的标签也会留在数据库里,你还可以把他们变回来。

使用命令beet config -d,查看默认配置,看看总共有哪些配置,然后我们照着这个配置文件修改就可以了

library: library.db
directory: ~/Music
import:
    write: yes
    copy: yes
    move: no
    link: no
    hardlink: no
    delete: no
    resume: ask
    incremental: no
    incremental_skip_later: no
    from_scratch: no
    quiet_fallback: skip
    none_rec_action: ask
    timid: no
    log:
    autotag: yes
    quiet: no
    singletons: no
    default_action: apply
    languages: []
    detail: no
    flat: no
    group_albums: no
    pretend: no
    search_ids: []
    duplicate_action: ask
    bell: no
    set_fields: {}

clutter: [Thumbs.DB, .DS_Store]
ignore:
- .*
- '*~'
- System Volume Information
- lost+found
ignore_hidden: yes

replace:
    '[\\/]': _
    ^\.: _
    '[\x00-\x1f]': _
    '[<>:"\?\*\|]': _
    \.$: _
    \s+$: ''
    ^\s+: ''
    ^-: _
path_sep_replace: _
asciify_paths: no
art_filename: cover
max_filename_length: 0

aunique:
    keys: albumartist album
    disambiguators: albumtype year label catalognum albumdisambig releasegroupdisambig
    bracket: '[]'

overwrite_null:
    album: []
    track: []

plugins: []
pluginpath: []
threaded: yes
timeout: 5.0
per_disc_numbering: no
verbose: 0
terminal_encoding:
original_date: no
artist_credit: no
id3v23: no
va_name: Various Artists

ui:
    terminal_width: 80
    length_diff_thresh: 10.0
    color: yes
    colors:
        text_success: green
        text_warning: yellow
        text_error: red
        text_highlight: red
        text_highlight_minor: lightgray
        action_default: turquoise
        action: blue

format_item: $artist - $album - $title
format_album: $albumartist - $album
time_format: '%Y-%m-%d %H:%M:%S'
format_raw_length: no

sort_album: albumartist+ album+
sort_item: artist+ album+ disc+ track+
sort_case_insensitive: yes

paths:
    default: $albumartist/$album%aunique{}/$track $title
    singleton: Non-Album/$artist/$title
    comp: Compilations/$album%aunique{}/$track $title

statefile: state.pickle

musicbrainz:
    host: musicbrainz.org
    ratelimit: 1
    ratelimit_interval: 1.0
    searchlimit: 5

match:
    strong_rec_thresh: 0.04
    medium_rec_thresh: 0.25
    rec_gap_thresh: 0.25
    max_rec:
        missing_tracks: medium
        unmatched_tracks: medium
    distance_weights:
        source: 2.0
        artist: 3.0
        album: 3.0
        media: 1.0
        mediums: 1.0
        year: 1.0
        country: 0.5
        label: 0.5
        catalognum: 0.5
        albumdisambig: 0.5
        album_id: 5.0
        tracks: 2.0
        missing_tracks: 0.9
        unmatched_tracks: 0.6
        track_title: 3.0
        track_artist: 2.0
        track_index: 1.0
        track_length: 2.0
        track_id: 5.0
    preferred:
        countries: []
        media: []
        original_year: no
    ignor: []
    required: []
    ignored_media: []
    ignore_data_tracks: yes
    ignore_video_tracks: yes
    track_length_grace: 10
    track_length_max: 30

具体参数的解释,看这篇帮助文档 https://beets.readthedocs.io/en/stable/reference/config.html

002.导入音乐库

导入音乐库之前注意要做好备份,因为这个操作设计到修改文件和移动文件相关的操作。

有两种把你的音乐库加入数据库的方式

a)使用现存的元数据,不进行改动

b) 让beet自动查询数据来修改你的音乐的元数据,添加标签之类的。

如果是方式b的话,可能消耗很长时间,并且有些修改操作会询问你。

执行下面的命令。import你想导入的目录即可,这样就会自动修改标签了

$ beet import /path/to/my/music

如果你不想自动修改标签,使用-A选项,表示don’t autotag

$ beet import -A /my/huge/mp3/library

除了导入音乐库,添加新音乐的时候也是用import命令

03.自动标签机制

001.机制解释

beet import 命令在一个文件夹中执行后会自动把音乐文件加入到你的音乐库,并且给他们完善标签。(除非你传递-noautotag选项) import默认设定在导入音乐的过程中有一些假定的限制,

  • 音乐必须按照专辑分目录,每个专辑都是一个目录。这个设定也有一些例外,
    • 一、比如看起来像是多碟专辑的目录,比如两个目录名字都含有disk,或者都含有cd加上数字,这些会进入一个专辑里
    • 二、如果你把一个目录中不小心混了多个目录,可以用beet把他们根据元数据(metadata)重新分好目录,用--group-albums选项
  • 音乐标签可能很不完善,默认会根据存在的元数据来查找tag,但是还有其他的一些解决方案,
    • 使用E和I选项描述如何从MusicBrainz查找专辑或者歌曲
    • 使用听歌识曲插件Acoustid plugin
    • 使用FromFilename plugin 插件,可以从文件名帮助猜测tag。比如 ’03 Call Me Maybe.mp3‘这样的文件名包含歌名的。
  • 目前支持的格式有 MP3, AAC, FLAC, ALAC, Ogg Vorbis, Monkey’s Audio, WavPack, Musepack, Windows Media, Opus, and AIFF

002.选项

To import music, just say beet import MUSICDIR. There are, of course, a few command-line options you should know:

  • beet import -A: don’t try to autotag anything; just import files (this goes much faster than with autotagging enabled)
  • beet import -W: when autotagging, don’t write new tags to the files themselves (just keep the new metadata in beets’ database)
  • beet import -C: don’t copy imported files to your music directory; leave them where they are
  • beet import -m: move imported files to your music directory (overrides the -c option)
  • beet import -l LOGFILE: write a message to LOGFILE every time you skip an album or choose to take its tags “as-is” (see below) or the album is skipped as a duplicate; this lets you come back later and reexamine albums that weren’t tagged successfully
  • beet import -q: quiet mode. Never prompt for input and, instead, conservatively skip any albums that need your opinion. The -ql combination is recommended.
  • beet import -t: timid mode, which is sort of the opposite of “quiet.” The importer will ask your permission for everything it does, confirming even very good matches with a prompt.
  • beet import -p: automatically resume an interrupted import. The importer keeps track of imports that don’t finish completely (either due to a crash or because you stop them halfway through) and, by default, prompts you to decide whether to resume them. The -p flag automatically says “yes” to this question. Relatedly, -P flag automatically says “no.”
  • beet import -s: run in singleton mode, tagging individual tracks instead of whole albums at a time. See the “as Tracks” choice below. This means you can use beet import -AC to quickly add a bunch of files to your library without doing anything to them.
  • beet import -g: assume there are multiple albums contained in each directory. The tracks contained a directory are grouped by album artist and album name and you will be asked to import each of these groups separately. See the “Group albums” choice below.

003.相似度

当导入音乐库时,相似度低的匹配会向你询问。

$ beet imp witchinghour
Tagging:
    Ladytron - Witching Hour
(Similarity: 98.4%)
* Last One Standing      -> The Last One Standing
* Beauty                 -> Beauty*2
* White Light Generation -> Whitelightgenerator
* All the Way            -> All the Way...

004.选择

When beets needs your input about a match, it says something like this:

Tagging:
    Beirut - Lon Gisland
(Similarity: 94.4%)
* Scenic World (Second Version) -> Scenic World
[A]pply, More candidates, Skip, Use as-is, as Tracks, Enter search, enter Id, or aBort?

When beets asks you this question, it wants you to enter one of the capital letters: A, M, S, U, T, G, E, I or B. That is, you can choose one of the following:

  • A: Apply the suggested changes shown and move on.
  • M: Show more options. (See the Candidates section, below.)
  • S: Skip this album entirely and move on to the next one.
  • U: Import the album without changing any tags. This is a good option for albums that aren’t in the MusicBrainz database, like your friend’s operatic faux-goth solo record that’s only on two CD-Rs in the universe.
  • T: Import the directory as singleton tracks, not as an album. Choose this if the tracks don’t form a real release—you just have one or more loner tracks that aren’t a full album. This will temporarily flip the tagger into singleton mode, which attempts to match each track individually.
  • G: Group tracks in this directory by album artist and album and import groups as albums. If the album artist for a track is not set then the artist is used to group that track. For each group importing proceeds as for directories. This is helpful if a directory contains multiple albums.
  • E: Enter an artist and album to use as a search in the database. Use this option if beets hasn’t found any good options because the album is mistagged or untagged.
  • I: Enter a metadata backend ID to use as search in the database. Use this option to specify a backend entity (for example, a MusicBrainz release or recording) directly, by pasting its ID or the full URL. You can also specify several IDs by separating them by a space.
  • B: Cancel this import task altogether. No further albums will be tagged; beets shuts down immediately. The next time you attempt to import the same directory, though, beets will ask you if you want to resume tagging where you left off.

005.候选选项

If you choose the M option, or if beets isn’t very confident about any of the choices it found, it will present you with a list of choices (called candidates), like so:

Finding tags for "Panther - Panther".
Candidates:
1. Panther - Yourself (66.8%)
2. Tav Falco's Panther Burns - Return of the Blue Panther (30.4%)
# selection (default 1), Skip, Use as-is, or Enter search, or aBort?

Here, you have many of the same options as before, but you can also enter a number to choose one of the options that beets has found. Don’t worry about guessing—beets will show you the proposed changes and ask you to confirm them, just like the earlier example. As the prompt suggests, you can just hit return to select the first candidate.

04.高级使用

这里主要是关于配置文件和各种插件的。

001.获取封面,专辑类别和歌词

配置中加入这三个插件即可

plugins: fetchart lyrics lastgenre

注意,有些插件有自己特殊依赖需要单独安装,使用pip安装即可

pip install beets[fetchart,lyrics,lastgenre]

002.自定义文件和文件夹名

关于路径名配置有一个文档 可以看 https://beets.readthedocs.io/en/stable/reference/config.html#path-format-config

为了灵活设置文件夹名和文件名有两点需要知道:

  • 模板函数,可以用来给你的路径名加上一点逻辑操作,比如,找到一个艺术家的首字母 %upper{%left{$albumartist,1}}
  • 如果需要更加灵活, Inline Plugin 这个插件可以支持使用python代码生成文件名,还是获取艺术家首字母的例子initial: albumartist[0].upper()

003.使你的音乐能通过网络访问

安装 Web Plugin插件,beet web 运行服务器后,你可以通过地址用浏览器访问。

004.格式转换

安装 Convert Plugin插件,需要安装ffmpeg,查看它的帮助文档https://beets.readthedocs.io/en/stable/plugins/convert.html

005.存储自定义字段

beets数据库有很多内置字段,你也可以自己设置一些新字段

比如说你想决定音乐什么时候播放,比如说某音乐家的音乐适合派对的时候播放

你需要创造一个context属性在记录这个值,使用modify命令

beet modify context=party artist:'beastie boys'

执行这个命令后,beets会询问你让你做出选择

你也可以用自己定义的字段来查询

beet ls context:mope

自定义字段甚至可以用在文件名定义中

删除操作,执行下面的代码

beet modify context! artist:'beastie boys

006.手动设置路径样式

之前有讲过整体的路径样式的配置。但是有时候,你想要对某些音乐进行独立配置。

比如说有些你不怎么喜欢的音乐,但是为了播放给朋友和家人听需要保存。

我们就可以像上面005一样用一个灵活的属性来存储一个标记用于分类

比如

beet modify bad=1 christmas

然后你就可以查询这个字段了。可以用不同的排序方式,也可以在配置文件中进行配置

paths:
    bad:1: Bad/$artist/$title

你可能感兴趣的:(python音乐管理命令行工具beets的使用(音频转码,标签管理,web音乐播放器,音乐数据库))