Skip to content

Commit

Permalink
Merge branch 'release/v1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJeong committed Feb 15, 2017
2 parents 6b878a2 + b0e5d10 commit 9911505
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 55 deletions.
163 changes: 126 additions & 37 deletions NicoDownloader/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ extension ProgressViewController {
func download() {
self.updateStatusMessage(message: "Downloading items...")
downloadWorkItem = DispatchWorkItem {
let semaphore = DispatchSemaphore(value: 1)
let semaphore = DispatchSemaphore(value: self.options.concurrentDownloadCount - 1)
for (idx, item) in self.items.enumerated() {
Thread.sleep(forTimeInterval: 3)
self.items[idx].status = .fetching
Expand All @@ -115,7 +115,7 @@ extension ProgressViewController {
self.items[idx].videoUrl = url
return self.prefetchVideoPage(videoId: item.videoId)
}.then { title -> Promise<Void> in
self.items[idx].name = title
self.items[idx].name = self.items[idx].name ?? title
self.items[idx].status = .downloading
return self.downloadVideo(item: self.items[idx], url: self.items[idx].videoUrl!, progressCallback: {
self.items[idx].progress = $0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension ProgressViewController: NSTableViewDelegate {
}
case tableView.tableColumns[1]:
if let cell = tableView.make(withIdentifier: CellIdentifiers.TitleCell, owner: nil) as? NSTableCellView {
cell.textField?.stringValue = item.name
cell.textField?.stringValue = item.name ?? "Unknown"
return cell
}
case tableView.tableColumns[2]:
Expand Down
14 changes: 7 additions & 7 deletions NicoDownloader/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -22,11 +17,16 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.0.1</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>2</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017년 Jeong. All rights reserved.</string>
<key>NSMainStoryboardFile</key>
Expand Down
4 changes: 3 additions & 1 deletion NicoDownloader/Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ struct Account {

struct Options {
let videoInfo: VideoInfo
let concurrentDownloadCount: Int
var saveDirectory: URL = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask)[0]

init(videoInfo: VideoInfo) {
init(videoInfo: VideoInfo, concurrentDownloadCount: Int) {
self.videoInfo = videoInfo
self.concurrentDownloadCount = concurrentDownloadCount
}
}

Expand Down
3 changes: 1 addition & 2 deletions NicoDownloader/Models/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ enum Status {

struct Item {
let videoId: String
var name: String
var name: String!
var pubdate: Date?
var status: Status = .sleeping
var videoUrl: String?
Expand All @@ -42,7 +42,6 @@ struct Item {

init(videoId: String) {
self.videoId = videoId
self.name = "Unknown"
}

init(videoId: String, name: String, pubdate: Date) {
Expand Down
37 changes: 32 additions & 5 deletions NicoDownloader/ViewControllers/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class ViewController: NSViewController {
@IBOutlet weak var rememberAccountCheckbox: NSButton!
@IBOutlet weak var modeTabView: NSTabView!
@IBOutlet weak var videoIdsTextField: NSTextField!
@IBOutlet weak var advancedOptionsBox: NSBox!
@IBOutlet weak var advancedOptionsDisclosure: NSButton!
@IBOutlet weak var advancedOptionHeightConstraint: NSLayoutConstraint!
@IBOutlet weak var concurrentDownloadCountButton: NSPopUpButton!

var sessionManager: SessionManager!
var saveDirectory: URL?
Expand All @@ -38,6 +42,8 @@ class ViewController: NSViewController {
if let saveDirectory = UserDefaults.standard.url(forKey: "saveDirectory") {
setSaveDirectory(url: saveDirectory)
}

toggleAdvancedOptions(animate: false)
}

override func viewDidAppear() {
Expand All @@ -51,8 +57,10 @@ class ViewController: NSViewController {
}

override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
guard let segID = segue.identifier, segID == "showDownloadController", let dest = segue.destinationController as? ProgressViewController else {
return
guard let segID = segue.identifier, segID == "showDownloadController",
let dest = segue.destinationController as? ProgressViewController,
let options = createOptions() else {
return
}

let account = Account(email: emailField.stringValue, password: passwordField.stringValue)
Expand All @@ -63,7 +71,7 @@ class ViewController: NSViewController {
}

dest.account = account
dest.options = createOptions()
dest.options = options
}

@IBAction func chooseDirectoryButtonDidTap(_ sender: Any) {
Expand All @@ -73,7 +81,7 @@ class ViewController: NSViewController {
}
}

private func createOptions() -> Options {
private func createOptions() -> Options? {
let videoInfo: VideoInfo
switch modeTabView.selectedTabViewItem?.label {
case .some("Video"):
Expand All @@ -86,8 +94,12 @@ class ViewController: NSViewController {
}
videoInfo = mylist
}
guard let concurrentDownloadCountString = concurrentDownloadCountButton.selectedItem?.title,
let concurrentDownloadCount = Int(concurrentDownloadCountString) else {
return nil
}

var options = Options(videoInfo: videoInfo)
var options = Options(videoInfo: videoInfo, concurrentDownloadCount: concurrentDownloadCount)

if let saveDirectory = saveDirectory {
options.saveDirectory = saveDirectory
Expand All @@ -100,5 +112,20 @@ class ViewController: NSViewController {
saveDirectory = url
selectedDirectoryTextField.stringValue = url.path
}

@IBAction func advancedOptionsDidClick(_ sender: Any) {
toggleAdvancedOptions()
}

private func toggleAdvancedOptions(animate: Bool = true) {
let show = advancedOptionHeightConstraint.constant == 0
let constraint = animate ? advancedOptionHeightConstraint.animator() : advancedOptionHeightConstraint
let box = animate ? advancedOptionsBox.animator() : advancedOptionsBox
let disclosure = animate ? advancedOptionsDisclosure.animator() : advancedOptionsDisclosure

constraint!.constant = show ? 34 : 0
box!.isHidden = !show
disclosure!.state = show ? NSOnState : NSOffState
}
}

0 comments on commit 9911505

Please sign in to comment.