mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
#34: just playing around a bit. Really broken right now.
This commit is contained in:
parent
ea7f5bacf9
commit
1d344275bb
@ -437,14 +437,23 @@ class baseBufferController(bufferController):
|
|||||||
def interact(self):
|
def interact(self):
|
||||||
"Select the best action for the currently focused tweet (audio, geocode, URL, etc)."
|
"Select the best action for the currently focused tweet (audio, geocode, URL, etc)."
|
||||||
tweet = self.get_tweet()
|
tweet = self.get_tweet()
|
||||||
|
url=None
|
||||||
urls = utils.find_urls(tweet)
|
urls = utils.find_urls(tweet)
|
||||||
#handle audio tweets.
|
if len(urls) == 1:
|
||||||
if utils.is_audio(tweet):
|
url=urls[0]
|
||||||
return self.audio()
|
elif len(urls) > 1:
|
||||||
|
urls_list = dialogs.urlList.urlList()
|
||||||
|
urls_list.populate_list(urls)
|
||||||
|
if urls_list.get_response() == widgetUtils.OK:
|
||||||
|
url=urls_list.get_string()
|
||||||
|
if hasattr(urls_list, "destroy"): urls_list.destroy()
|
||||||
|
if url != None:
|
||||||
|
if sound.URLPlayer.is_playable(url=url,play=True) == False:
|
||||||
|
return self.url(url)
|
||||||
elif utils.is_geocoded(tweet):
|
elif utils.is_geocoded(tweet):
|
||||||
output.speak("Not implemented",True)
|
return output.speak("Not implemented",True)
|
||||||
else:
|
else:
|
||||||
return self.url()
|
output.speak("Not actionable.",True)
|
||||||
|
|
||||||
def url(self,url=''):
|
def url(self,url=''):
|
||||||
if url == '':
|
if url == '':
|
||||||
|
20
src/sound.py
20
src/sound.py
@ -13,6 +13,7 @@ import output
|
|||||||
system = platform.system()
|
system = platform.system()
|
||||||
from mysc.repeating_timer import RepeatingTimer
|
from mysc.repeating_timer import RepeatingTimer
|
||||||
import application
|
import application
|
||||||
|
import time
|
||||||
URLPlayer = None
|
URLPlayer = None
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
@ -114,7 +115,7 @@ class URLStream(object):
|
|||||||
log.debug("Transformed URL: %s. Prepared" % (self.url,))
|
log.debug("Transformed URL: %s. Prepared" % (self.url,))
|
||||||
self.prepared = True
|
self.prepared = True
|
||||||
|
|
||||||
def play(self, url, volume=1.0):
|
def play(self, url=None, volume=1.0, stream=None):
|
||||||
if hasattr(self, "stream") and self.stream.is_playing:
|
if hasattr(self, "stream") and self.stream.is_playing:
|
||||||
output.speak(_(u"Stopped"))
|
output.speak(_(u"Stopped"))
|
||||||
self.stream.stop()
|
self.stream.stop()
|
||||||
@ -123,21 +124,34 @@ class URLStream(object):
|
|||||||
else:
|
else:
|
||||||
output.speak(_(u"Playing..."))
|
output.speak(_(u"Playing..."))
|
||||||
log.debug("Attempting to play an URL...")
|
log.debug("Attempting to play an URL...")
|
||||||
|
if url != None:
|
||||||
self.prepare(url)
|
self.prepare(url)
|
||||||
|
elif stream != None:
|
||||||
|
self.stream=stream
|
||||||
if self.prepared == True:
|
if self.prepared == True:
|
||||||
self.stream = sound_lib.stream.URLStream(url=self.url)
|
self.stream = sound_lib.stream.URLStream(url=self.url)
|
||||||
|
if hasattr(self,'stream'):
|
||||||
self.stream.volume = float(volume)
|
self.stream.volume = float(volume)
|
||||||
self.stream.play()
|
self.stream.play()
|
||||||
log.debug("played")
|
log.debug("played")
|
||||||
|
|
||||||
def is_playable(self, url):
|
def is_playable(self, url,play=False,volume=1.0):
|
||||||
|
print "Playability test invoked."
|
||||||
|
start=time.time()
|
||||||
try:
|
try:
|
||||||
log.debug("Checking URL playability...")
|
log.debug("Checking URL playability...")
|
||||||
self.prepare(url)
|
self.prepare(url)
|
||||||
if self.prepared == True:
|
if self.prepared == True:
|
||||||
self.stream = sound_lib.stream.URLStream(url=self.url)
|
stream=sound_lib.stream.URLStream(url=self.url)
|
||||||
|
end=time.time()
|
||||||
|
print "is_playable algo took",end-start,"seconds."
|
||||||
|
if play:
|
||||||
|
return self.play(stream=stream,volume=volume)
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
|
log.exception("Exception.")
|
||||||
|
end=time.time()
|
||||||
|
print "is_playable algo took",end-start,"seconds."
|
||||||
return False
|
return False
|
||||||
def stop_audio(self):
|
def stop_audio(self):
|
||||||
if hasattr(self, "stream") and self.stream.is_playing == True:
|
if hasattr(self, "stream") and self.stream.is_playing == True:
|
||||||
|
@ -5,6 +5,8 @@ from twython import TwythonError
|
|||||||
import config
|
import config
|
||||||
import logging
|
import logging
|
||||||
import requests
|
import requests
|
||||||
|
import time
|
||||||
|
import sound
|
||||||
log = logging.getLogger("twitter.utils")
|
log = logging.getLogger("twitter.utils")
|
||||||
""" Some utilities for the twitter interface."""
|
""" Some utilities for the twitter interface."""
|
||||||
|
|
||||||
@ -43,6 +45,7 @@ def find_next_reply(id, listItem):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def is_audio(tweet,force=False):
|
def is_audio(tweet,force=False):
|
||||||
|
start=time.time()
|
||||||
if force == False and 'is_audio' in tweet:
|
if force == False and 'is_audio' in tweet:
|
||||||
return tweet['is_audio']
|
return tweet['is_audio']
|
||||||
try:
|
try:
|
||||||
@ -61,10 +64,14 @@ def is_audio(tweet,force=False):
|
|||||||
if config.app["app-settings"]["use_modern_audio_algo"]:
|
if config.app["app-settings"]["use_modern_audio_algo"]:
|
||||||
for u in find_urls(tweet):
|
for u in find_urls(tweet):
|
||||||
if url_is_audio(u):
|
if url_is_audio(u):
|
||||||
|
end=time.time()
|
||||||
|
print "Codeofdusk algo took",end-start,"seconds."
|
||||||
tweet['is_audio']=True
|
tweet['is_audio']=True
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
log.exception("Exception while executing is_audio Codeofdusk algorithm.")
|
log.exception("Exception while executing is_audio Codeofdusk algorithm.")
|
||||||
|
end=time.time()
|
||||||
|
print "Codeofdusk algo took",end-start,"seconds."
|
||||||
tweet['is_audio']=False
|
tweet['is_audio']=False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -131,7 +138,11 @@ def is_allowed(tweet, clients):
|
|||||||
allowed = False
|
allowed = False
|
||||||
log.exception("Tuit not allowed: %s" % (tweet["text"],))
|
log.exception("Tuit not allowed: %s" % (tweet["text"],))
|
||||||
return allowed
|
return allowed
|
||||||
|
|
||||||
def url_is_audio(u):
|
def url_is_audio(u):
|
||||||
|
sound.URLPlayer.is_playable(u)
|
||||||
|
|
||||||
|
def old_url_is_audio(u):
|
||||||
try:
|
try:
|
||||||
response = requests.head(u,allow_redirects=True)
|
response = requests.head(u,allow_redirects=True)
|
||||||
if 'audio' in str(response.headers['content-type']).lower():
|
if 'audio' in str(response.headers['content-type']).lower():
|
||||||
|
Loading…
Reference in New Issue
Block a user