Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenDocument formats detection #38

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions lib/marcel/tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,7 @@ module Marcel
['video/x-ogm', [[0, 'OggS', [[29, 'ideo']]]]],
['application/x-msdownload;format=pe', [[0, 'MZ', [[128, "PE\000\000"], [176, "PE\000\000"], [208, "PE\000\000"], [240, "PE\000\000"]]]]],
['application/applefile', [[0, "\000\005\026\000"]]],
['application/dash+xml', [[0, '<MPD']]],
['application/dicom', [[128, 'DICM']]],
['application/epub+zip', [[0, "PK\003\004", [[30, 'mimetypeapplication/epub+zip']]]]],
['application/fits', [[0, 'SIMPLE = T'], [0, 'SIMPLE = T']]],
Expand All @@ -2260,6 +2261,7 @@ module Marcel
['application/sereal;version=2', [[0, '=srl']]],
['application/sereal;version=3', [[0, "=\363rl"]]],
['application/timestamped-data', [[0, "0\200\006\v*\206H\206\367"]]],
['application/vnd.apple.mpegurl', [[0, '#EXTM3U']]],
['application/vnd.digilite.prolights', [[0, "\177\fD+"]]],
['application/vnd.fdf', [[0, '%FDF-']]],
['application/vnd.java.hprof ', [[0, "JAVA PROFILE \\\\d\\\\.\\\\d\\\\.\\\\d\\\\u0000"]]],
Expand All @@ -2277,11 +2279,28 @@ module Marcel
['application/vnd.ms-outlook-pst', [[0, '!BDN', [[8, 'SM']]]]],
['application/vnd.ms-tnef', [[0, "x\237>\""]]],
['application/vnd.ms-works', [[0..8, "\320\317\021\340\241\261\032\341", [[1152..4096, "M\000a\000t\000O\000S\000T"]]]]],
['application/vnd.oasis.opendocument.chart', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.chart']]]]],
['application/vnd.oasis.opendocument.chart-template', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.chart-template']]]]],
['application/vnd.oasis.opendocument.formula', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.formula']]]]],
['application/vnd.oasis.opendocument.formula-template', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.formula-template']]]]],
['application/vnd.oasis.opendocument.graphics', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.graphics']]]]],
['application/vnd.oasis.opendocument.graphics-template', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.graphics-template']]]]],
['application/vnd.oasis.opendocument.image', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.image']]]]],
['application/vnd.oasis.opendocument.image-template', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.image-template']]]]],
['application/vnd.oasis.opendocument.presentation', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.presentation']]]]],
['application/vnd.oasis.opendocument.presentation-template', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.presentation-template']]]]],
['application/vnd.oasis.opendocument.spreadsheet', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.spreadsheet']]]]],
['application/vnd.oasis.opendocument.spreadsheet-template', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.spreadsheet-template']]]]],
['application/vnd.oasis.opendocument.text', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.text']]]]],
['application/vnd.oasis.opendocument.text-master', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.text-master']]]]],
['application/vnd.oasis.opendocument.text-template', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.text-template']]]]],
['application/vnd.oasis.opendocument.text-web', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.text-web']]]]],
['application/vnd.rn-realmedia', [[0, '.RMF']]],
['application/vnd.stardivision.calc', [[0..8, "\320\317\021\340\241\261\032\341", [[2048..2207, 'StarCalc']]]]],
['application/vnd.stardivision.draw', [[0..8, "\320\317\021\340\241\261\032\341", [[2048..2207, 'StarDraw']]]]],
['application/vnd.stardivision.impress', [[0..8, "\320\317\021\340\241\261\032\341", [[2048..2207, 'StarImpress']]]]],
['application/vnd.stardivision.writer', [[0..8, "\320\317\021\340\241\261\032\341", [[2048..2207, 'StarWriter']]]]],
['application/vnd.sun.xml.writer', [[0, 'PK', [[30, 'mimetypeapplication/vnd.sun.xml.writer']]]]],
['application/vnd.symbian.install', [[8, "\031\004\000\020"]]],
['application/vnd.tcpdump.pcap', [[0, "\241\262\303\324"], [0, "\324\303\262\241"]]],
['application/vnd.wolfram.wl', [[0, '#!/usr/bin/env wolframscript']]],
Expand Down Expand Up @@ -2316,6 +2335,7 @@ module Marcel
['application/x-erdas-hfa', [[0, 'EHFA_HEADER_TAG']]],
['application/x-executable', [[0, "\177ELF", [[16, "\002\000"], [16, "\000\002"]]]]],
['application/x-filemaker', [[14, "\300HBAM7", [[525, "HBAM2101OCT99\301\002H\aPro 7.0\300\300"]]]]],
['application/x-foxmail', [[0, "\020\020\020\020\020\020\020\021\021\021\021\021\021S"]]],
['application/x-gnumeric', [[39, '=<gmr:Workbook']]],
['application/x-grib', [[0, 'GRIB']]],
['application/x-gtar', [[257, "ustar \000"]]],
Expand Down Expand Up @@ -2435,6 +2455,7 @@ module Marcel
['video/mj2', [[0, "\000\000\000\fjP \r\n\207\n", [[20, 'mjp2']]]]],
['video/x-jng', [[0, "\213JNG"]]],
['video/x-mng', [[0, "\212MNG"]]],
['video/x-ms-asf', [[0, "0&\262u"]]],
['video/x-sgi-movie', [[0, "MOVI\000"], [0, "MOVI\001"], [0, "MOVI\002"], [0, "MOVI\376"], [0, "MOVI\377"]]],
['application/gzip', [[0, "\037\213"], [0, "\037\213"]]],
['application/zlib', [[0, "x\001"], [0, 'x^'], [0, "x\234"], [0, "x\332"]]],
Expand Down Expand Up @@ -2484,26 +2505,5 @@ module Marcel
['text/html', [[128..8192, '<html']]],
['text/plain', [[0, 'This is TeX,'], [0, 'This is METAFONT,'], [0, '/*'], [0, '//'], [0, ';;'], [0, "\376\377"], [0, "\377\376"], [0, "\357\273\277"]]],
['text/x-makefile', [[0, '# Makefile.in generated by'], [0, '#!make'], [0, '#!/usr/bin/make'], [0, '#!/usr/local/bin/make'], [0, '#!/usr/bin/env make']]],
['application/dash+xml', [[0, '<MPD']]],
['application/vnd.apple.mpegurl', [[0, '#EXTM3U']]],
['application/vnd.oasis.opendocument.chart', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.chart']]]]],
['application/vnd.oasis.opendocument.chart-template', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.chart-template']]]]],
['application/vnd.oasis.opendocument.formula', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.formula']]]]],
['application/vnd.oasis.opendocument.formula-template', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.formula-template']]]]],
['application/vnd.oasis.opendocument.graphics', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.graphics']]]]],
['application/vnd.oasis.opendocument.graphics-template', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.graphics-template']]]]],
['application/vnd.oasis.opendocument.image', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.image']]]]],
['application/vnd.oasis.opendocument.image-template', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.image-template']]]]],
['application/vnd.oasis.opendocument.presentation', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.presentation']]]]],
['application/vnd.oasis.opendocument.presentation-template', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.presentation-template']]]]],
['application/vnd.oasis.opendocument.spreadsheet', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.spreadsheet']]]]],
['application/vnd.oasis.opendocument.spreadsheet-template', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.spreadsheet-template']]]]],
['application/vnd.oasis.opendocument.text', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.text']]]]],
['application/vnd.oasis.opendocument.text-master', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.text-master']]]]],
['application/vnd.oasis.opendocument.text-template', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.text-template']]]]],
['application/vnd.oasis.opendocument.text-web', [[0, 'PK', [[30, 'mimetypeapplication/vnd.oasis.opendocument.text-web']]]]],
['application/vnd.sun.xml.writer', [[0, 'PK', [[30, 'mimetypeapplication/vnd.sun.xml.writer']]]]],
['application/x-foxmail', [[0, "\020\020\020\020\020\020\020\021\021\021\021\021\021S"]]],
['video/x-ms-asf', [[0, "0&\262u"]]],
]
end
4 changes: 2 additions & 2 deletions script/generate_tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def get_matches(parent)
subclass = (mime/'sub-class-of').map{|x| x['type']}
exts = (mime/'glob').map{|x| x['pattern'] =~ /^\*\.([^\[\]]+)$/ ? $1.downcase : nil }.compact
(mime/'magic').each do |magic|
priority = magic['priority'].to_i
priority = (magic['priority'] || '50').to_i
matches = get_matches(magic)
magics << [priority, type, matches]
end
Expand All @@ -121,7 +121,7 @@ def get_matches(parent)
end
end

magics = magics.sort {|a,b| [-a[0],a[1]] <=> [-b[0],b[1]] }
magics = magics.sort_by { |priority, type| [-priority, type] }

common_types = [
"image/jpeg", # .jpg
Expand Down
Binary file not shown.
Binary file not shown.