#33: Memmoize new audio detection logic for performance, follow HTTP redirects when determining filetype.

This commit is contained in:
Bill Dengler 2015-05-12 14:13:43 -04:00
parent 52bfa82ec5
commit 6fdc5c67e2

View File

@ -43,14 +43,22 @@ def find_next_reply(id, listItem):
return None return None
def is_audio(tweet): def is_audio(tweet):
if 'is_audio' in tweet:
return tweet['is_audio']
if len(tweet["entities"]["hashtags"]) > 0: if len(tweet["entities"]["hashtags"]) > 0:
for i in tweet["entities"]["hashtags"]: for i in tweet["entities"]["hashtags"]:
if i["text"] == "audio": if i["text"] == "audio":
tweet['is_audio']=True
return True return True
for u in find_urls(tweet): for u in find_urls(tweet):
response = requests.head(u) try:
if 'audio' in str(response.headers['content-type']).lower(): response = requests.head(u,allow_redirects=True)
return True if 'audio' in str(response.headers['content-type']).lower():
tweet['is_audio']=True
return True
except:
log.exception("Exception while determining audio by HTTP headers")
tweet['is_audio']=False
return False return False
def is_geocoded(tweet): def is_geocoded(tweet):