mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-02-16 22:44:09 -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)
|
tweet['is_audio']=True
|
||||||
if 'audio' in str(response.headers['content-type']).lower():
|
return True
|
||||||
tweet['is_audio']=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
|
||||||
|
|
||||||
@ -123,4 +119,13 @@ def is_allowed(tweet, clients):
|
|||||||
if i.lower() == source.lower():
|
if i.lower() == source.lower():
|
||||||
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…
x
Reference in New Issue
Block a user