Skip to content

Instantly share code, notes, and snippets.

@camallen
Created September 21, 2018 08:17
Show Gist options
  • Save camallen/ad6278cc88fad13eff767da0164eb062 to your computer and use it in GitHub Desktop.
Save camallen/ad6278cc88fad13eff767da0164eb062 to your computer and use it in GitHub Desktop.
Python magic lib test file mime types
# https://github.com/ahupp/python-magic#usage
import magic, csv
file_paths = (
'480_CornellFeeders_20171024_0921_000.mp4',
'480_CornellFeeders_20171024_0921_000.mp4',
'480_CornellFeeders_20171024_0921_001.mp4',
'480_CornellFeeders_20171024_0921_002.mp4'
)
def read_file_path_mime_type(path):
f = open(path, 'rb')
media_data = f.read()
media_type = magic.from_buffer(media_data, mime=True)
print("Path: %s has mime type: %s" %(path, media_type))
print('\ntest of the files - not via manifest')
for path in file_paths:
read_file_path_mime_type(path)
print('\ntest of the files - via manifest')
with open('manifest.csv', 'rb') as csvfile:
manifest_reader = csv.reader(csvfile)
for row in manifest_reader:
read_file_path_mime_type(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment