diff --git a/opengraphkt/src/main/kotlin/fr/lengrand/opengraphkt/Models.kt b/opengraphkt/src/main/kotlin/fr/lengrand/opengraphkt/Models.kt index 257acf4..dfdb686 100644 --- a/opengraphkt/src/main/kotlin/fr/lengrand/opengraphkt/Models.kt +++ b/opengraphkt/src/main/kotlin/fr/lengrand/opengraphkt/Models.kt @@ -46,6 +46,21 @@ enum class Type { } } +enum class Gender { + MALE, + FEMALE; + + companion object { + fun fromString(gender: String): Gender { + return valueOf(gender.uppercase()) + } + } + + override fun toString(): String { + return this.toString().lowercase() + } +} + data class Tag( val property: String, val content: String, @@ -133,26 +148,15 @@ data class Audio( val type: String? ) -/** - * * video.tv_show - same as video.movie - * * video.other - same as video.movie - */ data class Article( val publishedTime: String?, val modifiedTime: String?, val expirationTime: String?, - val section: String?, val authors: List, + val section: String?, val tags: List ) -data class Profile( - val firstName: String?, - val lastName: String?, - val username: String?, - val gender: String? -) - data class Book( val authors: List, val isbn: String?, @@ -160,6 +164,13 @@ data class Book( val tags: List ) +data class Profile( + val firstName: String?, + val lastName: String?, + val username: String?, + val gender: Gender? +) + data class MusicSong( val duration: Int?, val album: String?, @@ -170,12 +181,16 @@ data class MusicSong( data class MusicAlbum( val songs: List, + val songDisc: Int?, + val songTrack: Int?, val musician: List, val releaseDate: String? ) data class MusicPlaylist( val songs: List, + val songDisc: Int?, + val songTrack: Int?, val creator: String? ) diff --git a/opengraphkt/src/main/kotlin/fr/lengrand/opengraphkt/Parser.kt b/opengraphkt/src/main/kotlin/fr/lengrand/opengraphkt/Parser.kt index 91c5bfa..d77784e 100644 --- a/opengraphkt/src/main/kotlin/fr/lengrand/opengraphkt/Parser.kt +++ b/opengraphkt/src/main/kotlin/fr/lengrand/opengraphkt/Parser.kt @@ -350,7 +350,7 @@ class Parser { * Builds an Profile object from profile-related tags. * * @param groupedTags The map of grouped Tag objects - * @return An Profile object, or null if no profile tags are found + * @return A Profile object, or null if no profile tags are found */ private fun buildProfile(groupedTags: Map>): Profile? { val profileTags = groupedTags.getOrDefault("profile", emptyList()) @@ -362,7 +362,8 @@ class Parser { val firstName = profileTags.firstOrNull { it.property == "profile:first_name" }?.content val lastName = profileTags.firstOrNull { it.property == "profile:last_name" }?.content val username = profileTags.firstOrNull { it.property == "profile:username" }?.content - val gender = profileTags.firstOrNull { it.property == "profile:gender" }?.content + val genderString = profileTags.firstOrNull { it.property == "profile:gender" }?.content + val gender = if(genderString != null) Gender.fromString(genderString) else null return Profile( firstName = firstName, @@ -440,18 +441,22 @@ class Parser { } val songs = musicTags.filter { it.property == "music:song" }.map { it.content } + val songDisc = musicTags.firstOrNull { it.property == "music:song:disc" }?.content?.toIntOrNull() + val songTrack = musicTags.firstOrNull { it.property == "music:song:track" }?.content?.toIntOrNull() val musicians = musicTags.filter { it.property == "music:musician" }.map { it.content } val releaseDate = musicTags.firstOrNull { it.property == "music:release_date" }?.content return MusicAlbum( songs = songs, + songDisc = songDisc, + songTrack = songTrack, musician = musicians, releaseDate = releaseDate ) } /** - * Builds an MusicPlaylist object from music.playlist-related tags. + * Builds a MusicPlaylist object from music.playlist-related tags. * * @param groupedTags The map of grouped Tag objects * @return An MusicPlaylist object, or null if no music.playlist tags are found @@ -464,16 +469,20 @@ class Parser { } val songs = musicTags.filter { it.property == "music:song" }.map { it.content } + val songDisc = musicTags.firstOrNull { it.property == "music:song:disc" }?.content?.toIntOrNull() + val songTrack = musicTags.firstOrNull { it.property == "music:song:track" }?.content?.toIntOrNull() val creator = musicTags.firstOrNull { it.property == "music:creator" }?.content return MusicPlaylist( songs = songs, + songDisc = songDisc, + songTrack = songTrack, creator = creator ) } /** - * Builds an MusicRadioStation object from music.radio_station-related tags. + * Builds a MusicRadioStation object from music.radio_station-related tags. * * @param groupedTags The map of grouped Tag objects * @return An MusicRadioStation object, or null if no music.radio_station tags are found @@ -553,4 +562,4 @@ class Parser { series = series ) } -} \ No newline at end of file +} diff --git a/opengraphkt/src/test/kotlin/fr/lengrand/opengraphkt/ParserTest.kt b/opengraphkt/src/test/kotlin/fr/lengrand/opengraphkt/ParserTest.kt index 31f3bab..b068522 100644 --- a/opengraphkt/src/test/kotlin/fr/lengrand/opengraphkt/ParserTest.kt +++ b/opengraphkt/src/test/kotlin/fr/lengrand/opengraphkt/ParserTest.kt @@ -229,7 +229,7 @@ class ParserTest { assertEquals("John", openGraphData.profile.firstName) assertEquals("Doe", openGraphData.profile.lastName) assertEquals("johndoe", openGraphData.profile.username) - assertEquals("male", openGraphData.profile.gender) + assertEquals(Gender.MALE, openGraphData.profile.gender) } @Test