-
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.
Logging was being a pain so I hardcoded it.
- Loading branch information
1 parent
748ad1d
commit c208934
Showing
13 changed files
with
111 additions
and
87 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
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
34 changes: 8 additions & 26 deletions
34
src/main/kotlin/info/benjaminhill/slideshow/ClipFactory.kt
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 |
---|---|---|
@@ -1,33 +1,15 @@ | ||
package info.benjaminhill.slideshow | ||
|
||
import mu.KotlinLogging | ||
import java.io.File | ||
|
||
/** | ||
* Loads the correct Clip subclass based on media type (with some fallbacks) | ||
*/ | ||
object ClipFactory { | ||
private val LOG = KotlinLogging.logger {} | ||
|
||
fun fileToClip( | ||
file: File | ||
): Clip { | ||
if (listOf("mp4", "mpeg", "mov").contains(file.extension.toLowerCase())) { | ||
return ClipMovie(file) | ||
} | ||
|
||
if (file.extension.toLowerCase() == "gif") { | ||
return ClipGif(file) | ||
} | ||
|
||
if (listOf("jpg", "jpeg", "png").contains(file.extension.toLowerCase())) { | ||
if (file.name.startsWith("mvimg", true) || file.nameWithoutExtension.endsWith("_mp", true)) { | ||
try { | ||
return ClipMotionPhoto(file) | ||
} catch (e: Exception) { | ||
LOG.info { "${file.name} unable to extract motion photo video, ${e.message}" } | ||
} | ||
} | ||
|
||
return ClipStill(file) | ||
} | ||
error("${file.name} Don't know how to load file") | ||
fun fileToClip(file: File): Clip = when { | ||
listOf("mp4", "mpeg", "mov").contains(file.extension.toLowerCase()) -> ClipMovie(file) | ||
listOf("gif").contains(file.extension.toLowerCase()) -> ClipGif(file) | ||
listOf("jpg", "jpeg").contains(file.extension.toLowerCase()) && ClipMotionPhoto.isVideoEmbedded(file) -> ClipMotionPhoto(file) | ||
else -> ClipStill(file) | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package info.benjaminhill.util | ||
|
||
import java.lang.management.ManagementFactory | ||
|
||
|
||
class BasicLogger { | ||
var level = LEVEL.DEBUG | ||
private val jvmStartTime = ManagementFactory.getRuntimeMXBean().startTime | ||
private fun ts() = String.format("%09d", System.currentTimeMillis() - jvmStartTime) | ||
|
||
fun debug(message: () -> String) { | ||
if (level <= LEVEL.DEBUG) { | ||
println("${ts()} DEBUG: ${message()}") | ||
} | ||
} | ||
|
||
fun info(message: () -> String) { | ||
if (level <= LEVEL.INFO) { | ||
println("${ts()} INFO: ${message()}") | ||
} | ||
} | ||
|
||
fun warn(message: () -> String) { | ||
if (level <= LEVEL.WARN) { | ||
System.err.println("${ts()} WARN: ${message()}") | ||
} | ||
} | ||
|
||
fun error(message: () -> String) { | ||
if (level <= LEVEL.ERROR) { | ||
System.err.println("${ts()} ERROR: ${message()}") | ||
} | ||
} | ||
|
||
companion object { | ||
enum class LEVEL { | ||
DEBUG, | ||
INFO, | ||
WARN, | ||
ERROR | ||
} | ||
} | ||
} |
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,9 @@ | ||
package info.benjaminhill.util | ||
|
||
fun <T : Any> MutableList<T>.removeOrNull(): T? { | ||
return if (this.isNotEmpty()) { | ||
this.removeAt(0) | ||
} else { | ||
null | ||
} | ||
} |