mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
#33: Memmoize new audio detection logic for performance, follow HTTP redirects when determining filetype.
This commit is contained in:
parent
52bfa82ec5
commit
6fdc5c67e2
@ -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:
|
||||||
|
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():
|
||||||
|
tweet['is_audio']=True
|
||||||
return 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):
|
||||||
|
Loading…
Reference in New Issue
Block a user