Created
April 21, 2019 20:56
-
-
Save bazooka07/c9f3ae91121aad690f476128b00a52b3 to your computer and use it in GitHub Desktop.
Play your .pls or .m3u file with Ka-Radio32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
''' | |
Listen on Ka-Radio your .pls or .m3u file from : | |
- your computer | |
- https://laradiofm.com (choose pls format for streaming) | |
- https://directory.shoutcast.com/ (choose downloading) | |
- https://www.internet-radio.com | |
- https://dirble.com | |
- https://www.musicgoal.com/ | |
With Linux, save this file in /usr/local/bin folder with ka_radio.py as filename | |
chmod a+x /usr/local/bin/ka_radio.py | |
Open the file manager | |
select one file with .pls ou .m3u extension | |
right-click with the mouse on the filename | |
select the property tab for this file and choose /usr/local/bin/ka_radio.py for opening this file | |
Just adjust IP address of kA_RADIO as belows : | |
''' | |
from telnetlib import Telnet | |
import re | |
KA_RADIO = '192.168.30.77' | |
PROMPT = b'Karadio telnet\n>' | |
PATTERN1 = u'^File\d+=https?:\/\/([^/:]+)(?::(\d+))?(.*)$' | |
PATTERN2 = u'^https?:\/\/([^/:]+)(?::(\d+))?(.*)$' | |
def main(args): | |
if(len(args) > 1): | |
print('File: %s' % args[1]) | |
if args[1][-3:].lower() == 'pls': | |
buf = '' | |
with open(args[1]) as f: | |
buf = f.read() | |
matches = re.search(PATTERN1, buf, re.MULTILINE) | |
elif args[1][-3:].lower() == 'm3u': | |
buf = '' | |
with open(args[1]) as f: | |
buf = f.read() | |
matches = re.search(PATTERN2, buf, re.MULTILINE) | |
else: | |
return | |
if matches: | |
url, port, path = matches.groups() | |
if port == None: | |
port = '80' | |
if path == None: | |
path = '/' | |
cnx = Telnet(KA_RADIO) | |
try: | |
resp = cnx.read_until(b'\n', 5) | |
cnx.write(('cli.url("%s")\n' % url).encode('ascii')) | |
resp = cnx.read_until((b'##CLI.URLSET#: ')) | |
print(cnx.read_until(b'\n').decode('ascii').strip()) | |
cnx.write(('cli.port("%s")\n' % port).encode('ascii')) | |
resp = cnx.read_until((b'##CLI.PORTSET#: ')) | |
print(cnx.read_until(b'\n').decode('ascii').strip()) | |
cnx.write(('cli.path("%s")\n' % path).encode('ascii')) | |
resp = cnx.read_until((b'##CLI.PATHSET#: ')) | |
print(cnx.read_until(b'\n').decode('ascii').strip()) | |
cnx.write(b'cli.instant\n') | |
resp = cnx.read_until(b'\n', 5) | |
finally: | |
cnx.close() | |
else: | |
print('No match') | |
print(buf) | |
return 0 | |
if __name__ == '__main__': | |
import sys | |
sys.exit(main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment