Skip to content

Commit

Permalink
0.2 release!
Browse files Browse the repository at this point in the history
  • Loading branch information
cranci1 committed Jun 7, 2024
1 parent c1d9b94 commit 881910b
Show file tree
Hide file tree
Showing 16 changed files with 525 additions and 307 deletions.
82 changes: 59 additions & 23 deletions Osmium.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
13134C162C123C8700123CB1 /* tmpCleaner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13134C152C123C8700123CB1 /* tmpCleaner.swift */; };
13134C192C123CA800123CB1 /* ShareViewOpener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13134C182C123CA800123CB1 /* ShareViewOpener.swift */; };
13134C2F2C13694F00123CB1 /* Saving.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13134C2E2C13694F00123CB1 /* Saving.swift */; };
13177F332C0645A900E4CECA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13177F322C0645A900E4CECA /* AppDelegate.swift */; };
13177F352C0645A900E4CECA /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13177F342C0645A900E4CECA /* SceneDelegate.swift */; };
13177F372C0645A900E4CECA /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13177F362C0645A900E4CECA /* ViewController.swift */; };
Expand All @@ -19,13 +22,29 @@
13177F512C06460500E4CECA /* AboutPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13177F502C06460500E4CECA /* AboutPage.swift */; };
13177F542C07547900E4CECA /* VideoPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13177F532C07547900E4CECA /* VideoPlayer.swift */; };
135C0FAB2C10E0E300177744 /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 135C0FAA2C10E0E300177744 /* Request.swift */; };
135C0FAE2C10E17B00177744 /* GallerySaver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 135C0FAD2C10E17B00177744 /* GallerySaver.swift */; };
135C0FB02C10E18300177744 /* URLSaver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 135C0FAF2C10E18300177744 /* URLSaver.swift */; };
135C0FAE2C10E17B00177744 /* FileSaver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 135C0FAD2C10E17B00177744 /* FileSaver.swift */; };
135C0FB02C10E18300177744 /* URLOpener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 135C0FAF2C10E18300177744 /* URLOpener.swift */; };
1369A3C32C08ACE700C7E7B7 /* Save-Debug.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1369A3C22C08ACE700C7E7B7 /* Save-Debug.swift */; };
1369A3C52C08AD7800C7E7B7 /* PlayerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1369A3C42C08AD7800C7E7B7 /* PlayerExtension.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
13134C2D2C123EC800123CB1 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 13;
files = (
);
name = "Embed App Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
13134C152C123C8700123CB1 /* tmpCleaner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = tmpCleaner.swift; sourceTree = "<group>"; };
13134C182C123CA800123CB1 /* ShareViewOpener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareViewOpener.swift; sourceTree = "<group>"; };
13134C2E2C13694F00123CB1 /* Saving.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Saving.swift; sourceTree = "<group>"; };
13177F2F2C0645A900E4CECA /* Osmium.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Osmium.app; sourceTree = BUILT_PRODUCTS_DIR; };
13177F322C0645A900E4CECA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
13177F342C0645A900E4CECA /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -40,8 +59,8 @@
13177F502C06460500E4CECA /* AboutPage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AboutPage.swift; sourceTree = "<group>"; };
13177F532C07547900E4CECA /* VideoPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoPlayer.swift; sourceTree = "<group>"; };
135C0FAA2C10E0E300177744 /* Request.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Request.swift; sourceTree = "<group>"; };
135C0FAD2C10E17B00177744 /* GallerySaver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GallerySaver.swift; sourceTree = "<group>"; };
135C0FAF2C10E18300177744 /* URLSaver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSaver.swift; sourceTree = "<group>"; };
135C0FAD2C10E17B00177744 /* FileSaver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileSaver.swift; sourceTree = "<group>"; };
135C0FAF2C10E18300177744 /* URLOpener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLOpener.swift; sourceTree = "<group>"; };
1369A3C22C08ACE700C7E7B7 /* Save-Debug.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Save-Debug.swift"; sourceTree = "<group>"; };
1369A3C42C08AD7800C7E7B7 /* PlayerExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerExtension.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -57,6 +76,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
13134C1A2C123D2500123CB1 /* Utility */ = {
isa = PBXGroup;
children = (
13134C152C123C8700123CB1 /* tmpCleaner.swift */,
13134C182C123CA800123CB1 /* ShareViewOpener.swift */,
);
path = Utility;
sourceTree = "<group>";
};
13177F262C0645A800E4CECA = {
isa = PBXGroup;
children = (
Expand All @@ -77,16 +105,15 @@
isa = PBXGroup;
children = (
1369A3C12C08ACD300C7E7B7 /* NotificationCenter */,
1369A3C02C08ACCA00C7E7B7 /* Extensions */,
13177F522C07546D00E4CECA /* Player */,
13177F482C0645ED00E4CECA /* Settings */,
135C0FA92C10E0D300177744 /* Functions */,
13177F322C0645A900E4CECA /* AppDelegate.swift */,
13177F362C0645A900E4CECA /* ViewController.swift */,
13177F342C0645A900E4CECA /* SceneDelegate.swift */,
13177F462C0645D600E4CECA /* Main.storyboard */,
13177F3B2C0645AA00E4CECA /* Assets.xcassets */,
13177F3D2C0645AA00E4CECA /* LaunchScreen.storyboard */,
13177F3B2C0645AA00E4CECA /* Assets.xcassets */,
13177F402C0645AA00E4CECA /* Info.plist */,
);
path = Osmium;
Expand All @@ -98,6 +125,7 @@
13177F4C2C0645FF00E4CECA /* Video.swift */,
13177F4A2C0645FF00E4CECA /* Audio.swift */,
13177F4B2C0645FF00E4CECA /* Other.swift */,
13134C2E2C13694F00123CB1 /* Saving.swift */,
13177F492C0645F500E4CECA /* About */,
);
path = Settings;
Expand All @@ -114,6 +142,7 @@
13177F522C07546D00E4CECA /* Player */ = {
isa = PBXGroup;
children = (
1369A3C42C08AD7800C7E7B7 /* PlayerExtension.swift */,
13177F532C07547900E4CECA /* VideoPlayer.swift */,
);
path = Player;
Expand All @@ -122,19 +151,20 @@
135C0FA92C10E0D300177744 /* Functions */ = {
isa = PBXGroup;
children = (
13134C1A2C123D2500123CB1 /* Utility */,
135C0FB12C10E22700177744 /* Request */,
135C0FAC2C10E16B00177744 /* Saving Methods */,
135C0FAC2C10E16B00177744 /* Saving Method */,
);
path = Functions;
sourceTree = "<group>";
};
135C0FAC2C10E16B00177744 /* Saving Methods */ = {
135C0FAC2C10E16B00177744 /* Saving Method */ = {
isa = PBXGroup;
children = (
135C0FAD2C10E17B00177744 /* GallerySaver.swift */,
135C0FAF2C10E18300177744 /* URLSaver.swift */,
135C0FAD2C10E17B00177744 /* FileSaver.swift */,
135C0FAF2C10E18300177744 /* URLOpener.swift */,
);
path = "Saving Methods";
path = "Saving Method";
sourceTree = "<group>";
};
135C0FB12C10E22700177744 /* Request */ = {
Expand All @@ -145,14 +175,6 @@
path = Request;
sourceTree = "<group>";
};
1369A3C02C08ACCA00C7E7B7 /* Extensions */ = {
isa = PBXGroup;
children = (
1369A3C42C08AD7800C7E7B7 /* PlayerExtension.swift */,
);
path = Extensions;
sourceTree = "<group>";
};
1369A3C12C08ACD300C7E7B7 /* NotificationCenter */ = {
isa = PBXGroup;
children = (
Expand All @@ -171,12 +193,15 @@
13177F2B2C0645A900E4CECA /* Sources */,
13177F2C2C0645A900E4CECA /* Frameworks */,
13177F2D2C0645A900E4CECA /* Resources */,
13134C2D2C123EC800123CB1 /* Embed App Extensions */,
);
buildRules = (
);
dependencies = (
);
name = Osmium;
packageProductDependencies = (
);
productName = Osmium;
productReference = 13177F2F2C0645A900E4CECA /* Osmium.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -205,6 +230,8 @@
Base,
);
mainGroup = 13177F262C0645A800E4CECA;
packageReferences = (
);
productRefGroup = 13177F302C0645A900E4CECA /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -232,19 +259,22 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
13134C162C123C8700123CB1 /* tmpCleaner.swift in Sources */,
13177F4D2C0645FF00E4CECA /* Audio.swift in Sources */,
13177F542C07547900E4CECA /* VideoPlayer.swift in Sources */,
13134C192C123CA800123CB1 /* ShareViewOpener.swift in Sources */,
1369A3C52C08AD7800C7E7B7 /* PlayerExtension.swift in Sources */,
135C0FB02C10E18300177744 /* URLSaver.swift in Sources */,
135C0FB02C10E18300177744 /* URLOpener.swift in Sources */,
13177F4F2C0645FF00E4CECA /* Video.swift in Sources */,
13177F372C0645A900E4CECA /* ViewController.swift in Sources */,
135C0FAE2C10E17B00177744 /* GallerySaver.swift in Sources */,
135C0FAE2C10E17B00177744 /* FileSaver.swift in Sources */,
1369A3C32C08ACE700C7E7B7 /* Save-Debug.swift in Sources */,
13177F332C0645A900E4CECA /* AppDelegate.swift in Sources */,
13177F512C06460500E4CECA /* AboutPage.swift in Sources */,
13177F4E2C0645FF00E4CECA /* Other.swift in Sources */,
135C0FAB2C10E0E300177744 /* Request.swift in Sources */,
13177F352C0645A900E4CECA /* SceneDelegate.swift in Sources */,
13134C2F2C13694F00123CB1 /* Saving.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -381,13 +411,16 @@
13177F442C0645AA00E4CECA /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 399LMK6Q2Y;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Osmium/Info.plist;
INFOPLIST_KEY_NSPhotoLibraryAddUsageDescription = "The photo Library Addition is required to save media.";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "Access to the photo library is needed to play videos.";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
Expand All @@ -399,7 +432,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 0.2;
PRODUCT_BUNDLE_IDENTIFIER = me.sobet.Osmium;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -411,13 +444,16 @@
13177F452C0645AA00E4CECA /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 399LMK6Q2Y;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Osmium/Info.plist;
INFOPLIST_KEY_NSPhotoLibraryAddUsageDescription = "The photo Library Addition is required to save media.";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "Access to the photo library is needed to play videos.";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
Expand All @@ -429,7 +465,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 0.2;
PRODUCT_BUNDLE_IDENTIFIER = me.sobet.Osmium;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
12 changes: 6 additions & 6 deletions Osmium/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func deleteTemporaryDirectory() {
let fileManager = FileManager.default
let tempDir = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
let tmpURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)

do {
let contents = try fileManager.contentsOfDirectory(at: tempDir, includingPropertiesForKeys: nil, options: [])
for file in contents {
try fileManager.removeItem(at: file)
let tmpContents = try fileManager.contentsOfDirectory(at: tmpURL, includingPropertiesForKeys: nil, options: [])

for fileURL in tmpContents {
try fileManager.removeItem(at: fileURL)
}
} catch {
print("Error clearing temporary directory: \(error.localizedDescription)")
print("Error clearing tmp folder: \(error.localizedDescription)")
}
}

}

11 changes: 4 additions & 7 deletions Osmium/Functions/Request/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,14 @@ extension ViewController {
}

switch status {
case "redirect":
case "redirect", "stream":
if self.saveMedia {
self.saveMediaToGallery(urlString: mediaURLString)
self.saveMediaToTempFolder(urlString: mediaURLString)
self.writeToConsole("Saving media to temp folder...")
} else {
self.openURLInSafari(urlString: mediaURLString)
self.writeToConsole("Opening link...")
}
self.writeToConsole("Saving media...")

case "stream":
self.openURLInSafari(urlString: mediaURLString)
self.writeToConsole("Opening link...")

default:
self.writeToConsole("Unexpected status in response")
Expand Down
90 changes: 90 additions & 0 deletions Osmium/Functions/Saving Method/FileSaver.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// FileSaver.swift
// Osmium
//
// Created by Francesco on 05/06/24.
//

import UIKit

extension ViewController: URLSessionDownloadDelegate {

func saveMediaToTempFolder(urlString: String) {
guard let url = URL(string: urlString) else {
writeToConsole("Invalid media URL")
showAlert(title: "Error", message: "Invalid media URL")
return
}

let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig, delegate: self, delegateQueue: nil)

let task = session.downloadTask(with: url)
task.resume()
}

func randomizedFileName(from originalName: String) -> String {
let randomString = UUID().uuidString
let fileExtension = (originalName as NSString).pathExtension
return "\(randomString).\(fileExtension)"
}

func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
guard let response = downloadTask.response else {
writeToConsole("No response")
showAlert(title: "Error", message: "Failed to download media")
return
}

let url = downloadTask.originalRequest?.url
do {
let tempDirectory = FileManager.default.temporaryDirectory
let fileName = response.suggestedFilename ?? self.randomizedFileName(from: url?.lastPathComponent ?? "unknown")
var tempURL = tempDirectory.appendingPathComponent(fileName)

var count = 1
let fileManager = FileManager.default
while fileManager.fileExists(atPath: tempURL.path) {
let newName = "\(tempURL.deletingPathExtension().lastPathComponent)-\(count).\(tempURL.pathExtension)"
tempURL = tempDirectory.appendingPathComponent(newName)
count += 1
}

try fileManager.moveItem(at: location, to: tempURL)
self.writeToConsole("Media saved to: \(tempURL.path)")
self.openShareView(with: tempURL)

DispatchQueue.main.async {
self.downloadProgressLabel.text = "Download complete!"
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
self.downloadProgressLabel.isHidden = true
}
}
} catch {
self.writeToConsole("Error saving media: \(error.localizedDescription)")
self.showAlert(title: "Error", message: "Failed to save media")
self.clearTmpFolder()
}
}

func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
DispatchQueue.main.async {
self.downloadProgressLabel.isHidden = false
if totalBytesExpectedToWrite > 0 {
_ = Double(totalBytesWritten) / Double(totalBytesExpectedToWrite)
self.downloadProgressLabel.text = String(format: "Downloaded %.2f MB of %.2f MB", Double(totalBytesWritten) / 1_000_000, Double(totalBytesExpectedToWrite) / 1_000_000)
} else {
self.downloadProgressLabel.text = String(format: "Downloaded %.2f MB", Double(totalBytesWritten) / 1_000_000)
}
}
}

func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
if let error = error {
DispatchQueue.main.async {
self.writeToConsole("Error downloading media: \(error.localizedDescription)")
self.showAlert(title: "Error", message: "Failed to download media")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// URLSaver.swift
// URLOpener.swift
// Osmium
//
// Created by Francesco on 05/06/24.
Expand Down
Loading

0 comments on commit 881910b

Please sign in to comment.