Skip to content

Commit

Permalink
support converting TuneIn stream URL
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongyihui committed Dec 26, 2017
1 parent 437f906 commit f36ca02
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions avs/interface/audio_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
import uuid
import base64
import hashlib
import requests
import logging

from avs.player import Player

logger = logging.getLogger('AudioPlayer')


class AudioPlayer(object):
STATES = {'IDLE', 'PLAYING', 'STOPPED', 'PAUSED', 'BUFFER_UNDERRUN', 'FINISHED'}
Expand Down Expand Up @@ -65,6 +69,18 @@ def Play(self, directive):
self.player.play('file://{}'.format(mp3_file))
self.PlaybackStarted()
else:
if audio_url.find('radiotime.com') >= 0:
logger.debug('parse TuneIn audio stream: {}'.format(audio_url))

try:
response = requests.get(audio_url)
lines = response.content.decode().split('\n')
logger.debug(lines)
if lines and lines[0]:
audio_url = lines[0]
except Exception:
pass

# os.system('mpv {}'.format(audio_url))
self.player.play(audio_url)
self.PlaybackStarted()
Expand Down

0 comments on commit f36ca02

Please sign in to comment.