handle feeds with enclosures (featured media / podcasts) #35
@ -194,13 +194,17 @@ def grab_media(post_directory, url, prefered_name=None):
|
|||||||
"""
|
"""
|
||||||
media_item = urlparse(url).path.split('/')[-1]
|
media_item = urlparse(url).path.split('/')[-1]
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'User-Agent': 'https://git.autonomic.zone/ruangrupa/lumbunglib',
|
||||||
|
'From': 'info@lumbung.space' # This is another valid field
|
||||||
|
}
|
||||||
if prefered_name:
|
if prefered_name:
|
||||||
media_item = prefered_name
|
media_item = prefered_name
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(os.path.join(post_directory, media_item)):
|
if not os.path.exists(os.path.join(post_directory, media_item)):
|
||||||
#TODO: stream is true is a conditional so we could check the headers for things, mimetype etc
|
#TODO: stream is true is a conditional so we could check the headers for things, mimetype etc
|
||||||
response = requests.get(url, stream=True)
|
response = requests.get(url, headers=headers, stream=True)
|
||||||
if response.ok:
|
if response.ok:
|
||||||
with open(os.path.join(post_directory, media_item), 'wb') as media_file:
|
with open(os.path.join(post_directory, media_item), 'wb') as media_file:
|
||||||
shutil.copyfileobj(response.raw, media_file)
|
shutil.copyfileobj(response.raw, media_file)
|
||||||
|
Loading…
Reference in New Issue
Block a user