Improves types

* Adds missing properties to music album
* Changes gender from String to Enum
This commit is contained in:
Julien Lengrand-Lambert
2025-05-20 09:54:42 +02:00
parent f43d22b63b
commit f5143140a8
3 changed files with 42 additions and 18 deletions

View File

@@ -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<String>,
val section: String?,
val tags: List<String>
)
data class Profile(
val firstName: String?,
val lastName: String?,
val username: String?,
val gender: String?
)
data class Book(
val authors: List<String>,
val isbn: String?,
@@ -160,6 +164,13 @@ data class Book(
val tags: List<String>
)
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<String>,
val songDisc: Int?,
val songTrack: Int?,
val musician: List<String>,
val releaseDate: String?
)
data class MusicPlaylist(
val songs: List<String>,
val songDisc: Int?,
val songTrack: Int?,
val creator: String?
)

View File

@@ -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<String, List<Tag>>): 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
)
}
}
}

View File

@@ -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