From 0746dc2ab77fcc6543bb212e820ef032fd0894b0 Mon Sep 17 00:00:00 2001 From: Paul Friederichsen Date: Sun, 9 Jul 2023 05:08:32 -0500 Subject: [PATCH] Add support for gzip files --- docs/getting_started_files.md | 1 + hydrus/core/HydrusConstants.py | 11 ++++++++--- hydrus/core/HydrusFileHandling.py | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/getting_started_files.md b/docs/getting_started_files.md index 919f898e..deffc9a8 100644 --- a/docs/getting_started_files.md +++ b/docs/getting_started_files.md @@ -94,6 +94,7 @@ Now: * **application/vnd.rar** (.rar) * **application/zip** (.zip) * **application/x-7z-compressed** (.7z) +* **application/gzip** (.gz) Although some support is imperfect for the complicated filetypes. For the Windows and Linux built releases, hydrus now embeds an MPV player for video, audio and gifs, which provides smooth playback and audio, but some other environments may not support MPV and so will default when possible to the native hydrus software renderer, which does not support audio. When something does not render how you want, right-clicking on its thumbnail presents the option 'open externally', which will open the file in the appropriate default program (e.g. ACDSee, VLC). diff --git a/hydrus/core/HydrusConstants.py b/hydrus/core/HydrusConstants.py index 9d95b519..60cd2694 100644 --- a/hydrus/core/HydrusConstants.py +++ b/hydrus/core/HydrusConstants.py @@ -716,12 +716,13 @@ AUDIO_WAVPACK = 53 APPLICATION_SAI2 = 54 APPLICATION_KRITA = 55 IMAGE_SVG = 56 +APPLICATION_GZIP = 57 APPLICATION_OCTET_STREAM = 100 APPLICATION_UNKNOWN = 101 GENERAL_FILETYPES = { GENERAL_APPLICATION, GENERAL_AUDIO, GENERAL_IMAGE, GENERAL_VIDEO, GENERAL_ANIMATION } -SEARCHABLE_MIMES = { IMAGE_JPEG, IMAGE_PNG, IMAGE_APNG, IMAGE_GIF, IMAGE_WEBP, IMAGE_TIFF, IMAGE_ICON, IMAGE_SVG, APPLICATION_FLASH, VIDEO_AVI, VIDEO_FLV, VIDEO_MOV, VIDEO_MP4, VIDEO_MKV, VIDEO_REALMEDIA, VIDEO_WEBM, VIDEO_OGV, VIDEO_MPEG, APPLICATION_CLIP, APPLICATION_PSD, APPLICATION_SAI2, APPLICATION_KRITA, APPLICATION_PDF, APPLICATION_ZIP, APPLICATION_RAR, APPLICATION_7Z, AUDIO_M4A, AUDIO_MP3, AUDIO_REALMEDIA, AUDIO_OGG, AUDIO_FLAC, AUDIO_WAVE, AUDIO_TRUEAUDIO, AUDIO_WMA, VIDEO_WMV, AUDIO_MKV, AUDIO_MP4, AUDIO_WAVPACK } +SEARCHABLE_MIMES = { IMAGE_JPEG, IMAGE_PNG, IMAGE_APNG, IMAGE_GIF, IMAGE_WEBP, IMAGE_TIFF, IMAGE_ICON, IMAGE_SVG, APPLICATION_FLASH, VIDEO_AVI, VIDEO_FLV, VIDEO_MOV, VIDEO_MP4, VIDEO_MKV, VIDEO_REALMEDIA, VIDEO_WEBM, VIDEO_OGV, VIDEO_MPEG, APPLICATION_CLIP, APPLICATION_PSD, APPLICATION_SAI2, APPLICATION_KRITA, APPLICATION_PDF, APPLICATION_ZIP, APPLICATION_RAR, APPLICATION_7Z, APPLICATION_GZIP, AUDIO_M4A, AUDIO_MP3, AUDIO_REALMEDIA, AUDIO_OGG, AUDIO_FLAC, AUDIO_WAVE, AUDIO_TRUEAUDIO, AUDIO_WMA, VIDEO_WMV, AUDIO_MKV, AUDIO_MP4, AUDIO_WAVPACK } STORABLE_MIMES = set( SEARCHABLE_MIMES ).union( { APPLICATION_HYDRUS_UPDATE_CONTENT, APPLICATION_HYDRUS_UPDATE_DEFINITIONS } ) @@ -737,7 +738,7 @@ AUDIO = { AUDIO_M4A, AUDIO_MP3, AUDIO_OGG, AUDIO_FLAC, AUDIO_WAVE, AUDIO_WMA, AU VIDEO = { VIDEO_AVI, VIDEO_FLV, VIDEO_MOV, VIDEO_MP4, VIDEO_WMV, VIDEO_MKV, VIDEO_REALMEDIA, VIDEO_WEBM, VIDEO_OGV, VIDEO_MPEG } -APPLICATIONS = { IMAGE_SVG, APPLICATION_FLASH, APPLICATION_PSD, APPLICATION_CLIP, APPLICATION_SAI2, APPLICATION_KRITA, APPLICATION_PDF, APPLICATION_ZIP, APPLICATION_RAR, APPLICATION_7Z } +APPLICATIONS = { IMAGE_SVG, APPLICATION_FLASH, APPLICATION_PSD, APPLICATION_CLIP, APPLICATION_SAI2, APPLICATION_KRITA, APPLICATION_PDF, APPLICATION_ZIP, APPLICATION_RAR, APPLICATION_7Z, APPLICATION_GZIP } general_mimetypes_to_mime_groups = { GENERAL_APPLICATION : APPLICATIONS, @@ -760,7 +761,7 @@ for ( general_mime_type, mimes_in_type ) in general_mimetypes_to_mime_groups.ite MIMES_THAT_DEFINITELY_HAVE_AUDIO = tuple( [ APPLICATION_FLASH ] + list( AUDIO ) ) MIMES_THAT_MAY_HAVE_AUDIO = tuple( list( MIMES_THAT_DEFINITELY_HAVE_AUDIO ) + list( VIDEO ) ) -ARCHIVES = { APPLICATION_ZIP, APPLICATION_HYDRUS_ENCRYPTED_ZIP, APPLICATION_RAR, APPLICATION_7Z } +ARCHIVES = { APPLICATION_ZIP, APPLICATION_HYDRUS_ENCRYPTED_ZIP, APPLICATION_RAR, APPLICATION_7Z, APPLICATION_GZIP } MIMES_WITH_THUMBNAILS = set( IMAGES ).union( ANIMATIONS ).union( VIDEO ).union( { IMAGE_SVG, APPLICATION_FLASH, APPLICATION_CLIP, APPLICATION_PSD, APPLICATION_KRITA } ) @@ -804,6 +805,7 @@ mime_enum_lookup = { 'application/zip' : APPLICATION_ZIP, 'application/vnd.rar' : APPLICATION_RAR, 'application/x-7z-compressed' : APPLICATION_7Z, + 'application/gzip': APPLICATION_GZIP, 'application/json' : APPLICATION_JSON, 'application/cbor': APPLICATION_CBOR, 'application/hydrus-encrypted-zip' : APPLICATION_HYDRUS_ENCRYPTED_ZIP, @@ -862,6 +864,7 @@ mime_string_lookup = { APPLICATION_ZIP : 'zip', APPLICATION_RAR : 'rar', APPLICATION_7Z : '7z', + APPLICATION_GZIP: 'gzip', APPLICATION_WINDOWS_EXE : 'windows exe', APPLICATION_HYDRUS_ENCRYPTED_ZIP : 'application/hydrus-encrypted-zip', APPLICATION_HYDRUS_UPDATE_CONTENT : 'application/hydrus-update-content', @@ -924,6 +927,7 @@ mime_mimetype_string_lookup = { APPLICATION_ZIP : 'application/zip', APPLICATION_RAR : 'application/vnd.rar', APPLICATION_7Z : 'application/x-7z-compressed', + APPLICATION_GZIP: 'application/gzip', APPLICATION_WINDOWS_EXE : 'application/octet-stream', APPLICATION_HYDRUS_ENCRYPTED_ZIP : 'application/hydrus-encrypted-zip', APPLICATION_HYDRUS_UPDATE_CONTENT : 'application/hydrus-update-content', @@ -986,6 +990,7 @@ mime_ext_lookup = { APPLICATION_ZIP : '.zip', APPLICATION_RAR : '.rar', APPLICATION_7Z : '.7z', + APPLICATION_GZIP: '.gz', APPLICATION_WINDOWS_EXE : '.exe', APPLICATION_HYDRUS_ENCRYPTED_ZIP : '.zip.encrypted', APPLICATION_HYDRUS_UPDATE_CONTENT : '', diff --git a/hydrus/core/HydrusFileHandling.py b/hydrus/core/HydrusFileHandling.py index fb2ca2f5..fd685dc3 100644 --- a/hydrus/core/HydrusFileHandling.py +++ b/hydrus/core/HydrusFileHandling.py @@ -77,6 +77,7 @@ headers_and_mime.extend( [ ( ( ( 0, b'7z\xBC\xAF\x27\x1C' ), ), HC.APPLICATION_7Z ), ( ( ( 0, b'\x52\x61\x72\x21\x1A\x07\x00' ), ), HC.APPLICATION_RAR ), ( ( ( 0, b'\x52\x61\x72\x21\x1A\x07\x01\x00' ), ), HC.APPLICATION_RAR ), + ( ( ( 0, b'\x1f\x8b' ), ), HC.APPLICATION_GZIP ), ( ( ( 0, b'hydrus encrypted zip' ), ), HC.APPLICATION_HYDRUS_ENCRYPTED_ZIP ), ( ( ( 4, b'ftypmp4' ), ), HC.UNDETERMINED_MP4 ), ( ( ( 4, b'ftypisom' ), ), HC.UNDETERMINED_MP4 ),