feat: Playlist-Links im Jam (Feld und Teilen) (1.5.0)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -88,6 +88,28 @@ object JamSync {
|
||||
return id?.takeIf { VIDEO_ID.matches(it) }
|
||||
}
|
||||
|
||||
private val PLAYLIST_ID = Regex("^(PL|OLAK5uy_|RD|LL|UU|FL|OL|LM)[A-Za-z0-9_-]{0,80}$")
|
||||
|
||||
/** Playlist-/Album-ID aus einer ID oder einem Link mit `list=`, sonst null. */
|
||||
fun parsePlaylistId(input: String?): String? {
|
||||
val text = input?.trim() ?: return null
|
||||
val raw = if (text.contains("youtube.com") || text.contains("youtu.be") || text.contains("://")) {
|
||||
val rest = text.substringAfter("://", text)
|
||||
val host = rest.substringBefore('/').lowercase().removePrefix("www.").removePrefix("m.").removePrefix("music.")
|
||||
if (host != "youtube.com" && host != "youtu.be") return null
|
||||
rest.substringAfter('?', "").substringBefore('#').split('&')
|
||||
.firstOrNull { it.startsWith("list=") }?.removePrefix("list=") ?: return null
|
||||
} else text
|
||||
val id = raw.removePrefix("VL")
|
||||
return id.takeIf { PLAYLIST_ID.matches(it) }
|
||||
}
|
||||
|
||||
/** Playlist-Link (ohne einzelnes Video) aus einem geteilten Text. */
|
||||
fun playlistIdFromSharedText(text: String?): String? =
|
||||
text?.split(Regex("\\s+"))?.firstNotNullOfOrNull { word ->
|
||||
if (parseVideoId(word) == null) parsePlaylistId(word) else null
|
||||
}
|
||||
|
||||
/** Sucht in einem geteilten Text (z. B. aus der YouTube-App) den ersten YouTube-Link. */
|
||||
fun videoIdFromSharedText(text: String?): String? =
|
||||
text?.split(Regex("\\s+"))?.firstNotNullOfOrNull { parseVideoId(it) }
|
||||
|
||||
Reference in New Issue
Block a user