Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preference to automatically delete videos when watched #570

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ github "bustoutsolutions/siesta" ~> 1.0

github "sparkle-project/Sparkle" ~> 1.17

github "insidegui/ChromeCastCore" ~> 0.2.1
github "insidegui/ChromeCastCore" ~> 0.3.2
github "insidegui/CloudKitCodable" ~> 0.1.3
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ github "RxSwiftCommunity/RxRealm" "0.7.7"
github "SwiftyJSON/SwiftyJSON" "4.3.0"
github "apple/swift-protobuf" "1.5.0"
github "bustoutsolutions/siesta" "1.4.3"
github "insidegui/ChromeCastCore" "0.2.1"
github "insidegui/ChromeCastCore" "0.3.2"
github "insidegui/CloudKitCodable" "0.1.4"
github "realm/realm-cocoa" "v3.15.0"
github "realm/realm-cocoa" "v3.16.1"
github "sparkle-project/Sparkle" "1.21.3"
13 changes: 13 additions & 0 deletions WWDC/PlaybackViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ final class PlaybackViewModel {

if !d.isZero { self.nowPlayingInfo.value?.progress = p / d }
}

NotificationCenter.default.addObserver(self, selector: #selector(self.playerDidReachEndOfVideo(note:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This notification only fires if they play to the very, very end, which won't necessarily align with the other notions we have of "watched". We also probably shouldn't delete the video that is currently being played. Are there any other integration points for a feature like this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it should be deleted when the app considers it as being watched. And there's also the consideration of when to actually delete the video, since deleting the video file that's currently being played sounds dangerous.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another question is: should we delete the video if the user manually marks it as watched?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm starting to wonder if this feature is even worth it. Is it really that hard to press a button after you finish watching the video? Maybe we could display the delete option more prominently over the video when it's near the end? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post roll overlay? Like on Net... uh, major video subscription services ;-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we went a fully automatic route I'd be in favor of a cleanup job on app launch. Also, just confirmed users can delete the currently playing video manually already 😂😭

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you do? 😛

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything works fine. I'm guessing due to having a robust OS and frameworks that don't let the file get completely removed when it's open? Or maybe AVFoundation defensive programming?

}
}

@objc func playerDidReachEndOfVideo(note: NSNotification) {

let shouldDeleteVideo = UserDefaults.standard.bool(forKey: "autoDeleteVideosWhenWatched")

if shouldDeleteVideo {
DownloadManager.shared.deleteDownloadedFile(for: sessionViewModel.session)
}
}

Expand All @@ -134,6 +145,8 @@ final class PlaybackViewModel {
player.removeTimeObserver(timeObserver)
self.timeObserver = nil
}

NotificationCenter.default.removeObserver(self)
}

}
Expand Down
157 changes: 78 additions & 79 deletions WWDC/Preferences.storyboard
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14113"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
<capability name="stacking Non-gravity area distributions on NSStackView" minToolsVersion="7.0" minSystemVersion="10.11"/>
</dependencies>
<scenes>
<!--General Preferences View Controller-->
Expand All @@ -15,15 +14,79 @@
<rect key="frame" x="0.0" y="0.0" width="650" height="500"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField toolTip="The schedule and videos will be automatically refreshed every five minutes (useful during WWDC week)" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="YmL-o7-wzA">
<rect key="frame" x="119" y="456" width="117" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Downloads Folder:" id="wBE-cT-TAg">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<stackView distribution="fill" orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jme-OU-7GG">
<rect key="frame" x="242" y="428" width="218" height="43"/>
<subviews>
<textField toolTip="The schedule and videos will be automatically refreshed every five minutes (useful during WWDC week)" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="eKi-p7-aRV">
<rect key="frame" x="-2" y="29" width="155" height="14"/>
<textFieldCell key="cell" lineBreakMode="truncatingMiddle" sendsActionOnEndEditing="YES" alignment="left" title="/Users/inside/Movies/WWDC" id="IRs-Ob-UjV">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<stackView distribution="fill" orientation="horizontal" alignment="top" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="9eP-at-INJ">
<rect key="frame" x="0.0" y="0.0" width="218" height="21"/>
<subviews>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="zMH-NN-9R2">
<rect key="frame" x="-6" y="-7" width="136" height="32"/>
<buttonCell key="cell" type="push" title="Reveal in Finder" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="dNU-EY-RIE">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="revealDownloadsFolderInFinder:" target="9dt-pe-Bsa" id="AoO-dL-uKP"/>
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3wU-sv-Hfb">
<rect key="frame" x="126" y="-7" width="98" height="32"/>
<buttonCell key="cell" type="push" title="Change…" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="58d-Kc-Zja">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="selectDownloadsFolder:" target="9dt-pe-Bsa" id="Gmq-rY-I9y"/>
</connections>
</button>
</subviews>
<visibilityPriorities>
<integer value="1000"/>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
</subviews>
<visibilityPriorities>
<integer value="1000"/>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
<box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="oXs-gK-eLO">
<rect key="frame" x="39" y="405" width="611" height="5"/>
</box>
<box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="OZk-0e-tyQ">
<rect key="frame" x="39" y="322" width="611" height="5"/>
</box>
<box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="gSp-wk-rap">
<rect key="frame" x="39" y="265" width="611" height="5"/>
</box>
<textField toolTip="The schedule and videos will be automatically refreshed every five minutes (useful during WWDC week)" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Yew-yF-ZWD">
<rect key="frame" x="186" y="373" width="50" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Search:" id="fto-X6-Q8v">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<stackView distribution="fill" orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="N9Z-iX-jvK">
<rect key="frame" x="242" y="344" width="152" height="44"/>
<subviews>
Expand Down Expand Up @@ -101,14 +164,9 @@
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
<textField toolTip="The schedule and videos will be automatically refreshed every five minutes (useful during WWDC week)" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Yew-yF-ZWD">
<rect key="frame" x="186" y="373" width="50" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Search:" id="fto-X6-Q8v">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="OZk-0e-tyQ">
<rect key="frame" x="39" y="322" width="611" height="5"/>
</box>
<stackView distribution="fill" orientation="horizontal" alignment="top" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="GJT-d9-qvO">
<rect key="frame" x="242" y="287" width="288" height="18"/>
<subviews>
Expand Down Expand Up @@ -140,68 +198,9 @@
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
<textField toolTip="The schedule and videos will be automatically refreshed every five minutes (useful during WWDC week)" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="YmL-o7-wzA">
<rect key="frame" x="119" y="456" width="117" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Downloads Folder:" id="wBE-cT-TAg">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<stackView distribution="fill" orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jme-OU-7GG">
<rect key="frame" x="242" y="428" width="218" height="43"/>
<subviews>
<textField toolTip="The schedule and videos will be automatically refreshed every five minutes (useful during WWDC week)" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="eKi-p7-aRV">
<rect key="frame" x="-2" y="29" width="155" height="14"/>
<textFieldCell key="cell" lineBreakMode="truncatingMiddle" sendsActionOnEndEditing="YES" alignment="left" title="/Users/inside/Movies/WWDC" id="IRs-Ob-UjV">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<stackView distribution="fill" orientation="horizontal" alignment="top" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="9eP-at-INJ">
<rect key="frame" x="0.0" y="0.0" width="218" height="21"/>
<subviews>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="zMH-NN-9R2">
<rect key="frame" x="-6" y="-7" width="136" height="32"/>
<buttonCell key="cell" type="push" title="Reveal in Finder" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="dNU-EY-RIE">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="revealDownloadsFolderInFinder:" target="9dt-pe-Bsa" id="AoO-dL-uKP"/>
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3wU-sv-Hfb">
<rect key="frame" x="126" y="-7" width="98" height="32"/>
<buttonCell key="cell" type="push" title="Change…" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="58d-Kc-Zja">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="selectDownloadsFolder:" target="9dt-pe-Bsa" id="Gmq-rY-I9y"/>
</connections>
</button>
</subviews>
<visibilityPriorities>
<integer value="1000"/>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
</subviews>
<visibilityPriorities>
<integer value="1000"/>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
<box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="gSp-wk-rap">
<rect key="frame" x="39" y="265" width="611" height="5"/>
</box>
<stackView distribution="fill" orientation="horizontal" alignment="top" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="k0r-jU-jAt">
<rect key="frame" x="242" y="230" width="270" height="18"/>
<subviews>
Expand Down