Skip to content

Commit

Permalink
enhanced logging, fix cache count
Browse files Browse the repository at this point in the history
  • Loading branch information
esetnik committed Nov 22, 2017
1 parent da23630 commit dfed9de
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 62 deletions.
12 changes: 6 additions & 6 deletions Aerial/Source/Controllers/PreferencesWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -495,23 +495,23 @@ NSOutlineViewDelegate, VideoDownloadDelegate {
return video.isAvailableOffline == false
}

if uncached.count == 0 {
cacheStatusLabel.stringValue = "All videos have been cached"
return
}

NSLog("uncached: \(uncached)")

totalProgress.maxValue = Double(manifestVideos.count)
totalProgress.doubleValue = Double(manifestVideos.count) - Double(uncached.count)
NSLog("total process max value: \(totalProgress.maxValue), current value: \(totalProgress.doubleValue)")

if uncached.count == 0 {
cacheStatusLabel.stringValue = "All videos have been cached"
return
}

let video = uncached[0]

// find video that hasn't been cached
let videoDownload = VideoDownload(video: video, delegate: self)

cacheStatusLabel.stringValue = "Caching video \(video.name) \(video.timeOfDay.capitalized): \(video.id)"
cacheStatusLabel.stringValue = "Caching video \(video.name) \(video.timeOfDay.capitalized): \(video.url)"

currentVideoDownload = videoDownload
videoDownload.startDownload()
Expand Down
6 changes: 5 additions & 1 deletion Aerial/Source/Models/AerialVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

class AerialVideo {
class AerialVideo: CustomStringConvertible {
let id: String
let name: String
let type: String
Expand All @@ -32,4 +32,8 @@ class AerialVideo {
self.timeOfDay = timeOfDay
self.url = URL(string: url)!
}

var description: String {
return "id=\(id), name=\(name), type=\(type), timeofDay=\(timeOfDay), url=\(url)"
}
}
20 changes: 10 additions & 10 deletions Aerial/Source/Models/Extensions/CollectionType+Shuffling.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@

//
// CollectionType+Shuffling.swift
// Aerial
//

import Foundation

// shuffling thanks to Nate Cook http://stackoverflow.com/questions/24026510/how-do-i-shuffle-an-array-in-swift

extension MutableCollection {
/// Shuffle the elements of `self` in-place.
extension MutableCollection where Indices.Iterator.Element == Index {
/// Shuffles the contents of this collection.
mutating func shuffle() {
// empty and single-element collections don't shuffle
if count < 2 { return }
let c = count
guard c > 1 else { return }

for i in indices.dropLast() {
let diff = distance(from: i, to: endIndex)
let j = index(i, offsetBy: numericCast(arc4random_uniform(numericCast(diff))))
swapAt(i, j)
for (unshuffledCount, firstUnshuffled) in zip(stride(from: c, to: 1, by: -1), indices) {
let d: IndexDistance = numericCast(arc4random_uniform(numericCast(unshuffledCount)))
guard d != 0 else { continue }
let i = index(firstUnshuffled, offsetBy: d)
swap(&self[firstUnshuffled], &self[i])
}
}
}
Expand Down
67 changes: 22 additions & 45 deletions Aerial/Source/Models/ManifestLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,53 +101,30 @@ class ManifestLoader {
let options = JSONSerialization.ReadingOptions.allowFragments
let batches = try JSONSerialization.jsonObject(with: data,
options: options)
if let batches = batches as? Array<NSDictionary> {
for batch: NSDictionary in batches {
let assets = batch["assets"] as! Array<NSDictionary>

for item in assets {
let url = item["url"] as! String
let name = item["accessibilityLabel"] as! String
let timeOfDay = item["timeOfDay"] as! String
let id = item["id"] as! String
let type = item["type"] as! String

if type != "video" {
continue
}

let video = AerialVideo(id: id,
name: name,
type: type,
timeOfDay: timeOfDay,
url: url)

videos.append(video)

checkContentLength(video)
}
}

guard let batch = batches as? NSDictionary else {
NSLog("Aerial: Encountered unexpected content type for batch")
return
}
else if let batch = batches as? NSDictionary {
let assets = batch["assets"] as! Array<NSDictionary>

let assets = batch["assets"] as! Array<NSDictionary>

for item in assets {
let url = item["url-4K-SDR"] as! String
let name = item["accessibilityLabel"] as! String
let timeOfDay = "day"
let id = item["id"] as! String
let type = "video"

for item in assets {
let url = item["url-4K-SDR"] as! String
let name = item["accessibilityLabel"] as! String
let timeOfDay = "day"
let id = item["id"] as! String
let type = "video"

let video = AerialVideo(id: id,
name: name,
type: type,
timeOfDay: timeOfDay,
url: url)

videos.append(video)

checkContentLength(video)
}
let video = AerialVideo(id: id,
name: name,
type: type,
timeOfDay: timeOfDay,
url: url)

videos.append(video)

checkContentLength(video)
}

self.loadedManifest = videos
Expand Down

0 comments on commit dfed9de

Please sign in to comment.