/* * Media Converter * Extracts media files from Fedora repository * Copyright (C) 2020 Memoriav * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ package ch.memobase.models /** * Represents a media file type manageable by media conversion tools */ sealed trait MediaFileType /** * Represents any manageable audio file type */ sealed trait AudioFileType extends MediaFileType /** * Represents any manageable image file type */ sealed trait ImageFileType extends MediaFileType /** * Represents any manageable video file type */ sealed trait VideoFileType extends MediaFileType /** * Represents an unknown file type */ case object UnknownFileType extends MediaFileType /** * Represents an MP3 file */ case object Mp3File extends AudioFileType /** * Represents an OGA file */ case object OgaFile extends AudioFileType /** * Represents a JPG file */ case object JpegFile extends ImageFileType /** * Represents a PNG file */ case object PngFile extends ImageFileType /** * Represents a MPEG4 video file */ case object VideoMpeg4File extends VideoFileType /** * Helps with conversions between different representations of file types */ object Conversions { private val fileTypeTuples: List[(MediaFileType, List[String], String)] = List( (Mp3File, List("audio/mpeg"), "mp3"), (OgaFile, List("audio/ogg"), "oga"), (JpegFile, List("image/jpeg"), "jpg"), (PngFile, List("image/png"), "png"), (VideoMpeg4File, List("video/mp4"), "mp4") // TODO: Other filetypes... ) lazy val getMediaFileType: String => Option[MediaFileType] = (mimeType: String) => fileTypeTuples.collectFirst { case (ft, mt, _) if mt.contains(mimeType) => ft } lazy val getFileTypeExtension: MediaFileType => Option[String] = (mediaFileType: MediaFileType) => fileTypeTuples.collectFirst { case (ft, _, ex) if ft == mediaFileType => ex } }