Skip to content

Commit

Permalink
Merge pull request #21 from kingcos/dev
Browse files Browse the repository at this point in the history
Support WWDC 2019 & bugs fixed
  • Loading branch information
kingcos authored Aug 22, 2019
2 parents 22598ec + 9f08601 commit 5312e3f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 55 deletions.
96 changes: 48 additions & 48 deletions Sources/WWDCHelper/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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:
Expand Down
19 changes: 12 additions & 7 deletions Sources/WWDCHelperKit/WWDCHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum WWDCYear: String {

init(_ value: String?) {
guard let value = value else {
self = .wwdc2018
self = .wwdc2019
return
}

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

0 comments on commit 5312e3f

Please sign in to comment.