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..415ea24dd 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,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)) + 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..bbe42c8d2 100644 --- a/Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift +++ b/Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift @@ -2,54 +2,60 @@ 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 +203,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 + } + } +}