Compare commits

...
6 Commits
8 changed files with 102 additions and 35 deletions

No files matched your search

+12 -7
View File
@@ -34,7 +34,7 @@ To search for apps on the App Store, use the `search` command.
```
OVERVIEW: Search for iOS apps available on the App Store.
USAGE: ipatool search <term> [--limit <limit>] [--country <country>] [--log-level <log-level>]
USAGE: ipatool search <term> [--limit <limit>] [--country <country>] [--device-family <device-family>] [--log-level <log-level>]
ARGUMENTS:
<term> The term to search for.
@@ -44,7 +44,10 @@ OPTIONS:
(default: 5)
-c, --country <country> The two-letter (ISO 3166-1 alpha-2) country code for
the iTunes Store. (default: US)
--log-level <log-level> (default: info)
-d, --device-family <device-family>
The device family to limit the search query to.
(default: iPhone)
--log-level <log-level> The log level. (default: info)
--version Show the version.
-h, --help Show help information.
```
@@ -54,7 +57,7 @@ To download a copy of the ipa file, use the `download` command.
```
OVERVIEW: Download (encrypted) iOS app packages from the App Store.
USAGE: ipatool download --bundle-identifier <bundle-identifier> [--email <email>] [--password <password>] [--country <country>] [--log-level <log-level>]
USAGE: ipatool download --bundle-identifier <bundle-identifier> [--email <email>] [--password <password>] [--auth-code <auth-code>] [--country <country>] [--device-family <device-family>] [--log-level <log-level>]
OPTIONS:
-b, --bundle-identifier <bundle-identifier>
@@ -62,14 +65,16 @@ OPTIONS:
-e, --email <email> The email address for the Apple ID.
-p, --password <password>
The password for the Apple ID.
-c, --country <country> The two-letter (ISO 3166-1 alpha-2) country code for
the iTunes Store. (default: US)
--log-level <log-level> (default: info)
--auth-code <auth-code> The 2FA code for the Apple ID.
-c, --country <country> The two-letter (ISO 3166-1 alpha-2) country code for the iTunes Store. (default: US)
-d, --device-family <device-family>
The device family to limit the search query to. (default: iPhone)
--log-level <log-level> The log level. (default: info)
--version Show the version.
-h, --help Show help information.
```
**Note:** You can specify the Apple ID email address and username as arguments when using the tool or by setting them as environment variables (`IPATOOL_EMAIL` and `IPATOOL_PASSWORD`). If you do not specify this information using either of those methods, the tool will prompt for user input in an interactive session.
**Note:** You can specify the Apple ID email address and username as arguments when using the tool or by setting them as environment variables (`IPATOOL_EMAIL` and `IPATOOL_PASSWORD`). If you do not specify this information using either of those methods, the tool will prompt for user input in an interactive session. Similarly, you can supply the 2FA code interactively or using the environment variable `IPATOOL_2FA_CODE`.
## Common Knowledge
+24 -7
View File
@@ -22,12 +22,18 @@ struct Download: ParsableCommand {
@Option(name: [.short, .customLong("password")], help: "The password for the Apple ID.")
private var passwordArgument: String?
@Option(name: [.customLong("auth-code")], help: "The 2FA code for the Apple ID.")
private var authCodeArgument: String?
@Option(name: [.short, .long], help: "The two-letter (ISO 3166-1 alpha-2) country code for the iTunes Store.")
private var country: String = "US"
@Option
@Option(name: [.short, .long], help: "The device family to limit the search query to.")
private var deviceFamily: iTunesRequest.DeviceFamily = .phone
@Option(name: [.long], help: "The log level.")
private var logLevel: LogLevel = .info
lazy var logger = ConsoleLogger(level: logLevel)
}
@@ -41,7 +47,7 @@ extension Download {
do {
logger.log("Querying the iTunes Store for '\(bundleIdentifier)' in country '\(country)'...", level: .info)
return try itunesClient.lookup(bundleIdentifier: bundleIdentifier, country: country)
return try itunesClient.lookup(bundleIdentifier: bundleIdentifier, country: country, deviceFamily: deviceFamily)
} catch {
logger.log("\(error)", level: .debug)
@@ -81,7 +87,20 @@ extension Download {
_exit(1)
}
}
mutating func authCode() -> String {
if let authCode = authCodeArgument {
return authCode
} else if let authCode = ProcessInfo.processInfo.environment["IPATOOL_2FA_CODE"] {
return authCode
} else if let authCode = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter 2FA code: ", level: .warning)))) {
return authCode
} else {
logger.log("A 2FA auth-code is required.", level: .error)
_exit(1)
}
}
mutating func authenticate(email: String, password: String) -> StoreResponse.Account {
logger.log("Creating HTTP client...", level: .debug)
let httpClient = HTTPClient(urlSession: URLSession.shared)
@@ -95,10 +114,8 @@ extension Download {
} catch {
switch error {
case StoreResponse.Error.codeRequired:
let code = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter 2FA code: ", level: .warning))))
do {
return try storeClient.authenticate(email: email, password: password, code: code)
return try storeClient.authenticate(email: email, password: password, code: authCode())
} catch {
logger.log("\(error)", level: .debug)
+1 -1
View File
@@ -11,7 +11,7 @@ struct IPATool: ParsableCommand {
static var configuration: CommandConfiguration {
return .init(commandName: "ipatool",
abstract: "A cli tool for interacting with Apple's ipa files.",
version: "1.0.4",
version: "1.0.7",
subcommands: [Download.self, Search.self])
}
}
+5 -2
View File
@@ -22,7 +22,10 @@ struct Search: ParsableCommand {
@Option(name: [.short, .long], help: "The two-letter (ISO 3166-1 alpha-2) country code for the iTunes Store.")
private var country: String = "US"
@Option
@Option(name: [.short, .long], help: "The device family to limit the search query to.")
private var deviceFamily: iTunesRequest.DeviceFamily = .phone
@Option(name: [.long], help: "The log level.")
private var logLevel: LogLevel = .info
lazy var logger = ConsoleLogger(level: logLevel)
@@ -38,7 +41,7 @@ extension Search {
do {
logger.log("Searching for '\(term)' using the '\(country)' store front...", level: .info)
let results = try itunesClient.search(term: term, limit: limit, country: country)
let results = try itunesClient.search(term: term, limit: limit, country: country, deviceFamily: deviceFamily)
guard !results.isEmpty else {
logger.log("No results found.", level: .error)
+1 -1
View File
@@ -28,7 +28,7 @@ extension StoreRequest: HTTPRequest {
var headers: [String: String] {
var headers: [String: String] = [
"User-Agent": "Configurator/2.0 (Macintosh; OS X 10.12.6; 16G29) AppleWebKit/2603.3.8",
"User-Agent": "Configurator/2.15 (Macintosh; OS X 11.0.0; 16G29) AppleWebKit/2603.3.8",
"Content-Type": "application/x-www-form-urlencoded"
]
+24 -10
View File
@@ -8,16 +8,23 @@
import Foundation
protocol iTunesClientInterface {
func lookup(bundleIdentifier: String, country: String, completion: @escaping (Result<iTunesResponse.Result, Error>) -> Void)
func search(term: String, limit: Int, country: String, completion: @escaping (Result<[iTunesResponse.Result], Error>) -> Void)
func lookup(bundleIdentifier: String,
country: String,
deviceFamily: iTunesRequest.DeviceFamily,
completion: @escaping (Result<iTunesResponse.Result, Error>) -> Void)
func search(term: String,
limit: Int,
country: String,
deviceFamily: iTunesRequest.DeviceFamily,
completion: @escaping (Result<[iTunesResponse.Result], Error>) -> Void)
}
extension iTunesClientInterface {
func lookup(bundleIdentifier: String, country: String) throws -> iTunesResponse.Result {
func lookup(bundleIdentifier: String, country: String, deviceFamily: iTunesRequest.DeviceFamily) throws -> iTunesResponse.Result {
let semaphore = DispatchSemaphore(value: 0)
var result: Result<iTunesResponse.Result, Error>?
lookup(bundleIdentifier: bundleIdentifier, country: country) {
lookup(bundleIdentifier: bundleIdentifier, country: country, deviceFamily: deviceFamily) {
result = $0
semaphore.signal()
}
@@ -34,11 +41,11 @@ extension iTunesClientInterface {
}
}
func search(term: String, limit: Int, country: String) throws -> [iTunesResponse.Result] {
func search(term: String, limit: Int, country: String, deviceFamily: iTunesRequest.DeviceFamily) throws -> [iTunesResponse.Result] {
let semaphore = DispatchSemaphore(value: 0)
var result: Result<[iTunesResponse.Result], Error>?
search(term: term, limit: limit, country: country) {
search(term: term, limit: limit, country: country, deviceFamily: deviceFamily) {
result = $0
semaphore.signal()
}
@@ -63,8 +70,11 @@ final class iTunesClient: iTunesClientInterface {
self.httpClient = httpClient
}
func lookup(bundleIdentifier: String, country: String, completion: @escaping (Result<iTunesResponse.Result, Swift.Error>) -> Void) {
let request = iTunesRequest.lookup(bundleIdentifier: bundleIdentifier, country: country)
func lookup(bundleIdentifier: String,
country: String,
deviceFamily: iTunesRequest.DeviceFamily,
completion: @escaping (Result<iTunesResponse.Result, Swift.Error>) -> Void) {
let request = iTunesRequest.lookup(bundleIdentifier: bundleIdentifier, country: country, deviceFamily: deviceFamily)
httpClient.send(request) { result in
switch result {
@@ -82,8 +92,12 @@ final class iTunesClient: iTunesClientInterface {
}
}
func search(term: String, limit: Int, country: String, completion: @escaping (Result<[iTunesResponse.Result], Swift.Error>) -> Void) {
let request = iTunesRequest.search(term: term, limit: limit, country: country)
func search(term: String,
limit: Int,
country: String,
deviceFamily: iTunesRequest.DeviceFamily,
completion: @escaping (Result<[iTunesResponse.Result], Swift.Error>) -> Void) {
let request = iTunesRequest.search(term: term, limit: limit, country: country, deviceFamily: deviceFamily)
httpClient.send(request) { result in
switch result {
+27 -7
View File
@@ -5,11 +5,31 @@
// Created by Majd Alfhaily on 22.05.21.
//
import Foundation
import ArgumentParser
enum iTunesRequest {
case search(term: String, limit: Int, country: String)
case lookup(bundleIdentifier: String, country: String)
case search(term: String, limit: Int, country: String, deviceFamily: DeviceFamily = .phone)
case lookup(bundleIdentifier: String, country: String, deviceFamily: DeviceFamily = .phone)
}
extension iTunesRequest {
enum DeviceFamily: String, ExpressibleByArgument {
case phone = "iPhone"
case pad = "iPad"
var defaultValueDescription: String {
return rawValue
}
var entity: String {
switch self {
case .phone:
return "software"
case .pad:
return "iPadSoftware"
}
}
}
}
extension iTunesRequest: HTTPRequest {
@@ -28,10 +48,10 @@ extension iTunesRequest: HTTPRequest {
var payload: HTTPPayload? {
switch self {
case let .lookup(bundleIdentifier, country):
return .urlEncoding(["media": "software", "bundleId": bundleIdentifier, "limit": "1", "country": country])
case let .search(term, limit, country):
return .urlEncoding(["media": "software", "term": term, "limit": "\(limit)", "country": country])
case let .lookup(bundleIdentifier, country, deviceFamily):
return .urlEncoding(["media": "software", "bundleId": bundleIdentifier, "limit": "1", "country": country, "entity": deviceFamily.entity])
case let .search(term, limit, country, deviceFamily):
return .urlEncoding(["media": "software", "term": term, "limit": "\(limit)", "country": country, "entity": deviceFamily.entity])
}
}
}
@@ -53,6 +53,14 @@
<CommandLineArguments>
<CommandLineArgument
argument = "download --help"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "search &quot;Swift Playgrounds&quot; --device-family iPhone"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "search &quot;Swift Playgrounds&quot; --device-family iPad"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument