mirror of
https://github.com/yattee/yattee.git
synced 2026-10-30 08:27:17 +00:00
Open more YouTube link types and playlists from links
Route YouTube search results links to search and nocookie embeds to the video, match YouTube hosts exactly, and report YouTube pages without a video as unsupported instead of sending them to yt-dlp. A watch link inside a playlist shows both the video and the playlist when loaded, and plays the video with the playlist queued around it. URL scheme play, queue and bookmark actions accept playlist links.
This commit is contained in:
@@ -24,6 +24,30 @@ extension DataManager {
|
||||
return playlist
|
||||
}
|
||||
|
||||
/// A title no local playlist has yet: the base, else "Base (2)", "Base (3)"…
|
||||
func uniquePlaylistTitle(_ baseTitle: String) -> String {
|
||||
let existingTitles = Set(playlists().map(\.title))
|
||||
guard existingTitles.contains(baseTitle) else { return baseTitle }
|
||||
var counter = 2
|
||||
while existingTitles.contains("\(baseTitle) (\(counter))") {
|
||||
counter += 1
|
||||
}
|
||||
return "\(baseTitle) (\(counter))"
|
||||
}
|
||||
|
||||
/// Saves a remote playlist's videos as a new local playlist.
|
||||
@discardableResult
|
||||
func importPlaylist(_ playlist: Playlist) -> LocalPlaylist {
|
||||
let localPlaylist = createPlaylist(
|
||||
title: uniquePlaylistTitle(playlist.title),
|
||||
description: playlist.description
|
||||
)
|
||||
for video in playlist.videos {
|
||||
addToPlaylist(video, playlist: localPlaylist)
|
||||
}
|
||||
return localPlaylist
|
||||
}
|
||||
|
||||
/// Updates a playlist's title and description.
|
||||
func updatePlaylist(_ playlist: LocalPlaylist, title: String, description: String?) {
|
||||
playlist.title = title
|
||||
|
||||
Reference in New Issue
Block a user