handle feeds with enclosures (featured media / podcasts) #35

Merged
r merged 5 commits from r/konfluks:master into master 2022-06-01 06:05:37 +00:00
Showing only changes of commit cab36c8ac6 - Show all commits

View File

@ -194,13 +194,17 @@ def grab_media(post_directory, url, prefered_name=None):
"""
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:
media_item = prefered_name
try:
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
response = requests.get(url, stream=True)
response = requests.get(url, headers=headers, stream=True)
if response.ok:
with open(os.path.join(post_directory, media_item), 'wb') as media_file:
shutil.copyfileobj(response.raw, media_file)