-
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 #52 from KevinSchildhorn/FileMetadata
File metadata
- Loading branch information
Showing
27 changed files
with
344 additions
and
41 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
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
17 changes: 17 additions & 0 deletions
17
shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/data/MetadataDetails.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.kevinschildhorn.fotopresenter.data | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class MetadataDetails( | ||
val files: MutableList<MetadataFileDetails> | ||
) | ||
|
||
@Serializable | ||
data class MetadataFileDetails( | ||
val filePath: String, | ||
val tags: Set<String>, | ||
) { | ||
val tagsString: String | ||
get() = tags.joinToString(", ") | ||
} |
64 changes: 64 additions & 0 deletions
64
...Main/kotlin/com/kevinschildhorn/fotopresenter/data/datasources/ImageMetadataDataSource.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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.kevinschildhorn.fotopresenter.data.datasources | ||
|
||
import co.touchlab.kermit.Logger | ||
import com.ashampoo.kim.Kim | ||
import com.ashampoo.kim.common.convertToPhotoMetadata | ||
import com.ashampoo.kim.format.tiff.constants.ExifTag | ||
import com.kevinschildhorn.fotopresenter.data.MetadataDetails | ||
import com.kevinschildhorn.fotopresenter.data.MetadataFileDetails | ||
import com.kevinschildhorn.fotopresenter.data.network.NetworkHandler | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
|
||
class ImageMetadataDataSource( | ||
private val logger: Logger?, | ||
private val networkHandler: NetworkHandler, | ||
) { | ||
|
||
suspend fun importMetaData(): MetadataDetails { | ||
logger?.i { "Importing Metadata" } | ||
networkHandler.getMetadata()?.let { | ||
logger?.i { "Found Metadata" } | ||
return Json.decodeFromString<MetadataDetails>(it) | ||
} | ||
|
||
logger?.i { "No Metadata Found" } | ||
return MetadataDetails(mutableListOf()) | ||
} | ||
|
||
suspend fun exportMetadata(metadata: MetadataDetails): Boolean { | ||
logger?.i { "Exporting Metadata" } | ||
try { | ||
val jsonString = Json.encodeToString(metadata) | ||
networkHandler.setMetadata(jsonString) | ||
} catch (e: Exception) { | ||
logger?.e(e) { "Error Exporting Metadata" } | ||
return false | ||
} | ||
|
||
logger?.i { "Successfully Exported Metadata" } | ||
return true | ||
} | ||
|
||
suspend fun readMetadataFromFile(filePath: String): MetadataFileDetails? { | ||
networkHandler.openImage(filePath)?.let { sharedImage -> | ||
val metadata = Kim.readMetadata(sharedImage.byteArray) | ||
println(metadata) | ||
|
||
val comments = metadata?.findStringValue(ExifTag.EXIF_TAG_USER_COMMENT) | ||
val keywords = comments?.split(",") ?: emptyList() | ||
|
||
val takenDate = metadata?.findStringValue(ExifTag.EXIF_TAG_DATE_TIME_ORIGINAL) | ||
println("Taken date: $takenDate") | ||
|
||
val photoMetadata = metadata?.convertToPhotoMetadata() | ||
photoMetadata?.orientation | ||
|
||
return MetadataFileDetails( | ||
filePath = filePath, | ||
tags = keywords.toSet() | ||
) | ||
} | ||
return null | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
...nMain/kotlin/com/kevinschildhorn/fotopresenter/domain/image/SaveMetadataForPathUseCase.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.kevinschildhorn.fotopresenter.domain.image | ||
|
||
import com.kevinschildhorn.fotopresenter.data.ImageSlideshowDetails | ||
import com.kevinschildhorn.fotopresenter.data.MetadataFileDetails | ||
import com.kevinschildhorn.fotopresenter.data.datasources.ImageMetadataDataSource | ||
import org.koin.core.component.KoinComponent | ||
|
||
class SaveMetadataForPathUseCase( | ||
private val dataSource: ImageMetadataDataSource, | ||
) : KoinComponent { | ||
|
||
suspend operator fun invoke( | ||
path: String, | ||
tags: String, | ||
): Boolean { | ||
val tagList: List<String> = tags.split(",").map { it.trim() } | ||
val metaData = dataSource.importMetaData() | ||
|
||
val fileMetadata = MetadataFileDetails( | ||
filePath = path, | ||
tags = tagList.toSet(), | ||
) | ||
|
||
metaData.files.removeIf { it.filePath == path } | ||
if (fileMetadata.tags.isNotEmpty()) metaData.files.add(fileMetadata) | ||
|
||
return dataSource.exportMetadata(metaData) | ||
} | ||
} |
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.