added some logging commands and --verbose option

This commit is contained in:
a. fox 2024-02-20 14:58:47 -05:00
parent 6abcaf82c2
commit ad83c15e9c
7 changed files with 45 additions and 2 deletions

View File

@ -27,6 +27,15 @@
"version" : "1.3.0"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log",
"state" : {
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5",
"version" : "1.5.4"
}
},
{
"identity" : "urlqueryencoder",
"kind" : "remoteSourceControl",

View File

@ -14,6 +14,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"),
.package(url: "https://github.com/jellyfin/jellyfin-sdk-swift", from: "0.3.2"),
.package(url: "https://github.com/apple/swift-log", from: "1.5.4"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
@ -23,6 +24,7 @@ let package = Package(
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "JellyfinAPI", package: "jellyfin-sdk-swift"),
.product(name: "Logging", package: "swift-log"),
],
path: "Sources"
),

View File

@ -2,6 +2,17 @@
A utility to download media from Jellyfin Servers
## TODO
- remove references to JellyfinAPI library
- this doesn't compile on linux (and im assuming windows, too) and I would very much like to ship for those platforms.
- implement season downloading
- i think at the moment i have some basic code that will read in this value but doesn't actually do anything with it?
- remove percent encoding before creating file/directory names
- support QuickConnect
- idk if JellyfinAPI library supports that or not but I couldn't find the API endpoint when I was searching. 🤷
- add option for verbose output
## Usage
1. First, log in to your server: `$ ./seanut login -d your.jellyfin.server --username TestUser`

View File

@ -29,6 +29,7 @@ extension Seanut {
]
func createDirectory(_ path: String) {
Seanut.Logger?.info("Creating output directory \(output)...")
do {
try FileManager.default.createDirectory(
atPath: path.expandingTildeInPath.removingPercentEncoding!,
@ -55,6 +56,8 @@ extension Seanut {
return
}
Seanut.Logger?.info("Fetching children for \(rootInfo.name!)...")
for child in childInfo.items! {
await downloadRoot(id: child.id!, outputPath: newPath)
}
@ -63,6 +66,8 @@ extension Seanut {
let pathUrl = URL(string: rootInfo.path!)!
let itemName: String = rootInfo.name! + "." + pathUrl.pathExtension
let filePath = outputPath.appendingPathComponent(itemName.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!)
Seanut.Logger?.info("Downloading \(rootInfo.name!)...")
await downloadItem(id: id, outputPath: filePath)
}
}
@ -78,6 +83,8 @@ extension Seanut {
}
mutating func run() async {
Seanut.maybeSetLogger(options)
// checks if our specified output directory exists,
// if it doesn't then we create it before continuing
if !FileManager.default.fileExists(atPath: output.expandingTildeInPath) {

View File

@ -20,6 +20,8 @@ extension Seanut {
var password: String?
mutating func run() async {
Seanut.maybeSetLogger(options)
let seanutCacheFolder = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".seanut/")
if !FileManager.default.fileExists(atPath: seanutCacheFolder.absoluteString) {
do {

View File

@ -19,6 +19,7 @@ extension Seanut {
static let columnWidth = 40
mutating func run() async {
Seanut.maybeSetLogger(options)
let client = JellyfinClient(
configuration: Seanut.generateJellyfinConfiguration(url: options.domain.toURL()!),

View File

@ -5,6 +5,7 @@ import Foundation
import ArgumentParser
import JellyfinAPI
import CryptoKit
import Logging
let SeanutVersion = "0.0.1"
@ -16,9 +17,18 @@ struct Seanut: AsyncParsableCommand {
defaultSubcommand: SearchCommand.self
)
static var Logger: Logger? = nil
struct CommonArguments: ParsableArguments {
@Option(name: .shortAndLong, help: "jellyfin server domain name")
var domain: String
@Flag(name: .long, help: "prints extra information to the console")
var verbose = false
}
static func maybeSetLogger(_ opts: CommonArguments) {
Seanut.Logger = opts.verbose ? Logging.Logger(label: "garden.focks.SeanutSwift.logger") : nil
}
static func generateJellyfinConfiguration(url: URL) -> JellyfinClient.Configuration {
@ -49,9 +59,10 @@ struct Seanut: AsyncParsableCommand {
.appendingPathComponent(".seanut/\(domain)")
try auth.accessToken!.write(to: fileName, atomically: false, encoding: .utf8)
print("Access token retrieved and saved to ~/.seanut/\(domain)")
print("Access token retrieved ☑️")
} catch {
fatalError("failed to login with provided credentials. please try again.")
print("Failed to login with provided credentials. please try again later.")
exit(withError: error)
}
}