Skip to content

Commit

Permalink
Add new filetype support and allow saucenao on all files with thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
floogulinc committed Aug 10, 2023
1 parent 05d7b41 commit b9cbfe3
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/app/exif-reader.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export class ExifReaderService {
HydrusFiletype.IMAGE_JPEG,
HydrusFiletype.IMAGE_PNG,
HydrusFiletype.IMAGE_TIFF,
HydrusFiletype.IMAGE_WEBP
//HEIC/HEIF when added to hydrus
HydrusFiletype.IMAGE_WEBP,
HydrusFiletype.IMAGE_HEIF,
HydrusFiletype.IMAGE_HEIC,
HydrusFiletype.IMAGE_HEIC_SEQUENCE,
].includes(file.file_type)
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/file-info-sheet/file-info-sheet.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class FileInfoSheetComponent {
this.downloadService.shareFile(this.data.file);
}

canSaucenao = this.saucenaoService.canSaucenao && this.saucenaoService.validSaucenaoMime(this.data.file.mime);
canSaucenao = this.saucenaoService.canSaucenao && this.saucenaoService.validSaucenaoFile(this.data.file);

saucenaoLookup() {
const addUrlOptions: AddUrlOptions = {};
Expand Down
132 changes: 132 additions & 0 deletions src/app/hydrus-file-mimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ export enum HydrusFiletype {
IMAGE_SVG = 56,
APPLICATION_XCF = 57,
APPLICATION_GZIP = 58,
GENERAL_APPLICATION_ARCHIVE = 59,
GENERAL_IMAGE_PROJECT = 60,
IMAGE_HEIF = 61,
IMAGE_HEIF_SEQUENCE = 62,
IMAGE_HEIC = 63,
IMAGE_HEIC_SEQUENCE = 64,
IMAGE_AVIF = 65,
IMAGE_AVIF_SEQUENCE = 66,
APPLICATION_OCTET_STREAM = 100,
APPLICATION_UNKNOWN = 101
}
Expand All @@ -73,6 +81,12 @@ const searchableFileTypes = [
HydrusFiletype.IMAGE_TIFF,
HydrusFiletype.IMAGE_ICON,
HydrusFiletype.IMAGE_SVG,
HydrusFiletype.IMAGE_HEIF,
HydrusFiletype.IMAGE_HEIF_SEQUENCE,
HydrusFiletype.IMAGE_HEIC,
HydrusFiletype.IMAGE_HEIC_SEQUENCE,
HydrusFiletype.IMAGE_AVIF,
HydrusFiletype.IMAGE_AVIF_SEQUENCE,
HydrusFiletype.APPLICATION_FLASH,
HydrusFiletype.VIDEO_AVI,
HydrusFiletype.VIDEO_FLV,
Expand Down Expand Up @@ -107,6 +121,96 @@ const searchableFileTypes = [
HydrusFiletype.AUDIO_WAVPACK
]

const IMAGES = [
HydrusFiletype.IMAGE_JPEG,
HydrusFiletype.IMAGE_PNG,
HydrusFiletype.IMAGE_BMP,
HydrusFiletype.IMAGE_WEBP,
HydrusFiletype.IMAGE_TIFF,
HydrusFiletype.IMAGE_ICON,
HydrusFiletype.IMAGE_HEIF,
HydrusFiletype.IMAGE_HEIC,
HydrusFiletype.IMAGE_AVIF,
]

const ANIMATIONS = [
HydrusFiletype.IMAGE_GIF,
HydrusFiletype.IMAGE_APNG,
HydrusFiletype.IMAGE_HEIF_SEQUENCE,
HydrusFiletype.IMAGE_HEIC_SEQUENCE,
HydrusFiletype.IMAGE_AVIF_SEQUENCE,
]

const HEIF_TYPE_SEQUENCES = [
HydrusFiletype.IMAGE_HEIF_SEQUENCE,
HydrusFiletype.IMAGE_HEIC_SEQUENCE,
HydrusFiletype.IMAGE_AVIF_SEQUENCE
]

const AUDIO = [
HydrusFiletype.AUDIO_MP3,
HydrusFiletype.AUDIO_OGG,
HydrusFiletype.AUDIO_FLAC,
HydrusFiletype.AUDIO_M4A,
HydrusFiletype.AUDIO_MKV,
HydrusFiletype.AUDIO_MP4,
HydrusFiletype.AUDIO_REALMEDIA,
HydrusFiletype.AUDIO_TRUEAUDIO,
HydrusFiletype.AUDIO_WAVE,
HydrusFiletype.AUDIO_WAVPACK,
HydrusFiletype.AUDIO_WMA
]

const VIDEO = [
HydrusFiletype.VIDEO_MP4,
HydrusFiletype.VIDEO_WEBM,
HydrusFiletype.VIDEO_MKV,
HydrusFiletype.VIDEO_AVI,
HydrusFiletype.VIDEO_FLV,
HydrusFiletype.VIDEO_MOV,
HydrusFiletype.VIDEO_MPEG,
HydrusFiletype.VIDEO_OGV,
HydrusFiletype.VIDEO_REALMEDIA,
HydrusFiletype.VIDEO_WMV
]

const APPLICATIONS = [
HydrusFiletype.APPLICATION_FLASH,
HydrusFiletype.APPLICATION_PDF
]

const IMAGE_PROJECT_FILES = [
HydrusFiletype.APPLICATION_PSD,
HydrusFiletype.APPLICATION_CLIP,
HydrusFiletype.APPLICATION_SAI2,
HydrusFiletype.APPLICATION_KRITA,
HydrusFiletype.IMAGE_SVG,
HydrusFiletype.APPLICATION_XCF
]

const ARCHIVES = [
HydrusFiletype.APPLICATION_7Z,
HydrusFiletype.APPLICATION_GZIP,
HydrusFiletype.APPLICATION_RAR,
HydrusFiletype.APPLICATION_ZIP
]

const MIMES_WITH_THUMBNAILS = [
...IMAGES,
...ANIMATIONS,
...VIDEO,
HydrusFiletype.IMAGE_SVG,
HydrusFiletype.APPLICATION_PDF,
HydrusFiletype.APPLICATION_FLASH,
HydrusFiletype.APPLICATION_CLIP,
HydrusFiletype.APPLICATION_PSD,
HydrusFiletype.APPLICATION_KRITA
]

export function hasThumbnail(mime: HydrusFiletype) {
return MIMES_WITH_THUMBNAILS.includes(mime);
}

export const mime_string_lookup: Record<HydrusFiletype, string> = {
[HydrusFiletype.APPLICATION_HYDRUS_CLIENT_COLLECTION] : 'collection',
[HydrusFiletype.IMAGE_JPEG] : 'jpeg',
Expand All @@ -118,6 +222,12 @@ export const mime_string_lookup: Record<HydrusFiletype, string> = {
[HydrusFiletype.IMAGE_TIFF] : 'tiff',
[HydrusFiletype.IMAGE_ICON] : 'icon',
[HydrusFiletype.IMAGE_SVG] : 'svg',
[HydrusFiletype.IMAGE_HEIF]: 'heif',
[HydrusFiletype.IMAGE_HEIF_SEQUENCE]: 'heif sequence',
[HydrusFiletype.IMAGE_HEIC]: 'heic',
[HydrusFiletype.IMAGE_HEIC_SEQUENCE]: 'heic sequence',
[HydrusFiletype.IMAGE_AVIF]: 'avif',
[HydrusFiletype.IMAGE_AVIF_SEQUENCE]: 'avif sequence',
[HydrusFiletype.APPLICATION_FLASH] : 'flash',
[HydrusFiletype.APPLICATION_OCTET_STREAM] : 'application/octet-stream',
[HydrusFiletype.APPLICATION_YAML] : 'yaml',
Expand Down Expand Up @@ -165,6 +275,8 @@ export const mime_string_lookup: Record<HydrusFiletype, string> = {
[HydrusFiletype.UNDETERMINED_PNG] : 'png or apng',
[HydrusFiletype.APPLICATION_UNKNOWN] : 'unknown filetype',
[HydrusFiletype.GENERAL_APPLICATION] : 'application',
[HydrusFiletype.GENERAL_APPLICATION_ARCHIVE] : 'archive',
[HydrusFiletype.GENERAL_IMAGE_PROJECT] : 'image project file',
[HydrusFiletype.GENERAL_AUDIO] : 'audio',
[HydrusFiletype.GENERAL_IMAGE] : 'image',
[HydrusFiletype.GENERAL_VIDEO] : 'video',
Expand All @@ -182,6 +294,12 @@ const mime_mimetype_string_lookup: Partial<Record<HydrusFiletype, string>> = {
[HydrusFiletype.IMAGE_TIFF] : 'image/tiff',
[HydrusFiletype.IMAGE_ICON] : 'image/x-icon',
[HydrusFiletype.IMAGE_SVG] : 'image/svg+xml',
[HydrusFiletype.IMAGE_HEIF]: 'image/heif',
[HydrusFiletype.IMAGE_HEIF_SEQUENCE]: 'image/heif-sequence',
[HydrusFiletype.IMAGE_HEIC]: 'image/heic',
[HydrusFiletype.IMAGE_HEIC_SEQUENCE]: 'image/heic-sequence',
[HydrusFiletype.IMAGE_AVIF]: 'image/avif',
[HydrusFiletype.IMAGE_AVIF_SEQUENCE]: 'image/avif-sequence',
[HydrusFiletype.APPLICATION_FLASH] : 'application/x-shockwave-flash',
[HydrusFiletype.APPLICATION_OCTET_STREAM] : 'application/octet-stream',
[HydrusFiletype.APPLICATION_YAML] : 'application/x-yaml',
Expand Down Expand Up @@ -226,6 +344,8 @@ const mime_mimetype_string_lookup: Partial<Record<HydrusFiletype, string>> = {
[HydrusFiletype.VIDEO_WEBM] : 'video/webm',
[HydrusFiletype.APPLICATION_UNKNOWN] : 'unknown filetype',
[HydrusFiletype.GENERAL_APPLICATION] : 'application',
[HydrusFiletype.GENERAL_APPLICATION_ARCHIVE] : 'archive',
[HydrusFiletype.GENERAL_IMAGE_PROJECT] : 'image project file',
[HydrusFiletype.GENERAL_AUDIO] : 'audio',
[HydrusFiletype.GENERAL_IMAGE] : 'image',
[HydrusFiletype.GENERAL_VIDEO] : 'video',
Expand All @@ -243,6 +363,12 @@ const mime_ext_lookup: Partial<Record<HydrusFiletype, string>> = {
[HydrusFiletype.IMAGE_TIFF] : '.tiff',
[HydrusFiletype.IMAGE_ICON] : '.ico',
[HydrusFiletype.IMAGE_SVG] : '.svg',
[HydrusFiletype.IMAGE_HEIF]: '.heif',
[HydrusFiletype.IMAGE_HEIF_SEQUENCE]: '.heifs',
[HydrusFiletype.IMAGE_HEIC]: '.heic',
[HydrusFiletype.IMAGE_HEIC_SEQUENCE]: '.heics',
[HydrusFiletype.IMAGE_AVIF]: '.avif',
[HydrusFiletype.IMAGE_AVIF_SEQUENCE]: '.avifs',
[HydrusFiletype.APPLICATION_FLASH] : '.swf',
[HydrusFiletype.APPLICATION_OCTET_STREAM] : '.bin',
[HydrusFiletype.APPLICATION_YAML] : '.yaml',
Expand Down Expand Up @@ -301,6 +427,12 @@ const mime_enum_lookup: Record<string, HydrusFiletype> = {
'image/tiff' : HydrusFiletype.IMAGE_TIFF,
'image/x-icon' : HydrusFiletype.IMAGE_ICON,
'image/svg+xml': HydrusFiletype.IMAGE_SVG,
'image/heif' : HydrusFiletype.IMAGE_HEIF,
'image/heif-sequence' : HydrusFiletype.IMAGE_HEIF_SEQUENCE,
'image/heic' : HydrusFiletype.IMAGE_HEIC,
'image/heic-sequence' : HydrusFiletype.IMAGE_HEIC_SEQUENCE,
'image/avif' : HydrusFiletype.IMAGE_AVIF,
'image/avif-sequence' : HydrusFiletype.IMAGE_AVIF_SEQUENCE,
'image/vnd.microsoft.icon' : HydrusFiletype.IMAGE_ICON,
'image' : HydrusFiletype.GENERAL_IMAGE,
'application/x-shockwave-flash' : HydrusFiletype.APPLICATION_FLASH,
Expand Down
9 changes: 8 additions & 1 deletion src/app/hydrus-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export interface HydrusBasicFile extends HydrusBasicFileFromAPI {
file_category: FileCategory;
file_type: HydrusFiletype;
file_type_string: string;
has_thumbnail: boolean;
}

export interface HydrusFileList {
Expand Down Expand Up @@ -165,7 +166,13 @@ export function getFileCategory(type: HydrusFiletype): FileCategory {
HydrusFiletype.IMAGE_GIF,
HydrusFiletype.IMAGE_BMP,
HydrusFiletype.IMAGE_WEBP,
HydrusFiletype.IMAGE_SVG
HydrusFiletype.IMAGE_SVG,
HydrusFiletype.IMAGE_HEIF,
HydrusFiletype.IMAGE_HEIF_SEQUENCE,
HydrusFiletype.IMAGE_HEIC,
HydrusFiletype.IMAGE_HEIC_SEQUENCE,
HydrusFiletype.IMAGE_AVIF,
HydrusFiletype.IMAGE_AVIF_SEQUENCE,
].includes(type)) {
return FileCategory.Image;
}
Expand Down
5 changes: 3 additions & 2 deletions src/app/hydrus-files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Observable, of, forkJoin } from 'rxjs';
import { HydrusApiService } from './hydrus-api.service';
import { map, tap } from 'rxjs/operators';
import { HydrusServices } from './hydrus-services';
import { HydrusFiletype, filetypeFromMime, mime_string_lookup } from './hydrus-file-mimes';
import { HydrusFiletype, filetypeFromMime, hasThumbnail, mime_string_lookup } from './hydrus-file-mimes';

function chunk<T>(array: T[], size: number): T[][] {
const chunked = [];
Expand Down Expand Up @@ -120,7 +120,8 @@ export class HydrusFilesService {
thumbnail_url: this.api.getThumbnailURLFromHash(file.hash),
file_type: filetype,
file_category: getFileCategory(filetype),
file_type_string: filetype === HydrusFiletype.APPLICATION_UNKNOWN ? file.mime : mime_string_lookup[filetype]
file_type_string: filetype === HydrusFiletype.APPLICATION_UNKNOWN ? file.mime : mime_string_lookup[filetype],
has_thumbnail: hasThumbnail(filetype)
}
}

Expand Down
12 changes: 3 additions & 9 deletions src/app/saucenao.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SagiriClientError, SagiriServerError } from 'sagiri/dist/errors';
import { map, catchError } from 'rxjs/operators';
import { SagiriResult } from 'sagiri';
import { SettingsService } from './settings.service';
import { HydrusBasicFile } from './hydrus-file';

// from https://github.com/ClarityCafe/Sagiri/blob/master/lib/index.ts#L147-L156
/* interface SagiriResult {
Expand Down Expand Up @@ -64,15 +65,8 @@ export class SaucenaoService {
return !!this.settings.appSettings.saucenaoApiKey && !!this.settings.appSettings.saucenaoSearchProxy;
}

public validSaucenaoMime(mime: string) {
return ([
'image/jpeg',
'image/jpg',
'image/png',
'image/gif',
'image/bmp',
'image/webp'
].includes(mime));
public validSaucenaoFile(file: HydrusBasicFile) {
return file.has_thumbnail;
}

public searchResponse(urlOrFile: SaucenaoUrlorFile, queryOptions?: SaucenaoQuery): Observable<Response> {
Expand Down

0 comments on commit b9cbfe3

Please sign in to comment.