diff --git a/Sources/WWDCHelper/main.swift b/Sources/WWDCHelper/main.swift index 1dca0d7..7ec2ea4 100644 --- a/Sources/WWDCHelper/main.swift +++ b/Sources/WWDCHelper/main.swift @@ -11,7 +11,7 @@ import CommandLineKit import Rainbow import WWDCHelperKit -let appVersion = "v1.0.0" +let appVersion = "v1.1.0" let cli = CommandLineKit.CommandLine() cli.formatOutput = { s, type in @@ -30,51 +30,51 @@ cli.formatOutput = { s, type in return cli.defaultFormat(s: str, type: type) } -let yearOption = StringOption(shortFlag: "y", longFlag: "year", - helpMessage: "Setup the year of WWDC. Support ALL WWDCs from `2012` to `2018` now! Default is WWDC 2018.") -let sessionIDsOption = MultiStringOption(shortFlag: "s", longFlag: "sessions", - helpMessage: "Setup the session numbers in WWDC. Default is all sessions.") -let subtitleLanguageOption = StringOption(shortFlag: "l", longFlag: "language", - helpMessage: "Setup the language of subtitle. Support `chs`, `eng`, and `jpn` (only WWDC 2018) now! Default is Simplified Chinese.") -let isSubtitleForSDVideoOption = BoolOption(longFlag: "sd", - helpMessage: "Add sd tag for subtitle\'s filename. Default is for hd videos.") -let subtitlePathOption = StringOption(shortFlag: "p", longFlag: "path", - helpMessage: "Setup the download path of subtitles. Default is current folder.") -let helpOption = BoolOption(shortFlag: "h", longFlag: "help", - helpMessage: "Print the help info.") -let versionOption = BoolOption(shortFlag: "v", longFlag: "version", - helpMessage: "Print the version info.") - -cli.addOptions(yearOption, - sessionIDsOption, - subtitleLanguageOption, - isSubtitleForSDVideoOption, - subtitlePathOption, - helpOption, - versionOption) - -do { - try cli.parse() -} catch { - cli.printUsage(error) - exit(EX_USAGE) -} - -if helpOption.value { - cli.printUsage() - exit(EX_OK) -} - -if versionOption.value { - print(appVersion) - exit(EX_OK); -} - -let year = yearOption.value -let sessionIDs = sessionIDsOption.value -let subtitleLanguage = subtitleLanguageOption.value?.lowercased() -let subtitlePath = subtitlePathOption.value -let isSubtitleForSDVideo = isSubtitleForSDVideoOption.value +//let yearOption = StringOption(shortFlag: "y", longFlag: "year", +// helpMessage: "Setup the year of WWDC. Support ALL WWDCs from `2012` to `2019` now! Default is WWDC 2019.") +//let sessionIDsOption = MultiStringOption(shortFlag: "s", longFlag: "sessions", +// helpMessage: "Setup the session numbers in WWDC. Default is all sessions.") +//let subtitleLanguageOption = StringOption(shortFlag: "l", longFlag: "language", +// helpMessage: "Setup the language of subtitle. Support `chs`, `eng`, and `jpn` (only WWDC 2018 & 2019) now! Default is Simplified Chinese.") +//let isSubtitleForSDVideoOption = BoolOption(longFlag: "sd", +// helpMessage: "Add sd tag for subtitle\'s filename. Default is for hd videos.") +//let subtitlePathOption = StringOption(shortFlag: "p", longFlag: "path", +// helpMessage: "Setup the download path of subtitles. Default is current folder.") +//let helpOption = BoolOption(shortFlag: "h", longFlag: "help", +// helpMessage: "Print the help info.") +//let versionOption = BoolOption(shortFlag: "v", longFlag: "version", +// helpMessage: "Print the version info.") +// +//cli.addOptions(yearOption, +// sessionIDsOption, +// subtitleLanguageOption, +// isSubtitleForSDVideoOption, +// subtitlePathOption, +// helpOption, +// versionOption) +// +//do { +// try cli.parse() +//} catch { +// cli.printUsage(error) +// exit(EX_USAGE) +//} +// +//if helpOption.value { +// cli.printUsage() +// exit(EX_OK) +//} +// +//if versionOption.value { +// print(appVersion) +// exit(EX_OK); +//} +// +let year: String? = "2019" // yearOption.value +let sessionIDs = ["808"]// sessionIDsOption.value +let subtitleLanguage: String? = "jpn" // subtitleLanguageOption.value?.lowercased() +let subtitlePath: String? = nil //subtitlePathOption.value +let isSubtitleForSDVideo = false//isSubtitleForSDVideoOption.value var helper = WWDCHelper(year: year, sessionIDs: sessionIDs, @@ -95,9 +95,9 @@ do { switch err { case .unknownYear: - print("\(year!) hasn't been supported currently. Now support WWDC 2012 ~ WWDC 2018 same as developer official website.".red.bold) + print("\(year!) hasn't been supported currently. Now support WWDC 2012 ~ WWDC 2019 same as developer official website.".red.bold) case .unknownSubtitleLanguage: - print("Language \(subtitleLanguage!) is NOT supported for now, WWDC support Simpliefied Chinese, Japanese (for WWDC 2018) and English.".red.bold) + print("Language \(subtitleLanguage!) is NOT supported for now, WWDC support Simpliefied Chinese, Japanese (for WWDC 2018 & 2019) and English.".red.bold) case .unknownSessionID: print("Session ID was not found, please check it.".red.bold) case .subtitlePathNotExist: diff --git a/Sources/WWDCHelperKit/WWDCHelper.swift b/Sources/WWDCHelperKit/WWDCHelper.swift index aa0b2b2..e5819e8 100644 --- a/Sources/WWDCHelperKit/WWDCHelper.swift +++ b/Sources/WWDCHelperKit/WWDCHelper.swift @@ -24,7 +24,7 @@ public enum WWDCYear: String { init(_ value: String?) { guard let value = value else { - self = .wwdc2018 + self = .wwdc2019 return } @@ -164,12 +164,17 @@ extension WWDCHelper { } let strArr = content.flatMap { $0.map { $0 } } - guard let result = srtHelper.parse(strArr), - let data = result.data(using: .utf8) else { return } - - print(filename, "is downloading...") - - try data.write(to: path.url) + if strArr.isEmpty { + // Apple maybe upload empty content... + print("\(filename) downloaded error.".red.bold) + } else { + guard let result = srtHelper.parse(strArr), + let data = result.data(using: .utf8) else { return } + + print(filename, "is downloading...") + + try data.write(to: path.url) + } } print("Download successfully.".green.bold) }