Skip to content

Commit 474a960

Browse files
authored
Merge pull request #23 from VishwaiOSDev/feat/vishwa/insta-reels-downloader
Feature: Integrate Instagram Reels and Posts Download Capability
2 parents 5b4f1ac + ccde1d8 commit 474a960

37 files changed

+870
-247
lines changed

Loadify.xcodeproj/project.pbxproj

Lines changed: 64 additions & 8 deletions
Large diffs are not rendered by default.

Loadify/App/Enums/API.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77

88
import Foundation
99

10+
enum PlatformType: String {
11+
case youtube = "yt"
12+
case instagram = "ig"
13+
}
14+
1015
enum API {
11-
case details(youtubeURL: String)
12-
case download(youtubeURL: String, quality: VideoQuality)
16+
case details(forPlatform: PlatformType, url: String)
17+
case download(url: String, quality: VideoQuality)
1318
}
1419

1520
extension API: NetworkRequestable {
@@ -20,8 +25,8 @@ extension API: NetworkRequestable {
2025

2126
var path: String {
2227
switch self {
23-
case .details:
24-
return "/api/yt/details"
28+
case .details(let platformType, _):
29+
return "/api/\(platformType.rawValue)/details"
2530
case .download:
2631
return "/api/yt/download/video/mp4"
2732
}
@@ -36,7 +41,7 @@ extension API: NetworkRequestable {
3641

3742
var queryParameters: [String : AnyHashable]? {
3843
switch self {
39-
case .details(let url):
44+
case .details(_ , let url):
4045
return ["url": url]
4146
case .download(let url, let quality):
4247
return ["url": url, "video_quality": quality.rawValue]

Loadify/App/Enums/Errors.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import Foundation
99

1010
enum DownloadError: Error, LocalizedError {
11+
1112
case notCompatible
1213

1314
var errorDescription: String? {
@@ -18,6 +19,7 @@ enum DownloadError: Error, LocalizedError {
1819
}
1920

2021
enum PhotosError: Error, LocalizedError {
22+
2123
case permissionDenied
2224
case insufficientStorage
2325

@@ -28,4 +30,3 @@ enum PhotosError: Error, LocalizedError {
2830
}
2931
}
3032
}
31-

Loadify/App/Enums/VideoQuality.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import Foundation
99

10-
enum VideoQuality: String {
10+
enum VideoQuality: String, CaseIterable {
11+
1112
case none
1213
case low = "Low"
1314
case medium = "Medium"
@@ -21,4 +22,6 @@ enum VideoQuality: String {
2122
case .high: return "High - 1080p"
2223
}
2324
}
25+
26+
static var allCases: [VideoQuality] = [.high, .medium, .low]
2427
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// InstagramDetails.swift
3+
// Loadify
4+
//
5+
// Created by Vishweshwaran on 2023-11-23.
6+
//
7+
8+
import Foundation
9+
10+
struct InstagramDetails: Codable, Hashable {
11+
12+
let thumbnailURL: String
13+
let videoURL: String
14+
15+
enum CodingKeys: String, CodingKey {
16+
case thumbnailURL = "thumbnail_link"
17+
case videoURL = "download_link"
18+
}
19+
}
20+
21+
extension InstagramDetails {
22+
23+
static let thumbnailURL = Constants.iMacURL
24+
25+
static let previews: [InstagramDetails] = [
26+
InstagramDetails(thumbnailURL: thumbnailURL, videoURL: "")
27+
]
28+
}

Loadify/Model/VideoDetails.swift renamed to Loadify/Model/YouTube/YouTubeDetails.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99

10-
struct VideoDetails: Codable {
10+
struct YouTubeDetails: Codable {
1111

1212
private enum CodingKeys: String, CodingKey {
1313
case videoUrl = "video_url"
@@ -53,12 +53,12 @@ struct ErrorModel: Codable {
5353
var message: String
5454
}
5555

56-
extension VideoDetails {
56+
extension YouTubeDetails {
5757

5858
static let channelThumbnail = "1https://yt3.ggpht.com/wzh-BL3_M_uugIXZ_ANSSzzBbi_w5XnNSRl4F5DbLAxKdTfXkjgx-kWM1mChdrrMkADRQyB-nQ=s176-c-k-c0x00ffffff-no-rj"
5959
static let videoThumbnail = "1https://i.ytimg.com/vi/CYYtLXfquy0/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&;amp;rs=AOn4CLCo3jfFz7jTmuiffAP7oetxwNgEbA"
6060

61-
static let previews: VideoDetails = VideoDetails(
61+
static let previews: YouTubeDetails = YouTubeDetails(
6262
title: "AVATAR 2 THE #WAY OF WATER Trailer (4K ULTRA HD) 2022",
6363
lengthSeconds: "109",
6464
viewCount: "7876945312 ",
@@ -90,3 +90,4 @@ extension VideoDetails {
9090
]
9191
)
9292
}
93+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Sequence+Extension.swift
3+
// Loadify
4+
//
5+
// Created by Vishweshwaran on 2023-11-25.
6+
//
7+
8+
import Foundation
9+
10+
extension Sequence {
11+
12+
func asyncForEach(_ operation: (Element, Int) async throws -> Void) async rethrows {
13+
for (index, element) in self.enumerated() {
14+
try await operation(element, index)
15+
}
16+
}
17+
}

Loadify/Others/Extensions/String+Extension.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ extension String {
7979
return text.isEmpty ? true : false
8080
}
8181

82+
func doesMatchExist(_ regularExpression: String, inputText: String) -> Bool {
83+
guard let regex = try? NSRegularExpression(pattern: regularExpression) else {
84+
return false
85+
}
86+
return regex.firstMatch(in: inputText, range: NSRange(inputText.startIndex..., in: inputText)) != nil
87+
}
88+
8289
/// Helper function for combined the date and month in String
8390
private func combineDateAndMonth(date: Int, month: Month) -> String {
8491
let convertedMonth = getMonthNotation(for: month)

Loadify/Others/Extensions/UIDevice+Extension.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ extension UIDevice {
1111

1212
/// Returns `true` if the device has a notch
1313
var hasNotch: Bool {
14-
guard #available(iOS 11.0, *),
15-
let window = UIApplication.shared.windows.filter({$0.isKeyWindow}).first else {
14+
let firstScene = UIApplication.shared.connectedScenes.first as! UIWindowScene
15+
16+
guard let window = firstScene.windows.first else {
1617
return false
1718
}
1819

Loadify/Others/Extensions/URLSession+Extension.swift

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,7 @@ extension URLSession: URLSessionProtocol {
1616
throw NetworkError.invalidResponse(message: nil)
1717
}
1818

19-
switch httpResponse.statusCode {
20-
case 200...299:
21-
break
22-
case 400:
23-
throw NetworkError.badRequest(message: "The request was invalid. Please check your input.")
24-
case 401:
25-
throw NetworkError.unauthorized(message: "You are not authorized to access this resource.")
26-
case 403:
27-
throw NetworkError.forbidden(message: "Access to this resource is forbidden.")
28-
case 404:
29-
throw NetworkError.notFound(message: "The requested resource was not found.")
30-
case 500...599:
31-
throw NetworkError.serverError(message: "A server error occurred while processing your request.")
32-
default:
33-
throw NetworkError.unknownError(message: "An unknown error occurred.")
34-
}
19+
try handleStateBasedOnStatusCode(for: httpResponse.statusCode)
3520

3621
return (data, httpResponse)
3722
}
@@ -43,7 +28,13 @@ extension URLSession: URLSessionProtocol {
4328
throw NetworkError.invalidResponse(message: nil)
4429
}
4530

46-
switch httpResponse.statusCode {
31+
try handleStateBasedOnStatusCode(for: httpResponse.statusCode)
32+
33+
return (data, httpResponse)
34+
}
35+
36+
private func handleStateBasedOnStatusCode(for statusCode: Int) throws {
37+
switch statusCode {
4738
case 200...299:
4839
break
4940
case 400:
@@ -59,7 +50,5 @@ extension URLSession: URLSessionProtocol {
5950
default:
6051
throw NetworkError.unknownError(message: "An unknown error occurred.")
6152
}
62-
63-
return (data, httpResponse)
6453
}
6554
}

0 commit comments

Comments
 (0)