python code for internet radio stream

Solutions on MaxInterview for python code for internet radio stream by the best coders in the world

showing results for - "python code for internet radio stream"
Louisa
10 Apr 2019
1import requests
2import time
3import datetime
4print(datetime.datetime.now())
5import re
6
7
8url = 'http://prem1.rockradio.com:80/bluesrock?9555ae7caa92404c73cade1d'
9encoding = 'latin1'
10info = ''
11
12radio_session = requests.Session()
13
14while True:
15
16    radio = radio_session.get(url, headers={'Icy-MetaData': '1'}, stream=True)
17
18    metaint = int(radio.headers['icy-metaint'])
19
20    stream = radio.raw
21
22    audio_data = stream.read(metaint)
23    meta_byte = stream.read(1)
24
25    if (meta_byte):
26        meta_length = ord(meta_byte) * 16
27
28        meta_data = stream.read(meta_length).rstrip(b'\0')
29
30        stream_title = re.search(br"StreamTitle='([^']*)';", meta_data)
31
32
33        if stream_title:
34
35            stream_title = stream_title.group(1).decode(encoding, errors='replace')
36
37            if info != stream_title:
38                print('Now playing: ', stream_title)
39                info = stream_title
40            else:
41                pass
42
43        else:
44            print('No StreamTitle!')
45
46    time.sleep(1)
47
Lina
16 Sep 2016
1import vlc
2import time
3
4url = 'http://prem1.rockradio.com:80/bluesrock?9555ae7caa92404c73cade1d'
5
6#define VLC instance
7instance = vlc.Instance('--input-repeat=-1', '--fullscreen')
8
9#Define VLC player
10player=instance.media_player_new()
11
12#Define VLC media
13media=instance.media_new(url)
14
15#Set player media
16player.set_media(media)
17
18#Play the media
19player.play()
20
Magdalena
08 Oct 2020
1>>> play.pause()  #pause play back
2>>> player.play() #resume play back
3>>> player.stop() #stop play back
4