forked from kitodo/kitodo-production
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kitodo#5835 from markusweigelt/fix-phyiscaldivisio…
…n-type-of-av-for-3.6 For 3.6.x - Use type track for audio and video MIME types instead of type page for physical division type
- Loading branch information
Showing
14 changed files
with
264 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* (c) Kitodo. Key to digital objects e. V. <[email protected]> | ||
* | ||
* This file is part of the Kitodo project. | ||
* | ||
* It is licensed under GNU General Public License version 3 or later. | ||
* | ||
* For the full copyright and license information, please read the | ||
* GPL3-License.txt file that was distributed with this source code. | ||
*/ | ||
|
||
package org.kitodo.utils; | ||
|
||
import java.util.Objects; | ||
|
||
import org.kitodo.api.dataformat.PhysicalDivision; | ||
|
||
public class MediaUtil { | ||
|
||
public static final String MIME_TYPE_AUDIO_PREFIX = "audio"; | ||
public static final String MIME_TYPE_IMAGE_PREFIX = "image"; | ||
public static final String MIME_TYPE_VIDEO_PREFIX = "video"; | ||
|
||
/** | ||
* Private constructor to hide the implicit public one. | ||
*/ | ||
private MediaUtil() { | ||
|
||
} | ||
|
||
/** | ||
* Check if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_AUDIO_PREFIX} or | ||
* {@link org.kitodo.utils.MediaUtil#MIME_TYPE_VIDEO_PREFIX}. | ||
* | ||
* @param mimeType | ||
* The mime type to check | ||
* @return True if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_AUDIO_PREFIX} or | ||
* {@link org.kitodo.utils.MediaUtil#MIME_TYPE_VIDEO_PREFIX}. | ||
*/ | ||
public static boolean isAudioOrVideo(String mimeType) { | ||
return isAudio(mimeType) || isVideo(mimeType); | ||
} | ||
|
||
/** | ||
* Check if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_AUDIO_PREFIX}. | ||
* | ||
* @param mimeType | ||
* The mime type to check | ||
* @return True if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_AUDIO_PREFIX} | ||
*/ | ||
public static boolean isAudio(String mimeType) { | ||
return Objects.nonNull(mimeType) && mimeType.startsWith(MIME_TYPE_AUDIO_PREFIX); | ||
} | ||
|
||
/** | ||
* Check if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_IMAGE_PREFIX}. | ||
* | ||
* @param mimeType | ||
* The mime type to check | ||
* @return True if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_IMAGE_PREFIX} | ||
*/ | ||
public static boolean isImage(String mimeType) { | ||
return Objects.nonNull(mimeType) && mimeType.startsWith(MIME_TYPE_IMAGE_PREFIX); | ||
} | ||
|
||
/** | ||
* Check if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_VIDEO_PREFIX}. | ||
* | ||
* @param mimeType | ||
* The mime type to check | ||
* @return True if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_VIDEO_PREFIX} | ||
*/ | ||
public static boolean isVideo(String mimeType) { | ||
return Objects.nonNull(mimeType) && mimeType.startsWith(MIME_TYPE_VIDEO_PREFIX); | ||
} | ||
|
||
/** | ||
* Get the type of {@link org.kitodo.api.dataformat.PhysicalDivision} by mime type. | ||
* | ||
* @param mimeType | ||
* The mime type to get the physical division type for | ||
* @return The type of the {@link org.kitodo.api.dataformat.PhysicalDivision} | ||
*/ | ||
public static String getPhysicalDivisionTypeOfMimeType(String mimeType) { | ||
if (isImage(mimeType)) { | ||
return PhysicalDivision.TYPE_PAGE; | ||
} | ||
if (isAudioOrVideo(mimeType)) { | ||
return PhysicalDivision.TYPE_TRACK; | ||
} | ||
return PhysicalDivision.TYPE_OTHER; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
Kitodo-API/src/test/java/org/kitodo/utils/MediaUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* (c) Kitodo. Key to digital objects e. V. <[email protected]> | ||
* | ||
* This file is part of the Kitodo project. | ||
* | ||
* It is licensed under GNU General Public License version 3 or later. | ||
* | ||
* For the full copyright and license information, please read the | ||
* GPL3-License.txt file that was distributed with this source code. | ||
*/ | ||
|
||
package org.kitodo.utils; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
import org.kitodo.api.dataformat.PhysicalDivision; | ||
|
||
public class MediaUtilTest { | ||
|
||
/** | ||
* Test detection of mime type. | ||
*/ | ||
@Test | ||
public void testMimeTypeDetection() { | ||
assertTrue(MediaUtil.isAudio("audio/mp3")); | ||
assertFalse(MediaUtil.isVideo("image/jpeg")); | ||
|
||
assertTrue(MediaUtil.isImage("image/jpeg")); | ||
assertFalse(MediaUtil.isImage("video/mp4")); | ||
|
||
assertTrue(MediaUtil.isVideo("video/mp4")); | ||
assertFalse(MediaUtil.isVideo("image/jpeg")); | ||
|
||
assertTrue(MediaUtil.isAudioOrVideo("audio/mp3")); | ||
assertTrue(MediaUtil.isAudioOrVideo("video/mp4")); | ||
assertFalse(MediaUtil.isAudioOrVideo("image/jpeg")); | ||
} | ||
|
||
/** | ||
* Test getting the type of the {@link org.kitodo.api.dataformat.PhysicalDivision}. | ||
*/ | ||
@Test | ||
public void testGettingPhysicalDivisionTypeByMimeType() { | ||
assertEquals(PhysicalDivision.TYPE_PAGE, MediaUtil.getPhysicalDivisionTypeOfMimeType("image/jpeg")); | ||
assertEquals(PhysicalDivision.TYPE_TRACK, MediaUtil.getPhysicalDivisionTypeOfMimeType("audio/mp3")); | ||
assertEquals(PhysicalDivision.TYPE_TRACK, MediaUtil.getPhysicalDivisionTypeOfMimeType("video/mp4")); | ||
assertEquals(PhysicalDivision.TYPE_OTHER, MediaUtil.getPhysicalDivisionTypeOfMimeType("application/pdf")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.