Skip to content

Commit

Permalink
๐ŸŽจ :: ์ฝ”๋“œ Formatting ์ ์šฉ
Browse files Browse the repository at this point in the history
  • Loading branch information
baekteun committed Aug 27, 2024
1 parent 155e0be commit 2b6dece
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: // ๋ฏธ์‚ฌ์šฉ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

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

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

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

0 comments on commit 2b6dece

Please sign in to comment.