Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SpotifyBackup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Robert Goldmann
SpotifyBackup
Commits
c2883a4d
Commit
c2883a4d
authored
1 year ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
added new class to convert wav to mp3, maximize volume and set mp3 tags
parent
8ce97024
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Mp3Converter.py
+68
-0
68 additions, 0 deletions
Mp3Converter.py
poetry.lock
+12
-1
12 additions, 1 deletion
poetry.lock
pyproject.toml
+1
-0
1 addition, 0 deletions
pyproject.toml
with
81 additions
and
1 deletion
Mp3Converter.py
0 → 100644
+
68
−
0
View file @
c2883a4d
import
re
import
subprocess
from
TheCodeLabs_BaseUtils.DefaultLogger
import
DefaultLogger
from
mutagen.easyid3
import
EasyID3
LOG_FORMAT
=
'
[%(levelname)-7s] - %(asctime)s - %(message)s
'
LOGGER
=
DefaultLogger
().
create_logger_if_not_exists
(
'
Mp3Converter
'
,
logFormat
=
LOG_FORMAT
)
class
Mp3Converter
:
_PATTERN_MAX_VOLUME
=
re
.
compile
(
r
'
max_volume: ([-.\d+]*)\s
'
)
@staticmethod
def
convert_to_mp3
(
inputFilePath
:
str
,
outputFilePath
:
str
)
->
None
:
output
=
subprocess
.
check_output
([
'
ffmpeg
'
,
'
-i
'
,
inputFilePath
,
'
-af
'
,
'
volumedetect
'
,
'
-vn
'
,
# ignore video streams
'
-sn
'
,
# ignore subtitle streams
'
-sn
'
,
# ignore data streams
'
-hide_banner
'
,
# suppress unnecessary log messages
'
-f
'
,
'
null
'
,
'
NULL
'
],
stderr
=
subprocess
.
STDOUT
)
output
=
output
.
decode
(
'
utf-8
'
)
matches
=
re
.
findall
(
Mp3Converter
.
_PATTERN_MAX_VOLUME
,
output
)
detectedMaxVolume
=
None
if
matches
:
detectedMaxVolume
=
float
(
matches
[
0
])
LOGGER
.
debug
(
f
'
\t\t
Detected max volume:
{
detectedMaxVolume
}
dB
'
)
arguments
=
[
'
ffmpeg
'
,
'
-i
'
,
inputFilePath
,
'
-y
'
,
# overwrite if already exists
'
-hide_banner
'
,
# suppress unnecessary log messages
'
-loglevel
'
,
'
error
'
,
'
-vn
'
,
# ignore video streams
'
-sn
'
,
# ignore subtitle streams
'
-sn
'
,
# ignore data streams
'
-ac
'
,
'
2
'
,
# 2 channels
'
-b:a
'
,
'
320k
'
]
# 320k bitrate
if
detectedMaxVolume
is
not
None
and
detectedMaxVolume
<
0
:
arguments
.
extend
([
'
-filter:a
'
,
f
'
volume=
{
abs
(
detectedMaxVolume
)
}
dB
'
])
# normalizes volume
arguments
.
append
(
outputFilePath
)
LOGGER
.
info
(
f
'
\t\t
Running
{
"
"
.
join
(
arguments
)
}
'
)
subprocess
.
check_call
(
arguments
)
@staticmethod
def
set_mp3_tags
(
filePath
:
str
,
title
:
str
,
artist
:
str
,
album
:
str
)
->
None
:
LOGGER
.
info
(
f
'
\t\t
Setting mp3 tags for
"
{
filePath
}
"'
)
audio
=
EasyID3
(
filePath
)
audio
[
'
title
'
]
=
title
audio
[
'
artist
'
]
=
artist
audio
[
'
album
'
]
=
album
audio
.
save
()
if
__name__
==
'
__main__
'
:
Mp3Converter
.
convert_to_mp3
(
'
C:/Programmierung/SpotifyBackup/recorder/1 - Bignic - tetrapod.wav
'
,
'
C:/Programmierung/SpotifyBackup/recorder/a.mp3
'
)
Mp3Converter
.
set_mp3_tags
(
'
C:/Programmierung/SpotifyBackup/recorder/a.mp3
'
,
title
=
'
Fancy Song
'
,
artist
=
'
Various Artists
'
,
album
=
'
Album #1
'
)
This diff is collapsed.
Click to expand it.
poetry.lock
+
12
−
1
View file @
c2883a4d
...
@@ -132,6 +132,17 @@ files = [
...
@@ -132,6 +132,17 @@ files = [
{file
=
"idna-3.6.tar.gz"
,
hash
=
"sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"
}
,
{file
=
"idna-3.6.tar.gz"
,
hash
=
"sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"
}
,
]
]
[[package]]
name
=
"mutagen"
version
=
"1.47.0"
description
=
"read and write audio tags for many formats"
optional
=
false
python-versions
=
">
=
3.7
"
files
=
[
{file
=
"mutagen-1.47.0-py3-none-any.whl"
,
hash
=
"sha256:edd96f50c5907a9539d8e5bba7245f62c9f520aef333d13392a79a4f70aca719"
}
,
{file
=
"mutagen-1.47.0.tar.gz"
,
hash
=
"sha256:719fadef0a978c31b4cf3c956261b3c58b6948b32023078a2117b1de09f0fc99"
}
,
]
[[package]]
[[package]]
name
=
"psutil"
name
=
"psutil"
version
=
"5.9.7"
version
=
"5.9.7"
...
@@ -341,4 +352,4 @@ zstd = ["zstandard (>=0.18.0)"]
...
@@ -341,4 +352,4 @@ zstd = ["zstandard (>=0.18.0)"]
[
metadata
]
[
metadata
]
lock-version
=
"2.0"
lock-version
=
"2.0"
python-versions
=
"^3.11"
python-versions
=
"^3.11"
content-hash
=
"
a10c10003642c988271028a8a2a44227cae6123d1e05e4a66f3cb2dbab5a655a
"
content-hash
=
"
bb77de02b25207bf10249bf1370a69682b27ad88452311d42abc7d9830eb5494
"
This diff is collapsed.
Click to expand it.
pyproject.toml
+
1
−
0
View file @
c2883a4d
...
@@ -14,6 +14,7 @@ python = "^3.11"
...
@@ -14,6 +14,7 @@ python = "^3.11"
thecodelabs-baseutils
=
{
version
=
"*"
,
source
=
"TheCodeLabs"
}
thecodelabs-baseutils
=
{
version
=
"*"
,
source
=
"TheCodeLabs"
}
spotipy
=
"2.22.0"
spotipy
=
"2.22.0"
PyAudioWPatch
=
"0.2.12.6"
PyAudioWPatch
=
"0.2.12.6"
mutagen
=
"1.47.0"
[tool.poetry.dev-dependencies]
[tool.poetry.dev-dependencies]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment