Skip to content

Commit

Permalink
Merge pull request #1249 from wakmusic/1248-youtube-force-open-when-s…
Browse files Browse the repository at this point in the history
…ingle-song-play

🔀 :: (#1248) 단일곡 재생 시 제목에 Shorts를 의미하는 텍스트가 포함되어있을 시Youtube로 재생
  • Loading branch information
baekteun authored Aug 28, 2024
2 parents d9105f6 + 5407245 commit 916fcd2
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand All @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<Mutation> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ final class MusicDetailViewController: BaseReactorViewController<MusicDetailReac
sharedState.compactMap(\.navigateType)
.bind(with: self) { owner, navigate in
switch navigate {
case let .youtube(id):
owner.openYoutube(id: id)
case let .youtube(id, playPlatform):
owner.openYoutube(id: id, playPlatform: playPlatform)
case let .credit(id):
owner.navigateCredits(id: id)
case let .lyricsHighlighting(model):
Expand Down Expand Up @@ -218,8 +218,8 @@ final class MusicDetailViewController: BaseReactorViewController<MusicDetailReac
}

private extension MusicDetailViewController {
func openYoutube(id: String) {
WakmusicYoutubePlayer(id: id).play()
func openYoutube(id: String, playPlatform: WakmusicYoutubePlayer.PlayPlatform = .automatic) {
WakmusicYoutubePlayer(id: id, playPlatform: playPlatform).play()
}

func navigateCredits(id: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,14 @@ extension MyPlaylistDetailViewController: PlayButtonGroupViewDelegate {

/// 편집모드 시 셀 선택 이벤트
extension MyPlaylistDetailViewController: PlaylistTableViewCellDelegate {
func playButtonDidTap(key: String) {
WakmusicYoutubePlayer(id: key).play()
func playButtonDidTap(model: PlaylistItemModel) {
LogManager.analytics(
CommonAnalyticsLog.clickPlayButton(location: .playlist, type: .single)
)
WakmusicYoutubePlayer(
id: model.id,
playPlatform: model.title.isContainShortsTagTitle ? .youtube : .automatic
).play()
}

func superButtonTapped(index: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,14 @@ extension PlaylistViewController: UITableViewDelegate {
}

extension PlaylistViewController: PlaylistTableViewCellDelegate {
func playButtonDidTap(key: String) {
func playButtonDidTap(model: PlaylistItemModel) {
LogManager.analytics(
CommonAnalyticsLog.clickPlayButton(location: .playlist, type: .single)
)
WakmusicYoutubePlayer(id: key).play()
WakmusicYoutubePlayer(
id: model.id,
playPlatform: model.title.isContainShortsTagTitle ? .youtube : .automatic
).play()
}

func superButtonTapped(index: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Utility

internal protocol PlaylistTableViewCellDelegate: AnyObject {
func superButtonTapped(index: Int)
func playButtonDidTap(key: String)
func playButtonDidTap(model: PlaylistItemModel)
}

internal class PlaylistTableViewCell: UITableViewCell {
Expand Down Expand Up @@ -148,7 +148,7 @@ extension PlaylistTableViewCell {
return
}

owner.delegate?.playButtonDidTap(key: song.id)
owner.delegate?.playButtonDidTap(model: song)
}
.disposed(by: disposeBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ extension BeforeSearchContentViewController: UICollectionViewDelegate {

switch model {
case let .youtube(model: model):
// 주간 왁뮤
WakmusicYoutubePlayer(id: model.id).play()
LogManager.analytics(SearchAnalyticsLog.clickLatestWakmuYoutubeVideo)
case let .recommend(model: model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ extension LikeStorageReactor {
func playWithAddToCurrentPlaylist(song: FavoriteSongEntity) -> Observable<Mutation> {
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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
57 changes: 41 additions & 16 deletions Projects/Modules/Utility/Sources/Player/WakmusicYoutubePlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
}
}

0 comments on commit 916fcd2

Please sign in to comment.