From 2b6decef0b048e0196cf58ce7e0ad1868900a714 Mon Sep 17 00:00:00 2001 From: baegteun Date: Tue, 27 Aug 2024 10:36:19 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20::=20=EC=BD=94=EB=93=9C=20Format?= =?UTF-8?q?ting=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArtistMusicContentViewController.swift | 2 +- .../NewSongsContentViewController.swift | 8 +- ...WakmusicPlaylistDetailViewController.swift | 8 +- .../Player/WakmusicYoutubePlayer.swift | 97 +++++++++---------- 4 files changed, 57 insertions(+), 58 deletions(-) diff --git a/Projects/Features/ArtistFeature/Sources/ViewControllers/ArtistMusicContentViewController.swift b/Projects/Features/ArtistFeature/Sources/ViewControllers/ArtistMusicContentViewController.swift index dd1b3a2d4..8ed336be1 100644 --- a/Projects/Features/ArtistFeature/Sources/ViewControllers/ArtistMusicContentViewController.swift +++ b/Projects/Features/ArtistFeature/Sources/ViewControllers/ArtistMusicContentViewController.swift @@ -324,7 +324,7 @@ extension ArtistMusicContentViewController: PlayButtonGroupViewDelegate { PlayState.shared.loadAndAppendSongsToPlaylist(songs) if let components = URLComponents(url: url, resolvingAgainstBaseURL: false), let listID = components.queryItems?.first(where: { $0.name == "list" })?.value { - WakmusicYoutubePlayer(listID: listID).play() + WakmusicYoutubePlayer(listID: listID).play() } case .shufflePlay: // 미사용 diff --git a/Projects/Features/HomeFeature/Sources/ViewControllers/NewSongsContentViewController.swift b/Projects/Features/HomeFeature/Sources/ViewControllers/NewSongsContentViewController.swift index f011e5553..22ca9f883 100644 --- a/Projects/Features/HomeFeature/Sources/ViewControllers/NewSongsContentViewController.swift +++ b/Projects/Features/HomeFeature/Sources/ViewControllers/NewSongsContentViewController.swift @@ -251,10 +251,10 @@ extension NewSongsContentViewController: SingleActionButtonViewDelegate { output.showToast.onNext("해당 기능은 준비 중입니다.") return } - if let components = URLComponents(url: url, resolvingAgainstBaseURL: false), - let listID = components.queryItems?.first(where: { $0.name == "list" })?.value { - WakmusicYoutubePlayer(listID: listID).play() - } + if let components = URLComponents(url: url, resolvingAgainstBaseURL: false), + let listID = components.queryItems?.first(where: { $0.name == "list" })?.value { + WakmusicYoutubePlayer(listID: listID).play() + } let songs: [SongEntity] = output.dataSource.value.map { return SongEntity( diff --git a/Projects/Features/PlaylistFeature/Sources/ViewControllers/WakmusicPlaylistDetailViewController.swift b/Projects/Features/PlaylistFeature/Sources/ViewControllers/WakmusicPlaylistDetailViewController.swift index a8bdb8796..cdd7fa408 100644 --- a/Projects/Features/PlaylistFeature/Sources/ViewControllers/WakmusicPlaylistDetailViewController.swift +++ b/Projects/Features/PlaylistFeature/Sources/ViewControllers/WakmusicPlaylistDetailViewController.swift @@ -318,10 +318,10 @@ extension WakmusicPlaylistDetailViewController: SingleActionButtonViewDelegate { LogManager.analytics(PlaylistAnalyticsLog.clickPlaylistPlayButton(type: "all", key: reactor?.key ?? "")) PlayState.shared.append(contentsOf: songs.map { PlaylistItem(item: $0) }) - if let components = URLComponents(url: url, resolvingAgainstBaseURL: false), - let listID = components.queryItems?.first(where: { $0.name == "list" })?.value { - WakmusicYoutubePlayer(listID: listID).play() - } + if let components = URLComponents(url: url, resolvingAgainstBaseURL: false), + let listID = components.queryItems?.first(where: { $0.name == "list" })?.value { + WakmusicYoutubePlayer(listID: listID).play() + } } } diff --git a/Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift b/Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift index 034ce58e0..518bb13e9 100644 --- a/Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift +++ b/Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift @@ -8,8 +8,8 @@ private enum OpenerPlatform { } private enum VideoPlayType { - case videos(ids: [String]) - case playlist(listID: String) + case videos(ids: [String]) + case playlist(listID: String) } public struct WakmusicYoutubePlayer: WakmusicPlayer { @@ -39,21 +39,21 @@ public struct WakmusicYoutubePlayer: WakmusicPlayer { self.youtubeURLGenerator = youtubeURLGenerator } - public init( - listID: String, - youtubeURLGenerator: any YoutubeURLGeneratable = YoutubeURLGenerator() - ) { - self.youtubeVideoType = .playlist(listID: listID) - self.youtubeURLGenerator = youtubeURLGenerator - } + public init( + listID: String, + youtubeURLGenerator: any YoutubeURLGeneratable = YoutubeURLGenerator() + ) { + self.youtubeVideoType = .playlist(listID: listID) + self.youtubeURLGenerator = youtubeURLGenerator + } public func play() { - switch youtubeVideoType { - case let .videos(ids): - playYoutube(ids: ids) - case let .playlist(listID): - playPlaylistYoutube(listID: listID) - } + switch youtubeVideoType { + case let .videos(ids): + playYoutube(ids: ids) + case let .playlist(listID): + playPlaylistYoutube(listID: listID) + } } } @@ -68,10 +68,10 @@ private extension WakmusicYoutubePlayer { } func playPlaylistYoutube(listID: String) { - guard let url = urlForYoutubePlaylist(listID: listID) else { - return - } - UIApplication.shared.open(url) + guard let url = urlForYoutubePlaylist(listID: listID) else { + return + } + UIApplication.shared.open(url) } } @@ -146,37 +146,36 @@ private extension WakmusicYoutubePlayer { private extension WakmusicYoutubePlayer { func urlForYoutubePlaylist(listID: String) -> URL? { - switch openerPlatform { - case .youtube: - let appURL = openableURL(youtubeURLGenerator.generateYoutubePlaylistAppURL(id: listID)) - let webURL = openableURL(youtubeURLGenerator.generateYoutubePlaylistWebURL(id: listID)) - return appURL ?? webURL - - - case .youtubeMusic: - let appURL = openableURL(youtubeURLGenerator.generateYoutubeMusicPlaylistAppURL(id: listID)) - let webURL = openableURL(youtubeURLGenerator.generateYoutubeMusicPlaylistWebURL(id: listID)) - return appURL ?? webURL - } - } + switch openerPlatform { + case .youtube: + let appURL = openableURL(youtubeURLGenerator.generateYoutubePlaylistAppURL(id: listID)) + let webURL = openableURL(youtubeURLGenerator.generateYoutubePlaylistWebURL(id: listID)) + return appURL ?? webURL + + case .youtubeMusic: + let appURL = openableURL(youtubeURLGenerator.generateYoutubeMusicPlaylistAppURL(id: listID)) + let webURL = openableURL(youtubeURLGenerator.generateYoutubeMusicPlaylistWebURL(id: listID)) + return appURL ?? webURL + } + } } private extension WakmusicYoutubePlayer { - func openableURL(_ urlString: String) -> URL? { - guard let url = URL(string: urlString), UIApplication.shared.canOpenURL(url) else { return nil } - return url - } - - @MainActor - func redirectedYoutubeURL(_ urlString: String) async throws -> URL? { - guard let url = URL(string: urlString) else { return nil } - - let provider = LPMetadataProvider() - let metadata = try await provider.startFetchingMetadata(for: url) - guard let redirectedURL = metadata.url, - UIApplication.shared.canOpenURL(redirectedURL) - else { return nil } - - return redirectedURL - } + func openableURL(_ urlString: String) -> URL? { + guard let url = URL(string: urlString), UIApplication.shared.canOpenURL(url) else { return nil } + return url + } + + @MainActor + func redirectedYoutubeURL(_ urlString: String) async throws -> URL? { + guard let url = URL(string: urlString) else { return nil } + + let provider = LPMetadataProvider() + let metadata = try await provider.startFetchingMetadata(for: url) + guard let redirectedURL = metadata.url, + UIApplication.shared.canOpenURL(redirectedURL) + else { return nil } + + return redirectedURL + } }