Commit graph

267 commits

Author SHA1 Message Date
wisp3rwind
feb5041f57 replaygain: remove debugging leftovers 2021-03-18 14:29:28 +01:00
Aksh Gupta
79858975a9 chore: refactor code quality issues 2021-03-11 08:45:42 +05:30
Samuel Cook
ff4cec2e69
Removes support for bs1770gain.
References in the documentation to this plugin were removed in
beetbox/beets#3127 (beetbox/beets#3130) but no actual code
changes were made.

This PR removes support for this dependency entirely.
2021-01-27 17:42:18 -08:00
ybnd
eb8ba838e5 Check 'auto' on import_begin 2020-12-22 12:45:28 +01:00
ybnd
93101e7ea6 Disable replaygain parallelism during import 2020-12-21 19:19:20 +01:00
ybnd
12db40fa67 Remove .get() when checking config values 2020-12-21 08:50:39 +01:00
ybnd
1dfd79e658 Fix logic for replaygain auto-compute on import 2020-12-20 19:38:21 +01:00
ybnd
363f71af2e Move OperationalError handler to test_replaygain.py 2020-12-14 22:10:54 +01:00
ybnd
e1876590ba Fix replaygain.py to pass test_replaygain.py 2020-08-12 12:49:16 +02:00
ybnd
72710cd8c7 Merge branch 'master' into parallel-replaygain 2020-08-12 11:59:32 +02:00
ybnd
50757d34ad Fix conflicts 2020-08-12 11:42:18 +02:00
Adrian Sampson
5db2b4ccaa Fix new flake8 warnings 2020-05-13 08:20:50 -04:00
Adrian Sampson
47deb2f084 Switch log level for #3563, fix #3533 2020-04-23 08:03:51 -04:00
Michal Koutenský
5143e630d8 Fix #3533 - crash when calculating RG/R128 mix 2020-04-23 11:05:33 +02:00
ybnd
63ea17365a Modify patched stdout in test_malformed_output 2020-02-05 09:04:24 +01:00
ybnd
7005691410 Add comment to clarify unexpected AttributeError handling 2020-02-05 08:52:50 +01:00
ybnd
9bd78424c1 Handle keyboard interrupts more cleanly 2020-02-04 19:16:33 +01:00
ybnd
4970585b0a Remove temporary workaround for silent exceptions 2020-01-31 14:08:28 +01:00
ybnd
4a427182cd Handle exceptions in pooled threads
* ExceptionWatcher instance running in parallel to the pool, monitoring a queue for exceptions
* Pooled threads push exceptions to this queue, log non-fatal exceptions
* Application exits on fatal exception in pooled thread

* More front end info logs in the CLI
2020-01-31 13:50:38 +01:00
ybnd
bef473c8e8 Remove spliced progress regex and add --suppress-progress flag 2020-01-31 07:42:50 +01:00
ybnd
506be02597 Remove packaging dependency 2020-01-30 20:11:09 +01:00
ybnd
f51a68c7e1 Implement comments 2020-01-30 19:53:05 +01:00
ybnd
c3817a4c06 Implement review comments
* safer version comparison

* regex bytes directly

* handle b'\x08 ...' case

* test_replaygain.py: injected command output should match the type of the actual output
2020-01-30 19:21:53 +01:00
ybnd
65ffca215a Exception handling in main & worker threads
* With `bs1770gain` installed the `Bs1770gainBackend` tests fail, but this should be fixed by https://github.com/beetbox/beets/pull/3480.
2020-01-30 18:04:20 +01:00
ybnd
c1cb78c908 Small fixes in replaygain.Bs1770gainBackend and test_replaygain.py
* Fix unspecified `gain_adjustment` when method defined in config

* Fix difference between dB and LUFS values in case of mismatched `target_level`/`method`:

  ```
  db_to_lufs( target_level <dB> ) - lufs_to_dB( -23 <LUFS> )
  ```

* Ignore single assertion in case of bs1770gain

(cherry picked from commit 2395bf224032c44f1ea5d28e0c63af96a92b96df)
2020-01-30 17:59:57 +01:00
ybnd
c78afb1a97 Don't call bs1770gain outside of try statement 2020-01-30 17:02:28 +01:00
ybnd
53820c0a98 Handle bs1770gain v0.6.0 XML output
* Remove `0%\x08\x08` from output (backspace code doesn't resolve; progress percentages get spliced in)

* Handle changed attributes/fields:
  * `sample-peak` attribute `factor` is called `amplitude` instead
  * Album summary is not included in a `summary` tag now, but in two separate `integrated` and `sample-peak` tags

* Handle `lu` attribute

* Get bs1770gain version
  * If v0.6.0 or later, add `--unit=ebu` flag to convert `db` attributes to LUFS
  * May be useful later on

### Output examples

Track:
```
<!-- analyzing ... -->
<bs1770gain norm="-18.00">
  <track total="1" number="1" file="02 tïtle 0.mp3">
    <integrated lufs="-70.00" lu="52.00"/>
    <sample-peak spfs="-72.28" amplitude="0.00"/>
  </track>
  <integrated lufs="-70.00" lu="52.00"/>
  <sample-peak spfs="-72.28" amplitude="0.00"/>
</bs1770gain>
<!-- done. -->
```

Album:
```
<!-- analyzing ... -->
<bs1770gain norm="-18.00">
  <track total="2" number="1" file="02 tïtle 0.mp3">
    <integrated dbfs="-70.00" db="52.00"/>
    <sample-peak dbfs="-72.28" amplitude="0.00"/>
  </track>
  <track total="2" number="2" file="02 tïtle 1.mp3">
    <integrated dbfs="-70.00" db="52.00"/>
    <sample-peak dbfs="-72.28" amplitude="0.00"/>
  </track>
  <integrated dbfs="-70.00" db="52.00"/>
  <sample-peak dbfs="-72.28" amplitude="0.00"/>
</bs1770gain>
<!-- done. -->
```
2020-01-30 16:13:29 +01:00
ybnd
b903584163 Fix --threads argument handling 2020-01-30 13:31:14 +01:00
ybnd
b126ecafdd Clean up single/multithreaded execution selection logic
As suggested in https://github.com/beetbox/beets/pull/3478#discussion_r372467445
2020-01-30 12:38:20 +01:00
ybnd
0fede91bbd Workaround to pass ReplayGainLdnsCliMalformedTest.test_malformed_output ~ Python 3.8 2020-01-30 12:07:42 +01:00
ybnd
79c5535cf6 Open/close pool at begin/end of import session 2020-01-30 09:35:22 +01:00
ybnd
388d2d2c0d Consolidate ThreadPool checking, opening and closing into methods 2020-01-30 09:35:22 +01:00
ybnd
42e895c239 Match --jobs default & signature to that of convert plugin (--threads)
And change local function `func` to `ReplayGainPlugin` method `replaygain_func` so that `self` is passed explicitly
2020-01-30 09:35:22 +01:00
ybnd
d95bb5683b Analyze replaygain in parallel with multiprocessing.pool.ThreadPool
* Add `--jobs` or `-j` to `replaygain`-> set the pool size
* Single-threaded execution by default, if `--jobs` is unset

* If multithreaded, calls `Backend.compute_album_gain` or `Backend.compute_track_gain` asynchronously with metadata storing/writing in the callback
2020-01-28 21:20:21 +01:00
Jack Wilsdon
d91da56745
Fix various typos 2019-10-10 08:50:09 +01:00
Samuel Nilsson
6e24669d61 Fix #3341 2019-08-03 22:51:40 +02:00
Samuel Nilsson
60c174101f ffmpeg replaygain backend: Only calculate replaygain for audio stream. Fixed documentation for backend option. 2019-07-29 10:32:19 +02:00
Zsin Skri
a9f70f8151 apply suggested improvements
Apply improvements suggested in GitHub PullRequest #3065:
- be idiomatic
  - 0 is falsy
  - check enum equality, not identity
  - mutate list by constructing a new one
- improve documentation
  - fix a typo
  - do not mention deprecation of a config option
2019-07-26 01:02:03 +02:00
Zsin Skri
e7e2c424e7 replaygain: targetlevel and peak_method depends on tag format
Allow to configure the target level for R128_* tags separately from REPLAYGAIN_*
tags and skip peak calculation for R128_* tags if possible.
2019-07-22 13:42:22 +02:00
Zsin Skri
0c8eead459 replaygain: pass target_level and peak to backends
Configure the replaygain analysis by passing arguments to the Backends. This
avoids the difference between ReplayGain and EBU r128 backends; every Backend
can now fulfil both tasks. Additionally it eases Backend development as the
difference between the two tag formats is now completely handled in the main
Plugin, not in the Backends.
2019-07-22 12:58:54 +02:00
Zsin Skri
e5f2fe6fd3 avoid test failure
Use the POSIX character class instead of `\s` to match all whitespace in a
regular expression describing the language of valid inputs, in order to avoid a
test failure for the invalid escape sequence `\s` in Python strings.
2019-07-21 01:28:16 +02:00
Zsin Skri
f9ff56f496 improve wording in the ffmpeg replaygain backend
This commit mostly addresses feedback:
- remove some unused parenthesis
- fix a typo
- expand some docstrings
- document that ffmpeg is usually easy to install
2019-07-21 01:18:49 +02:00
Zsin Skri
271a3c980c replaygain: ffmpeg: increase parser readability
Use keyword arguments to make the ffmpeg parser more readable.
2019-07-19 21:54:47 +02:00
Zsin Skri
c3af5b3763 replaygain: add ffmpeg backend
Add replaygain backend using ffmpeg's ebur128 filter.

The album gain is calculated as the mean of all BS.1770 gating block powers.
Besides differences in gating block offset, this should be equivalent to a
BS.1770 analysis of a proper concatenation of all tracks.

Just calculating the mean of all track gains (as implemented by the bs1770gain
backend) yields incorrect results as that would:
- completely ignore track lengths
  - just using length in seconds won't work either (e.g. BS.1770 ignores
    passages below a threshold)
- take the mean of track loudness, not power

When using the ffmpeg replaygain backend to create R128_*_GAIN tags, the
targetlevel will be set to -23 LUFS. GitHub PullRequest #3065 will make this
configurable.
It will also skip peak calculation, as there is no R128_*_PEAK tag.

It is checked if the libavfilter library supports replaygain calculation. Before
version 6.67.100 that did require the `--enable-libebur128` compile-time-option,
after that the ebur128 library is included in libavfilter itself. Thus we
require either a recent enough libavfilter version or the `--enable-libebur128`
option.
2019-07-19 21:54:47 +02:00
Zsin Skri
7a7314ee3f Allow other ReplayGain backends to support R128.
Previously using EBU R128 forced the use of the bs1770gain backend.
This change adds a whitelist of backends supporting R128. When the configured
backend is in that list it will also be used for R128 calculations. Otherwise
bs1770gain is still used as a default.

This should not change the overall behaviour of the program at all, but allow
for further R128-supporting backends to be added.
2019-07-19 21:54:47 +02:00
Zsin Skri
30395911e2 util.command_output: return stderr, too
Return a namedtuple CommandOutput(stdout, stderr) instead of just stdout from
util.command_ouput, allowing separate access to stdout and stderr.

This change is required by the ffmpeg replaygain backend (GitHub
PullRequest #3056) as ffmpeg's ebur128 filter outputs only to stderr.
2019-07-14 18:32:59 +02:00
Zsin Skri
f645400c5e replaygain: adapt to mediafile commit 95e569a
Since commit 95e569a, mediafile takes care of the float -> Q7.8 conversion in
R128 GAIN tags by itself.

From `store_album_r128_gain` this conversion was already missing, remove it from
`store_track_r128_gain`, too.

fixes #3311
2019-06-18 23:17:38 +02:00
Adrian Sampson
f865fc00cd replaygain: Fix py3 crash in audiotools backend
Fixes #3305.
2019-06-08 16:23:49 -04:00
Samuel Nilsson
b8b99d9396 Merge branch 'master' into replaygain 2019-06-08 16:15:27 +02:00
Jack Wilsdon
f09088df43
replaygain: Handle invalid XML output from bs1770gain 2019-05-02 01:24:19 +01:00
Samuel Nilsson
93007bfdd5 ReplayGain: fixed error caused by per_disc option 2019-02-06 13:17:34 +01:00
Samuel Nilsson
24f02cb5cd ReplayGain refactoring 2019-02-06 10:12:06 +01:00
Samuel Nilsson
31326ebb20 Simplified album ReplayGain code 2019-02-06 10:06:48 +01:00
Samuel Nilsson
d910ed3ecf Merge branch 'master' of github.com:beetbox/beets into replaygain 2019-02-06 09:27:45 +01:00
Samuel Nilsson
3d842db8d8 Added per disc album_gain support 2019-02-06 09:27:24 +01:00
Jack Wilsdon
768770d561
Fix incorrect indentation 2019-01-31 00:15:42 +00:00
Martin Haaß
a3770686b4 to fix the peak calculation also delete the division 2018-08-20 23:39:34 +02:00
Martin Haaß
f58f03dbfd replaygain: albumpeak on large collections is calculated as average, not maximum (bug 3008) 2018-08-20 23:06:11 +02:00
Adrian Sampson
7d607b4c5d Merge pull request #2813 from autrimpo/issue2757
Use NullPaddedInt for R128 tags
2018-05-31 10:13:20 -04:00
Cédric Schieli
b9bac391a9
Really fix album replaygain calculation with gstreamer backend.
Fixes #2845
2018-03-19 21:09:35 +01:00
Michal Koutenský
8350ed6baf Unique debug messages for R128 functions 2018-02-18 20:09:58 +01:00
Adrian Sampson
b28e0b43ff Merge pull request #2778 from ylep/replaygain-options
Add --force, --write and --nowrite options to replaygain plugin
2018-01-02 14:50:27 -05:00
Yann Leprince
499cd378b7 fix the default write behaviour to the importer configuration 2018-01-02 12:11:47 +01:00
Yann Leprince
3ef4b70439 Fix coding style 2017-12-31 14:51:14 +01:00
Yann Leprince
1f6335581e Add --force, --write and --nowrite options to replaygain plugin 2017-12-31 12:00:02 +01:00
Yann Leprince
05775ccac6 Fix fragile parsing of bs1770gain output
bs1770gain is sorting the filenames internally, so in some corner cases it returns the results in a different order from the command-line arguments.

This patch uses the --xml option of bs1770gain (introduced in 0.4.6) in order to read the filenames reliably.
2017-12-31 11:27:42 +01:00
Heinz Wiesinger
bd6645d135 Fix album replaygain calculation with gstreamer backend.
Fixes #2636
2017-10-04 20:22:01 +02:00
Michal Koutenský
70a2ad354b fixes issue #2615 2017-07-04 15:53:02 +02:00
Michal Koutenský
2685f13315 replaygain: support r128 2017-05-17 21:48:01 +02:00
Adrian Sampson
998e6ac1c7 Remove unused import 2017-01-10 14:54:17 -05:00
Adrian Sampson
bc93a11141 Fix #2382: replaygain backend parsing on Python 3 2017-01-10 14:45:57 -05:00
Adrian Sampson
153b01e5a6 replaygain: Don't muck with logging level
This is now handled by the central logging infrastructure; no need to change
it here. I think this must be a leftover from the era when plugins had to
explicitly muck with their verbosity level, but even still it doesn't make
sense to do set the level to INFO unconditionally...
2017-01-10 14:24:18 -05:00
Johnny Robeson
3db656a685 use py3_path on gstreamer location prop setters
Location properties require strings, so we give them to them!
2016-09-24 01:16:56 -04:00
Johnny Robeson
7a2bdf502f s/utf8/utf-8/ in all encoding/decoding contexts
This matches up with the python documentation.
2016-09-06 23:10:24 -04:00
Johnny Robeson
6bedbd84df removebyte conversion/literals for command args
Paths are obviously untouched.

We definitely don't need these as they are entirely ascii.
2016-08-25 03:37:30 -04:00
Johnny Robeson
fb78830788 fix incorrect bytes() usages in replaygain
We encode the method and gain offset values to ascii.
2016-08-09 05:17:53 -04:00
Adrian Sampson
5e3bbf2aeb Remove remaining links to Google Code (fix #2145) 2016-07-27 13:32:41 -04:00
Johnny Robeson
c9c37a8f79 adding missing b' to command name checks in replaygain 2016-07-07 03:44:19 -04:00
Adrian Sampson
5efd5b21c5 Use new as_str method
Instead of `get(six.text_type)`, which was a surprisingly large portion of our
uses of six.
2016-06-25 19:16:14 -07:00
Johnny Robeson
e8afcbe7ec replace unicode with six.text_type 2016-06-24 05:53:49 -04:00
Johnny Robeson
31cca684f2 replace itertools.izip with zip from six.moves 2016-06-23 04:40:18 -04:00
Adrian Sampson
351b6f8c9d Remove raw Unicode literals (fix #2069)
PEP 414 didn't add `ur"..."` literals to Python 3. So for hybrid 2/3
compatibility, these had to be replaced with ordinary Unicode string literals.
This was only painful for one string; the others were only raw strings by
convention. (All were regexes.)
2016-06-21 14:29:14 -07:00
Johnny Robeson
0f4b907ff5 wrap filter()s in a list() in replaygain plugin 2016-06-14 00:28:46 -04:00
pszxzsd
8dcd50b18f make bs1770gain calculate sample peak instead of true peak 2016-06-01 20:00:08 +02:00
Johnny Robeson
e6ab231f72 Revert "Remove bytes casting for non-path command args/opts"
This reverts commit 2a6e74bc27.
2016-05-30 22:00:42 -04:00
Johnny Robeson
2a6e74bc27 Remove bytes casting for non-path command args/opts 2016-05-30 21:42:44 -04:00
Adrian Sampson
eac7d64545 Merge branch 'master' into no_unicode_literals 2016-02-28 15:21:43 -08:00
Adrian Sampson
e54c7eec3d Standardize __future__ imports without parentheses
Since the list is short enough now, we don't need parentheses for the line
wrap. This is a little less ugly.
2016-02-28 15:03:51 -08:00
Adrian Sampson
d53019f9db Further whitespace fiddling
Most commonly, this sticks with:

    log.debug(
        'some long message here'
    )

instead of placing the closing ) at the end of the string literal.
2016-02-28 14:48:10 -08:00
Peter Kessen
456565b6f2 Removed import of unicode_literals from plugins
* play
* plexpudate
* random
* replaygain
2016-02-20 14:22:45 +01:00
Adrian Sampson
314521b6ae replaygain: Fix obvious typo (fix #1873, I hope) 2016-02-07 14:28:33 -08:00
Adrian Sampson
0aea7e398b replaygain: Handle missing GStreamer data (#1855) 2016-02-02 08:08:58 -08:00
Diego Moreda
76d7c65c1b replaygain: refine test by subclassing exception
* Subclass FatalReplayGainError into FatalGstreamerPluginReplayGainError
in order to handle gstreamer plugin errors more cleanly on
test_replaygain.
2016-01-26 22:20:42 +01:00
Jack Wilsdon
12cd5306b7 Update copyright dates to 2016 2015-12-30 15:42:06 +00:00
Adrian Sampson
b25b4db9e1 replaygain: Dodge possible encoding issues
In error reporting. May avoid the error in #1774, but it's hard to find out
exactly what the Python types of these arguments are from the GStreamer
documentation.
2015-12-26 22:40:13 -08:00
Peter Kessen
3eb8008b11 added encoding as comment in files
added line like
# -*- coding: utf-8 -*-
to all files with correct license in header
2015-11-19 18:41:01 +01:00
Adrian Sampson
9f7aa866bd Use ui.should_write everywhere
There sure are a lot of plugins that want to write metadata!
2015-11-07 13:20:09 -08:00
Adrian Sampson
16ad174d29 A debug message for ReplayGain 2015-10-29 17:43:31 -04:00
Adrian Sampson
225ba282cd Fix #1592 again: wrap title_gain in handler 2015-09-08 12:07:03 -07:00
Adrian Sampson
2140bb27a3 Fix #1592: unhandled exception in PyAudioTools 2015-09-07 14:15:46 -07:00