1313import optparse
1414import email
1515import subprocess
16+ import hashlib
1617from future .builtins import bytes
1718
1819import yaml
@@ -138,12 +139,12 @@ def play_playlist(self, payload):
138139
139140 url = stream ['streamUrl' ]
140141 if stream ['streamUrl' ].startswith ("cid:" ):
141- url = "file://" + tmp_path + stream ['streamUrl' ].lstrip ("cid:" ) + ".mp3"
142+ url = "file://" + tmp_path + hashlib . md5 ( stream ['streamUrl' ].replace ("cid:" , "" , 1 ). encode ()). hexdigest ( ) + ".mp3"
142143
143144 if (url .find ('radiotime.com' ) != - 1 ):
144145 url = self .tunein_playlist (url )
145146
146- self .pHandler .queued_play (mrl_fix ( url ) , stream ['offsetInMilliseconds' ], audio_type = 'media' , stream_id = streamId )
147+ self .pHandler .queued_play (url , stream ['offsetInMilliseconds' ], audio_type = 'media' , stream_id = streamId )
147148
148149 def play_speech (self , mrl ):
149150 self .stop ()
@@ -210,15 +211,6 @@ def playback_callback(requestType, playerActivity, streamId):
210211MIN_VOLUME = 30
211212
212213
213- def mrl_fix (url ):
214- if ('#' in url ) and url .startswith ('file://' ):
215- new_url = url .replace ('#' , '.hashMark.' )
216- os .rename (url .replace ('file://' , '' ), new_url .replace ('file://' , '' ))
217- url = new_url
218-
219- return url
220-
221-
222214def internet_on ():
223215 try :
224216 requests .get ('https://api.amazon.com/auth/o2/token' )
@@ -438,7 +430,7 @@ def process_response(response):
438430 j = json .loads (payload .get_payload ())
439431 logger .debug ("JSON String Returned: %s" , json .dumps (j , indent = 2 ))
440432 elif payload .get_content_type () == "audio/mpeg" :
441- filename = tmp_path + payload .get ('Content-ID' ).strip ("<>" ) + ".mp3"
433+ filename = tmp_path + hashlib . md5 ( payload .get ('Content-ID' ).strip ("<>" ). encode ()). hexdigest ( ) + ".mp3"
442434 with open (filename , 'wb' ) as f :
443435 f .write (payload .get_payload (decode = True ))
444436 else :
@@ -452,7 +444,7 @@ def process_response(response):
452444 for directive in j ['messageBody' ]['directives' ]:
453445 if directive ['namespace' ] == 'SpeechSynthesizer' :
454446 if directive ['name' ] == 'speak' :
455- player .play_speech (mrl_fix ( "file://" + tmp_path + directive ['payload' ]['audioContent' ].lstrip ("cid:" ) + ".mp3" ) )
447+ player .play_speech ("file://" + tmp_path + hashlib . md5 ( directive ['payload' ]['audioContent' ].replace ("cid:" , "" , 1 ). encode ()). hexdigest () + ".mp3" )
456448
457449 elif directive ['namespace' ] == 'SpeechRecognizer' :
458450 if directive ['name' ] == 'listen' :
0 commit comments