From a6e6879f2dc8aaeaef093c4aa9bfb77d7d4c3419 Mon Sep 17 00:00:00 2001 From: baegteun Date: Wed, 28 Aug 2024 20:09:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?:sparkles:=20::=20[#1248]=20=EB=8B=A8?= =?UTF-8?q?=EC=9D=BC=EA=B3=A1=20=EC=9E=AC=EC=83=9D=20=EC=8B=9C=20=EC=A0=9C?= =?UTF-8?q?=EB=AA=A9=EC=97=90=20Shorts=EB=A5=BC=20=EC=9D=98=EB=AF=B8?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=ED=85=8D=EC=8A=A4=ED=8A=B8=EA=B0=80=20?= =?UTF-8?q?=ED=8F=AC=ED=95=A8=EB=90=98=EC=96=B4=EC=9E=88=EC=9D=84=20?= =?UTF-8?q?=EC=8B=9CYoutube=EB=A1=9C=20=EC=9E=AC=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewControllers/HomeViewController.swift | 10 +++- .../MusicDetail/MusicDetailReactor.swift | 4 +- .../MusicDetailViewController.swift | 8 +-- .../MyPlaylistDetailViewController.swift | 10 +++- .../PlaylistViewController+Delegate.swift | 7 ++- .../Sources/Views/PlaylistTableViewCell.swift | 4 +- .../BeforeSearchContentViewController.swift | 1 + .../Sources/Reactors/LikeStorageReactor.swift | 5 +- .../Sources/Extensions/Extension+String.swift | 4 ++ .../Player/WakmusicYoutubePlayer.swift | 56 +++++++++++++------ 10 files changed, 78 insertions(+), 31 deletions(-) diff --git a/Projects/Features/HomeFeature/Sources/ViewControllers/HomeViewController.swift b/Projects/Features/HomeFeature/Sources/ViewControllers/HomeViewController.swift index 92bfdd693..86ccdc97b 100644 --- a/Projects/Features/HomeFeature/Sources/ViewControllers/HomeViewController.swift +++ b/Projects/Features/HomeFeature/Sources/ViewControllers/HomeViewController.swift @@ -420,7 +420,10 @@ extension HomeViewController: HomeChartCellDelegate { CommonAnalyticsLog.clickPlayButton(location: .home, type: .single) ) PlayState.shared.append(item: .init(id: model.id, title: model.title, artist: model.artist)) - WakmusicYoutubePlayer(id: model.id).play() + WakmusicYoutubePlayer( + id: model.id, + playPlatform: model.title.isContainShortsTagTitle ? .youtube : .automatic + ).play() } } @@ -438,7 +441,10 @@ extension HomeViewController: HomeNewSongCellDelegate { CommonAnalyticsLog.clickPlayButton(location: .home, type: .single) ) PlayState.shared.append(item: .init(id: model.id, title: model.title, artist: model.artist)) - WakmusicYoutubePlayer(id: model.id).play() + WakmusicYoutubePlayer( + id: model.id, + playPlatform: model.title.isContainShortsTagTitle ? .youtube : .automatic + ).play() } } diff --git a/Projects/Features/MusicDetailFeature/Sources/MusicDetail/MusicDetailReactor.swift b/Projects/Features/MusicDetailFeature/Sources/MusicDetail/MusicDetailReactor.swift index ac741c061..6dfdd4284 100644 --- a/Projects/Features/MusicDetailFeature/Sources/MusicDetail/MusicDetailReactor.swift +++ b/Projects/Features/MusicDetailFeature/Sources/MusicDetail/MusicDetailReactor.swift @@ -39,7 +39,7 @@ final class MusicDetailReactor: Reactor { } enum NavigateType { - case youtube(id: String) + case youtube(id: String, playPlatform: WakmusicYoutubePlayer.PlayPlatform) case credit(id: String) case lyricsHighlighting(model: LyricHighlightingRequiredModel) case musicPick(id: String) @@ -296,7 +296,7 @@ private extension MusicDetailReactor { LogManager.analytics(log) } PlayState.shared.append(item: PlaylistItem(id: song.videoID, title: song.title, artist: song.artistString)) - return navigateMutation(navigate: .youtube(id: song.videoID)) + return navigateMutation(navigate: .youtube(id: song.videoID, playPlatform: song.title.isContainShortsTagTitle ? .youtube : .automatic)) } func nextButtonDidTap() -> Observable { diff --git a/Projects/Features/MusicDetailFeature/Sources/MusicDetail/MusicDetailViewController.swift b/Projects/Features/MusicDetailFeature/Sources/MusicDetail/MusicDetailViewController.swift index 7a9dc4f98..57c4baac3 100644 --- a/Projects/Features/MusicDetailFeature/Sources/MusicDetail/MusicDetailViewController.swift +++ b/Projects/Features/MusicDetailFeature/Sources/MusicDetail/MusicDetailViewController.swift @@ -129,8 +129,8 @@ final class MusicDetailViewController: BaseReactorViewController Observable { let appendingPlaylisItem = PlaylistItem(id: song.songID, title: song.title, artist: song.artist) PlayState.shared.append(item: appendingPlaylisItem) - WakmusicYoutubePlayer(id: song.songID).play() + WakmusicYoutubePlayer( + id: song.songID, + playPlatform: song.title.isContainShortsTagTitle ? .youtube : .automatic + ).play() return .empty() } diff --git a/Projects/Modules/Utility/Sources/Extensions/Extension+String.swift b/Projects/Modules/Utility/Sources/Extensions/Extension+String.swift index 8aee481dd..992034871 100644 --- a/Projects/Modules/Utility/Sources/Extensions/Extension+String.swift +++ b/Projects/Modules/Utility/Sources/Extensions/Extension+String.swift @@ -60,4 +60,8 @@ public extension String { formatter.dateFormat = format return formatter.date(from: self) ?? .init() } + + var isContainShortsTagTitle: Bool { + return self.lowercased().contains("#Shorts".lowercased()) + } } diff --git a/Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift b/Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift index 483c1930c..197763adf 100644 --- a/Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift +++ b/Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift @@ -2,54 +2,59 @@ import Foundation import LinkPresentation import UIKit -private enum OpenerPlatform { - case youtube - case youtubeMusic -} +public struct WakmusicYoutubePlayer: WakmusicPlayer { + fileprivate enum OpenerPlatform { + case youtube + case youtubeMusic + } + private enum VideoPlayType { + case videos(ids: [String]) + case playlist(listID: String) + } -private enum VideoPlayType { - case videos(ids: [String]) - case playlist(listID: String) -} + public enum PlayPlatform { + case youtube + case youtubeMusic + case automatic + } -public struct WakmusicYoutubePlayer: WakmusicPlayer { private let youtubeURLGenerator: any YoutubeURLGeneratable private let youtubeVideoType: VideoPlayType private let title: String? - private var openerPlatform: OpenerPlatform { - let platform = PreferenceManager.songPlayPlatformType ?? .youtube - switch platform { - case .youtube: return .youtube - case .youtubeMusic: return .youtubeMusic - } - } + private let openerPlatform: OpenerPlatform public init( id: String, title: String? = nil, + playPlatform: PlayPlatform = .automatic, youtubeURLGenerator: any YoutubeURLGeneratable = YoutubeURLGenerator() ) { self.youtubeVideoType = .videos(ids: [id]) self.title = title + self.openerPlatform = playPlatform.toOpenerPlatform self.youtubeURLGenerator = youtubeURLGenerator } public init( ids: [String], title: String? = nil, + playPlatform: PlayPlatform = .automatic, youtubeURLGenerator: any YoutubeURLGeneratable = YoutubeURLGenerator() ) { self.youtubeVideoType = .videos(ids: ids) self.title = title + self.openerPlatform = playPlatform.toOpenerPlatform self.youtubeURLGenerator = youtubeURLGenerator } public init( listID: String, + playPlatform: PlayPlatform = .automatic, youtubeURLGenerator: any YoutubeURLGeneratable = YoutubeURLGenerator() ) { self.youtubeVideoType = .playlist(listID: listID) self.title = nil + self.openerPlatform = playPlatform.toOpenerPlatform self.youtubeURLGenerator = youtubeURLGenerator } @@ -197,3 +202,22 @@ private extension URL { return components.url } } + +private extension WakmusicYoutubePlayer.PlayPlatform { + var toOpenerPlatform: WakmusicYoutubePlayer.OpenerPlatform { + switch self { + case .youtube: return .youtube + case .youtubeMusic: return .youtubeMusic + case .automatic: return PreferenceManager.songPlayPlatformType?.toOpnerPlatform ?? .youtube + } + } +} + +private extension YoutubePlayType { + var toOpnerPlatform: WakmusicYoutubePlayer.OpenerPlatform { + switch self { + case .youtube: return .youtube + case .youtubeMusic: return .youtubeMusic + } + } +} From 540724563b1445722f097b6cb90a392ef388bf80 Mon Sep 17 00:00:00 2001 From: baegteun Date: Wed, 28 Aug 2024 20:09:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8E=A8=20::=20=EC=BD=94=EB=93=9C=20Fo?= =?UTF-8?q?rmatting=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/MusicDetail/MusicDetailReactor.swift | 5 ++++- .../Utility/Sources/Player/WakmusicYoutubePlayer.swift | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Projects/Features/MusicDetailFeature/Sources/MusicDetail/MusicDetailReactor.swift b/Projects/Features/MusicDetailFeature/Sources/MusicDetail/MusicDetailReactor.swift index 6dfdd4284..415ea24dd 100644 --- a/Projects/Features/MusicDetailFeature/Sources/MusicDetail/MusicDetailReactor.swift +++ b/Projects/Features/MusicDetailFeature/Sources/MusicDetail/MusicDetailReactor.swift @@ -296,7 +296,10 @@ private extension MusicDetailReactor { LogManager.analytics(log) } PlayState.shared.append(item: PlaylistItem(id: song.videoID, title: song.title, artist: song.artistString)) - return navigateMutation(navigate: .youtube(id: song.videoID, playPlatform: song.title.isContainShortsTagTitle ? .youtube : .automatic)) + return navigateMutation(navigate: .youtube( + id: song.videoID, + playPlatform: song.title.isContainShortsTagTitle ? .youtube : .automatic + )) } func nextButtonDidTap() -> Observable { diff --git a/Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift b/Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift index 197763adf..bbe42c8d2 100644 --- a/Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift +++ b/Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift @@ -7,6 +7,7 @@ public struct WakmusicYoutubePlayer: WakmusicPlayer { case youtube case youtubeMusic } + private enum VideoPlayType { case videos(ids: [String]) case playlist(listID: String)