mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-23 03:38:08 -06:00
#33: Generalize.
This commit is contained in:
parent
6fdc5c67e2
commit
68499ca9e5
@ -51,13 +51,9 @@ def is_audio(tweet):
|
|||||||
tweet['is_audio']=True
|
tweet['is_audio']=True
|
||||||
return True
|
return True
|
||||||
for u in find_urls(tweet):
|
for u in find_urls(tweet):
|
||||||
try:
|
if url_is_audio(u):
|
||||||
response = requests.head(u,allow_redirects=True)
|
|
||||||
if 'audio' in str(response.headers['content-type']).lower():
|
|
||||||
tweet['is_audio']=True
|
tweet['is_audio']=True
|
||||||
return True
|
return True
|
||||||
except:
|
|
||||||
log.exception("Exception while determining audio by HTTP headers")
|
|
||||||
tweet['is_audio']=False
|
tweet['is_audio']=False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -124,3 +120,12 @@ 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):
|
||||||
|
try:
|
||||||
|
response = requests.head(u,allow_redirects=True)
|
||||||
|
if 'audio' in str(response.headers['content-type']).lower():
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
except:
|
||||||
|
log.exception("Exception while determining audio by HTTP headers")
|
||||||
|
Loading…
Reference in New Issue
Block a user