Added support for M3U playlists\nAdded verbose output
This commit is contained in:
parent
a3a8fa97fa
commit
435ffb827a
2 changed files with 19 additions and 7 deletions
25
radiorec.py
25
radiorec.py
|
@ -47,28 +47,39 @@ def record_worker(stoprec, streamurl, target_dir, name=None):
|
||||||
elif(content_type == 'application/ogg' or content_type == 'audio/ogg'):
|
elif(content_type == 'application/ogg' or content_type == 'audio/ogg'):
|
||||||
filename += '.ogg'
|
filename += '.ogg'
|
||||||
elif(content_type == 'audio/x-mpegurl'):
|
elif(content_type == 'audio/x-mpegurl'):
|
||||||
#TODO Add support for M3U playlists
|
|
||||||
print('Sorry, M3U playlists are currently not supported')
|
print('Sorry, M3U playlists are currently not supported')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
else:
|
else:
|
||||||
print('Unknown content type "' + content_type + '". Assuming mp3.')
|
print('Unknown content type "' + content_type + '". Assuming mp3.')
|
||||||
filename += 'mp3'
|
filename += 'mp3'
|
||||||
target = open(filename, "wb")
|
with open(filename, "wb") as target:
|
||||||
while(not stoprec.is_set() and not conn.closed):
|
while(not stoprec.is_set() and not conn.closed):
|
||||||
target.write(conn.read(1024))
|
target.write(conn.read(1024))
|
||||||
|
|
||||||
def record(args):
|
def record(args):
|
||||||
settings = read_settings()
|
settings = read_settings()
|
||||||
streamurl = ''
|
streamurl = ''
|
||||||
|
global verboseprint
|
||||||
|
verboseprint = print if args.verbose else lambda *a, **k: None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
streamurl = settings['STATIONS'][args.station]
|
streamurl = settings['STATIONS'][args.station]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print('Unkown station name: ' + args.station)
|
print('Unkown station name: ' + args.station)
|
||||||
return
|
sys.exit()
|
||||||
|
if streamurl.endswith('.m3u'):
|
||||||
|
verboseprint('Seems to be an M3U playlist. Trying to parse…')
|
||||||
|
with urllib.request.urlopen(streamurl) as remotefile:
|
||||||
|
for line in remotefile:
|
||||||
|
if not line.decode('utf-8').startswith('#'):
|
||||||
|
tmpstr = line.decode('utf-8')
|
||||||
|
break
|
||||||
|
streamurl = tmpstr
|
||||||
|
verboseprint('stream url: ' + streamurl)
|
||||||
target_dir = os.path.expandvars(settings['GLOBAL']['target_dir'])
|
target_dir = os.path.expandvars(settings['GLOBAL']['target_dir'])
|
||||||
stoprec = threading.Event()
|
stoprec = threading.Event()
|
||||||
|
|
||||||
print('Recording ' + args.station + '…')
|
verboseprint('Recording ' + args.station + '…')
|
||||||
recthread = threading.Thread(target = record_worker,
|
recthread = threading.Thread(target = record_worker,
|
||||||
args = (stoprec, streamurl, target_dir, args.name), daemon = True)
|
args = (stoprec, streamurl, target_dir, args.name), daemon = True)
|
||||||
recthread.start()
|
recthread.start()
|
||||||
|
@ -79,7 +90,6 @@ def record(args):
|
||||||
|
|
||||||
def list(args):
|
def list(args):
|
||||||
settings = read_settings()
|
settings = read_settings()
|
||||||
print('Known stations:')
|
|
||||||
for key in settings['STATIONS']:
|
for key in settings['STATIONS']:
|
||||||
print(key)
|
print(key)
|
||||||
|
|
||||||
|
@ -93,6 +103,7 @@ def main():
|
||||||
help='Recording time in minutes')
|
help='Recording time in minutes')
|
||||||
parser_record.add_argument('name', nargs='?', type=str,
|
parser_record.add_argument('name', nargs='?', type=str,
|
||||||
help='A name for the recording')
|
help='A name for the recording')
|
||||||
|
parser_record.add_argument('-v', '--verbose', action='store_true', help="Verbose output")
|
||||||
parser_record.set_defaults(func=record)
|
parser_record.set_defaults(func=record)
|
||||||
parser_list = subparsers.add_parser('list', help='List all known stations')
|
parser_list = subparsers.add_parser('list', help='List all known stations')
|
||||||
parser_list.set_defaults(func=list)
|
parser_list.set_defaults(func=list)
|
||||||
|
|
|
@ -6,5 +6,6 @@ dlf = http://dradio_mp3_dlf_m.akacast.akamaistream.net/7/249/142684/v1/gnl.akaca
|
||||||
dkultur = http://dradio_mp3_dkultur_m.akacast.akamaistream.net/7/530/142684/v1/gnl.akacast.akamaistream.net/dradio_mp3_dkultur_m
|
dkultur = http://dradio_mp3_dkultur_m.akacast.akamaistream.net/7/530/142684/v1/gnl.akacast.akamaistream.net/dradio_mp3_dkultur_m
|
||||||
dwissen = http://dradio_mp3_dwissen_m.akacast.akamaistream.net/7/728/142684/v1/gnl.akacast.akamaistream.net/dradio_mp3_dwissen_m
|
dwissen = http://dradio_mp3_dwissen_m.akacast.akamaistream.net/7/728/142684/v1/gnl.akacast.akamaistream.net/dradio_mp3_dwissen_m
|
||||||
swr2 = http://swr-mp3-m-swr2.akacast.akamaistream.net/7/721/137135/v1/gnl.akacast.akamaistream.net/swr-mp3-m-swr2
|
swr2 = http://swr-mp3-m-swr2.akacast.akamaistream.net/7/721/137135/v1/gnl.akacast.akamaistream.net/swr-mp3-m-swr2
|
||||||
|
swr2_m3u = http://mp3-live.swr.de/swr2_m.m3u
|
||||||
brklassik = http://gffstream.ic.llnwd.net/stream/gffstream_w13a
|
brklassik = http://gffstream.ic.llnwd.net/stream/gffstream_w13a
|
||||||
mdrklassik = http://c22033-l.i.core.cdn.streamfarm.net/22008mdrklassik/live/3087mdrklassik/live_de_128.mp3[brodbemn@pcvs90
|
mdrklassik = http://c22033-l.i.core.cdn.streamfarm.net/22008mdrklassik/live/3087mdrklassik/live_de_128.mp3[brodbemn@pcvs90
|
||||||
|
|
Loading…
Reference in a new issue