Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ python3 spotrec.py

### Example

First of all run spotify.
First of all run spotify. To circumvent incompatibilities occuring on some distros, install it via snap:

```bash
snap install spotify
```

Then you can run the python script which will record the music:

```
./spotrec.py -o ./my_song_dir --skip-intro
```
By default spotrec will output `*.flac` files. If you want to change the file type to `*.mp3` use the `--audio-codec` flag:

```bash
./spotrec.py -o ./my_song_dir --skip-intro --audio-codec mp3
```

Check the pulseaudio configuration:

Expand Down
12 changes: 9 additions & 3 deletions spotrec.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
_tmp_file = True
_underscored_filenames = False
_use_internal_track_counter = False
_audio_codec = "flac"

# Hard-coded settings
_pa_recording_sink_name = "spotrec"
Expand Down Expand Up @@ -126,6 +127,7 @@ def handle_command_line():
global _tmp_file
global _underscored_filenames
global _use_internal_track_counter
global _audio_codec

parser = argparse.ArgumentParser(
description=app_name + " v" + app_version, formatter_class=argparse.RawTextHelpFormatter)
Expand All @@ -137,6 +139,9 @@ def handle_command_line():
action="store_true", default=_mute_pa_recording_sink)
parser.add_argument("-o", "--output-directory", help="Where to save the recordings\n"
"Default: " + _output_directory, default=_output_directory)
parser.add_argument("-ac", "--audio-codec", help="Set the audio codec of the recorded files\n"
"Available: flac, mp3"
"Default: flac", default=_audio_codec)
parser.add_argument("-p", "--filename-pattern", help="A pattern for the file names of the recordings\n"
"Available: {artist}, {album}, {trackNumber}, {title}\n"
"Default: \"" + _filename_pattern + "\"\n"
Expand Down Expand Up @@ -167,6 +172,7 @@ def handle_command_line():

_use_internal_track_counter = args.internal_track_counter

_audio_codec = args.audio_codec

def init_log():
global log
Expand Down Expand Up @@ -445,9 +451,9 @@ def record(self, out_dir: str, file: str, metadata_for_file={}):
# Use a dot as filename prefix to hide the file until the recording was successful
self.tmp_file_prefix = "."
self.filename = self.tmp_file_prefix + \
os.path.basename(file) + ".flac"
os.path.basename(file) + "." + _audio_codec
else:
self.filename = os.path.basename(file) + ".flac"
self.filename = os.path.basename(file) + "." +_audio_codec

# build metadata param
metadata_params = ''
Expand All @@ -458,7 +464,7 @@ def record(self, out_dir: str, file: str, metadata_for_file={}):
# "-hide_banner": short the debug log a little
# "-y": overwrite existing files
self.process = Shell.Popen(_ffmpeg_executable + ' -hide_banner -y -f pulse -ac 2 -ar 44100 -i ' +
self.pulse_input + metadata_params + ' -acodec flac ' +
self.pulse_input + metadata_params + ' -acodec ' + _audio_codec+ ' ' +
shlex.quote(os.path.join(self.out_dir, self.filename)))

self.pid = str(self.process.pid)
Expand Down