Skip to content

Commit

Permalink
Don't save extraneous torrent files if download script is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgio Calderolla committed Apr 1, 2021
1 parent 448edc0 commit 5b68087
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Catch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@
CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 709;
CURRENT_PROJECT_VERSION = 711;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -826,7 +826,7 @@
CODE_SIGN_IDENTITY = "Mac Developer";
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 709;
CURRENT_PROJECT_VERSION = 711;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down
4 changes: 3 additions & 1 deletion Sources/App/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ final class Defaults: NSObject {
var downloadOptions: DownloadOptions? {
guard let torrentsSavePath = torrentsSavePath else { return nil }

// Disable downloading any files if the download script is enabled.
return DownloadOptions(
containerDirectory: torrentsSavePath,
shouldOrganizeByShow: shouldOrganizeTorrentsByShow,
shouldSaveMagnetLinks: !shouldOpenTorrentsAutomatically
shouldSaveMagnetLinks: !shouldOpenTorrentsAutomatically && !isDownloadScriptEnabled,
shouldSaveTorrentFiles: !isDownloadScriptEnabled
)
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/App/FeedHelperProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ final class FeedHelperProxy {
downloadingToBookmark: downloadOptions.containerDirectoryBookmark,
organizingByShow: downloadOptions.shouldOrganizeByShow,
savingMagnetLinks: downloadOptions.shouldSaveMagnetLinks,
savingTorrentFiles: downloadOptions.shouldSaveTorrentFiles,
skippingURLs: previouslyDownloadedURLs.map { $0.absoluteString },
withReply: { downloadedEpisodes, error in
DispatchQueue.main.async {
Expand Down Expand Up @@ -87,6 +88,7 @@ final class FeedHelperProxy {
toBookmark: downloadOptions.containerDirectoryBookmark,
organizingByShow: downloadOptions.shouldOrganizeByShow,
savingMagnetLinks: downloadOptions.shouldSaveMagnetLinks,
savingTorrentFiles: downloadOptions.shouldSaveTorrentFiles,
withReply: { downloadedFile, error in
DispatchQueue.main.async {
switch (downloadedFile, error) {
Expand Down
6 changes: 5 additions & 1 deletion Sources/Feed Helper/EpisodeDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ struct EpisodeDownloader {

// Return the magnet link, if needed the main app will open it on the fly
return DownloadedEpisode(episode: episode, localURL: nil)
} else {
} else if downloadOptions.shouldSaveTorrentFiles {
// Treat episode url as torrent file and download
let downloadedTorrentFile: URL
do {
downloadedTorrentFile = try downloadTorrentFile(for: episode)
Expand All @@ -32,6 +33,9 @@ struct EpisodeDownloader {
}

return DownloadedEpisode(episode: episode, localURL: downloadedTorrentFile)
} else {
// Treat episode url agnostically, just return it
return DownloadedEpisode(episode: episode, localURL: nil)
}
}

Expand Down
8 changes: 6 additions & 2 deletions Sources/Feed Helper/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extension Service: FeedHelperService {
downloadingToBookmark downloadDirectoryBookmark: Data,
organizingByShow shouldOrganizeByShow: Bool,
savingMagnetLinks shouldSaveMagnetLinks: Bool,
savingTorrentFiles shouldSaveTorrentFiles: Bool,
skippingURLs previouslyDownloadedURLs: [String],
withReply reply: @escaping (_ downloadedFeedFiles: [[AnyHashable:Any]]?, _ error: Error?) -> Void) {
let downloadedEpisodes: [DownloadedEpisode]
Expand All @@ -19,7 +20,8 @@ extension Service: FeedHelperService {
let downloadOptions = try DownloadOptions(
containerDirectoryBookmark: downloadDirectoryBookmark,
shouldOrganizeByShow: shouldOrganizeByShow,
shouldSaveMagnetLinks: shouldSaveMagnetLinks
shouldSaveMagnetLinks: shouldSaveMagnetLinks,
shouldSaveTorrentFiles: shouldSaveTorrentFiles
)

downloadedEpisodes = try FeedHelper.checkFeeds(
Expand Down Expand Up @@ -55,14 +57,16 @@ extension Service: FeedHelperService {
toBookmark downloadDirectoryBookmark: Data,
organizingByShow shouldOrganizeByShow: Bool,
savingMagnetLinks shouldSaveMagnetLinks: Bool,
savingTorrentFiles shouldSaveTorrentFiles: Bool,
withReply reply: @escaping (_ downloadedFile: [AnyHashable:Any]?, _ error: Error?) -> Void) {
let downloadedFile: DownloadedEpisode

do {
let downloadOptions = try DownloadOptions(
containerDirectoryBookmark: downloadDirectoryBookmark,
shouldOrganizeByShow: shouldOrganizeByShow,
shouldSaveMagnetLinks: shouldSaveMagnetLinks
shouldSaveMagnetLinks: shouldSaveMagnetLinks,
shouldSaveTorrentFiles: shouldSaveTorrentFiles
)

downloadedFile = try FeedHelper.download(
Expand Down
4 changes: 3 additions & 1 deletion Sources/Shared/DownloadOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct DownloadOptions {
var containerDirectory: URL
var shouldOrganizeByShow: Bool
var shouldSaveMagnetLinks: Bool
var shouldSaveTorrentFiles: Bool
}


Expand All @@ -18,10 +19,11 @@ extension DownloadOptions {

// Deserialization
extension DownloadOptions {
init(containerDirectoryBookmark: Data, shouldOrganizeByShow: Bool, shouldSaveMagnetLinks: Bool) throws {
init(containerDirectoryBookmark: Data, shouldOrganizeByShow: Bool, shouldSaveMagnetLinks: Bool, shouldSaveTorrentFiles: Bool) throws {
containerDirectory = try URL(sandboxBookmark: containerDirectoryBookmark)

self.shouldOrganizeByShow = shouldOrganizeByShow
self.shouldSaveMagnetLinks = shouldSaveMagnetLinks
self.shouldSaveTorrentFiles = shouldSaveTorrentFiles
}
}
2 changes: 2 additions & 0 deletions Sources/Shared/FeedHelperService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let feedHelperErrorDomain = "com.giorgiocalderolla.Catch.CatchFeedHelper"
downloadingToBookmark downloadDirectoryBookmark: Data,
organizingByShow shouldOrganizeByShow: Bool,
savingMagnetLinks shouldSaveMagnetLinks: Bool,
savingTorrentFiles shouldSaveTorrentFiles: Bool,
skippingURLs previouslyDownloadedURLs: [String],
withReply reply: @escaping (_ downloadedFeedFiles: [[AnyHashable:Any]]?, _ error: Error?) -> Void
)
Expand All @@ -24,6 +25,7 @@ let feedHelperErrorDomain = "com.giorgiocalderolla.Catch.CatchFeedHelper"
toBookmark downloadDirectoryBookmark: Data,
organizingByShow shouldOrganizeByShow: Bool,
savingMagnetLinks shouldSaveMagnetLinks: Bool,
savingTorrentFiles shouldSaveTorrentFiles: Bool,
withReply reply: @escaping (_ downloadedFile: [AnyHashable:Any]?, _ error: Error?) -> Void
)
}

0 comments on commit 5b68087

Please sign in to comment.