Analyze a Markdown file for Image URLs, download these files and generate a new markdown with the downloaded files.
Has only been tested on OSX!
call the script with markdown file as parameter and optionally a folder (-m) where to save the Media will keep only images that are downloaded and generates a new markdown file with replaced links
python3 mdMakelocal.py file.md [file2.md ..] [-m Folder]
- python3
with the libraries
- requests
- glob
- uuid
- hashlib
- markdown
- mimetypes
- threading
- lxml
- urllib
- If the filename already exists in the media folder, it will append the files md5 hash to the filename
- The original markdown file will no be modified, only a new one generated with the appendix '-localMedia-X' where X is a number increased when a file already exists with that name.
- Downloads are threaded
- Image Filename and extension is generated from (in the following order)
- html header 'content-disposition'
- filename and html header 'content-type'
- filename itself
- All links are downloaded, only afterwards the mimetype is detected. Then the file will be deleted if it's not matching a image type.
- the generated filename could be to long for the filesystem.
- Markdown file is converted to html to check for links, maybe would be nicer with regex?
Image links from w3.org to test the script on this file