Skip to content

Commit

Permalink
fixes to cli tool
Browse files Browse the repository at this point in the history
  • Loading branch information
llsc12 committed May 19, 2023
1 parent b7efdcb commit 5313a15
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"location" : "https://github.com/llsc12/Khinsider",
"state" : {
"branch" : "main",
"revision" : "c09ba134c14818bd2e4c51336e206deaeba5f6e1"
"revision" : "e13cd4a8806026051f5ecda7ee8f2ff835699533"
}
},
{
Expand Down
84 changes: 84 additions & 0 deletions KhinsiderDL.xcodeproj/xcshareddata/xcschemes/khinsider-dl.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AA2F2D9E29CD163C0094F38F"
BuildableName = "khinsider-dl"
BlueprintName = "khinsider-dl"
ReferencedContainer = "container:KhinsiderDL.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
viewDebuggingEnabled = "No">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AA2F2D9E29CD163C0094F38F"
BuildableName = "khinsider-dl"
BlueprintName = "khinsider-dl"
ReferencedContainer = "container:KhinsiderDL.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "https://downloads.khinsider.com/game-soundtracks/album/mario-party-7"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AA2F2D9E29CD163C0094F38F"
BuildableName = "khinsider-dl"
BlueprintName = "khinsider-dl"
ReferencedContainer = "container:KhinsiderDL.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict/>
<dict>
<key>AA2F2D9E29CD163C0094F38F</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
34 changes: 33 additions & 1 deletion KhinsiderDL/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,39 @@ struct KhinsiderDL: AsyncParsableCommand {
print("Searching for album...")
guard let album = try await Khinsider.album(from: url) else { throw ValidationError("Couldn't find album.") }
print("Found \(album.title), getting tracks...")
guard let sourceUrls = try await album.allSourceLinks(format) else { throw ValidationError("Couldn't get album download links.") }

let quality: Khinsider.KHAlbum.Format = await {
if
let formats = try? await album.availableFormats,
formats.contains(.flac)
{
print("Downloading as flac...")
return .flac
} else {
print("Flac not available, downloading as mp3...")
return .mp3
}
}()

let sourceUrls = await withTaskGroup(of: URL?.self) { group in
try? await album.tracks.forEach { track in
group.addTask {
print("Scraping \(track.title)")
return await track.getSourceLink(quality)
}
}

var collected = [URL]()

for await value in group {
if let value {
collected.append(value)
}
}

return collected
}

print("Downloading \(sourceUrls.count) tracks.")

sourceUrls.forEach { url in
Expand Down
3 changes: 2 additions & 1 deletion KhinsiderDLUI/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ struct ContentView: View {
{
quality = .flac
conPrint("Downloading as flac...")
} else { conPrint("Downloading as mp3...") }
} else { conPrint("Flac not available, downloading as mp3...") }
conPrint("Scraping all tracks... This might take a while.")
guard let links = try? await album.allSourceLinks(quality) else {
conPrint("[Fail] Failed to get tracks from album.")
isDownloading = false
Expand Down

0 comments on commit 5313a15

Please sign in to comment.