Python library uses filetype to accurately determine file types

Source: Internet
Author: User
Tags rar webp

FileType effect

A small, free-to-open Python development package used primarily to obtain file types.

FileType Supported versions:

Python2/python3

FileType Installation:

Pip Install filetype

FileType Functional Features

? Simple and Friendly API

Support wide range file types

? provide file extension and MIME type judgment

? file MIME type extension new

? Through files (image, video, audio ...) ) Simple analysis

? Pluggable: Add a match for a new custom type

Fast, even when dealing with large files

? Only the top 261 bytes are required to represent the maximum file header, so you can pass a single byte

? dependent on freedom (just Python code, no extensions for C, no libmagic bindings)

? cross-platform file recognition

code example:

ImportfiletypedefMain (): Kind= Filetype.guess ('tests/fixtures/sample.jpg')    ifKind isNone:Print('cannot guess file type!')        return    Print('File Extension:%s'%kind.extension)Print('File MIME Type:%s'%kind.mime)if __name__=='__main__': Main ()

Type of support

Image

? Jpg–image/jpeg

? Png–image/png

? Gif–image/gif

? Webp–image/webp

? Cr2–image/x-canon-cr2

? Tif–image/tiff

? Bmp–image/bmp

? Jxr–image/vnd.ms-photo

? Psd–image/vnd.adobe.photoshop

? Ico–image/x-icon

Video

? Mp4–video/mp4

? m4v–video/x-m4v

? Mkv–video/x-matroska

? Webm–video/webm

? Mov–video/quicktime

? Avi–video/x-msvideo

? Wmv–video/x-ms-wmv

? Mpg–video/mpeg

? flv–video/x-flv

Audio

? Mid–audio/midi

? Mp3–audio/mpeg

? m4a–audio/m4a

? Ogg–audio/ogg

? Flac–audio/x-flac

? Wav–audio/x-wav

? Amr–audio/amr

Data base

? Epub–application/epub+zip

? Zip–application/zip

? Tar–application/x-tar

? Rar–application/x-rar-compressed

? Gz–application/gzip

? Bz2–application/x-bzip2

? 7z–application/x-7z-compressed

? Xz–application/x-xz

? Pdf–application/pdf

? Exe–application/x-msdownload

? Swf–application/x-shockwave-flash

? Rtf–application/rtf

? Eot–application/octet-stream

? Ps–application/postscript

? Sqlite–application/x-sqlite3

? Nes–application/x-nintendo-nes-rom

? Crx–application/x-google-chrome-extension

? Cab–application/vnd.ms-cab-compressed

? Deb–application/x-deb

? Ar–application/x-unix-archive

? Z–application/x-compress

? Lz–application/x-lzip

Font

? Woff–application/font-woff

? Woff2–application/font-woff

? Ttf–application/font-sfnt

? Otf–application/font-sfnt

Python library uses filetype to accurately determine file types

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.