Is it possible to get mpv to dump a stream to separate files based on the current icy-title value when using --stream-record with an icecast stream?
man mpv only mentions using a fixed file name with --record-file, --stream-record --dump-cache.
If this is not possible directly with mpv what might be a possible approach to save separate files for each song in an icecast playlist rather than one huge continuous file as --stream-record=mystream.mp3 does?
While a solution is probably possible with a custom mpv lua script extension, apparently downloading to custom file names is not supported ootb.
A dedicated utility that can parse icecast titles and dump the streams to separate files is 🔗streamripper. It can be installed with apt install streamripper on debian linuces or brew install streamripper on mac.
The following command will create separate files named after stream titles:
streamripper http://some-icast-server.com/stream -r 8888
The -r flag will create a relay server on port 8888. You can listen to the relayed stream while it's been downloading with:
mpv http://localhost:8888
I am currently writing a python script that can do exactly that.
I will in a few days give you the repo address to check it out, it is an internet radio client, that can also record the selected stream.
Here is a very very reducted version, that shows the principle of the whole procedure:
import mpv
import time
def title0(player):
tit1 = player.metadata.get('icy-title')
tit2 = player.metadata.get('title')
tit3 = player.metadata.get('TITLE')
tit4 = player.metadata.get('artist')
tit5 = player.metadata.get('ARTIST')
if tit1 == None:
tit1 = ""
if tit2 == None:
tit2 = ""
if tit3 == None:
tit3 = ""
if tit4 == None:
tit4 = ""
if tit5 == None:
tit5 = ""
if tit4 == "" and tit5 == "":
pavla = ""
else:
pavla = " - "
tit0 = tit1+tit2+tit3+pavla+tit4+tit5
if tit0 == '':
tit0 = "Not Available"
return tit0
player = mpv.MPV()
player.play('https://laterna.kafeneio.social/public/kafeneio')
player.wait_for_playback()
tit0 = "Not Available"
while tit0 == "Not Available":
try:
fil_format = player.file_format
tit0 = title0(player).replace("-", " ")
fil_nam = tit0+'.'+fil_format
except:
time.sleep(1)
player.stream_record = fil_nam
time.sleep(30)
This script will save a file with the correct format and the 'icy-title' name in the same directory as your py script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With