Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
adborbas committed Jun 6, 2022
0 parents commit 62fe1fd
Show file tree
Hide file tree
Showing 39 changed files with 1,642 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# .github/workflows/documentation.yml
name: Documentation

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Generate Documentation
uses: SwiftDocOrg/swift-doc@master
with:
inputs: "./Sources"
module-name: "qBittorrentKit"
output: "./.build/documentation"
- name: Upload Documentation to Wiki
uses: SwiftDocOrg/github-wiki-publish-action@v1
with:
path: "./.build/documentation"
env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

.DS_Store

# qBittorrent Docker
Resources/config/qBittorrent/rss/
Resources/config/qBittorrent/GeoDB/
Resources/config/qBittorrent/qBittorrent-data.conf
Resources/config/qBittorrent/lockfile
Resources/config/qBittorrent/BT_backup/
Resources/config/qBittorrent/logs/

## User settings
xcuserdata/

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

# Swift Package Manager
Packages/
Package.pins
Package.resolved
*.xcodeproj
.swiftpm

.build/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Adam Borbas

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
34 changes: 34 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// swift-tools-version:5.3

import PackageDescription

let package = Package(
name: "qBittorrent",
platforms: [
.macOS(.v10_15),
.iOS(.v13)
],
products: [
.library(
name: "qBittorrent",
targets: ["qBittorrent"]),
],
dependencies: [
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.4.0")),
],
targets: [
.target(
name: "qBittorrent",
dependencies: ["Alamofire"],
exclude: ["Resources"]),
.testTarget(
name: "UnitTests",
dependencies: ["qBittorrent"]),
.testTarget(
name: "IntegrationTests",
dependencies: ["qBittorrent"],
resources: [
.process("Resources")
]),
]
)
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# qBittorrentKit

qBittorrentKit is a light-weight [qBittorrent](https://www.qbittorrent.org) client for iOS/macOS.

## Getting started

1. Initialize the client

```swift
let qBittorrent = qBittorrentWebAPI(scheme: .http,
host: "myservice.local",
authentication: .bypassed)
```

2. Call any of the supported features

```swift
qBittorrent.sink { completion in
print("torrents received")
} receiveValue: { torrents in
print(torrents)
}
```

## Features

[WebAPI methods of qBittorrent](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-v3.2.0-v4.0.4))

### Torrent properties

- List torrents
- Get torrent generic parameters
- Set file priority
- Get torrent content

### Manage torrents

- Add torrent
- Delete torrent

### qBittorent config

- List categories
- Get app preferences
- Get webAPIVersion

## Install via SPM

1. Using Xcode go to File > Add Packages...
1. Paste the project URL: `https://github.com/adborbas/qBittorrentKit`
1. Click on next and select the project target

## Running tests

### Unit tests

1. Just run the test target.

### Integration tests

1. Have [qBittorrent](https://www.qbittorrent.org/download.php) installed somewhere.
1. Add your qBittorent credentials to `Tests/qBittorentTests/SECRET_SERVICE.swift`. Exmaple:

```swift
import Foundation
import qBittorrent

extension qBittorrentWebAPITests {
func givenService() -> qBittorrentWebAPI {
return qBittorrentWebAPI(scheme: .http,
host: "<YOUR-qBittorent-ADDRESS>",
authentication: .basicAuth(BasicAuthCredentials(username: "<USERNAME>", password: "<PASSWORD>")))
}
}
```

3. Start tests in `qBittorrentWebAPITests`.
4. ⚠️ Note that that some tests require a torrent added to qBittorrent. To make these tests reproducible a `test.torrent` torrent will be added and then removed from the client.
5 changes: 5 additions & 0 deletions Resources/config/qBittorrent/categories.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"category1": {
"save_path": ""
}
}
74 changes: 74 additions & 0 deletions Resources/config/qBittorrent/qBittorrent.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[AutoRun]
enabled=false
program=

[BitTorrent]
Session\DefaultSavePath=/downloads/
Session\Port=6881
Session\QueueingSystemEnabled=true
Session\TempPath=/downloads/incomplete/

[Core]
AutoDeleteAddedTorrentFile=Never

[LegalNotice]
Accepted=true

[Meta]
MigrationVersion=3

[Network]
Cookies=@Invalid()
PortForwardingEnabled=false
Proxy\OnlyForTorrents=false

[Preferences]
Advanced\RecheckOnCompletion=false
Advanced\trackerPort=9000
Connection\PortRangeMin=6881
Connection\ResolvePeerCountries=true
Connection\UPnP=false
Downloads\SavePath=/downloads/
Downloads\TempPath=/downloads/incomplete/
DynDNS\DomainName=changeme.dyndns.org
DynDNS\Enabled=false
DynDNS\Password=
DynDNS\Service=DynDNS
DynDNS\Username=
General\Locale=
MailNotification\email=
MailNotification\enabled=false
MailNotification\password=
MailNotification\req_auth=true
MailNotification\req_ssl=false
MailNotification\sender=qBittorrent_notification@example.com
MailNotification\smtp_server=smtp.changeme.com
MailNotification\username=
WebUI\Address=*
WebUI\AlternativeUIEnabled=false
WebUI\AuthSubnetWhitelist=@Invalid()
WebUI\AuthSubnetWhitelistEnabled=false
WebUI\BanDuration=3600
WebUI\CSRFProtection=true
WebUI\ClickjackingProtection=true
WebUI\CustomHTTPHeaders=
WebUI\CustomHTTPHeadersEnabled=false
WebUI\HTTPS\CertificatePath=
WebUI\HTTPS\Enabled=false
WebUI\HTTPS\KeyPath=
WebUI\HostHeaderValidation=true
WebUI\LocalHostAuth=false
WebUI\MaxAuthenticationFailCount=5
WebUI\Port=24560
WebUI\ReverseProxySupportEnabled=false
WebUI\RootFolder=
WebUI\SecureCookie=true
WebUI\ServerDomains=*
WebUI\SessionTimeout=3600
WebUI\TrustedReverseProxiesList=
WebUI\UseUPnP=true
WebUI\Username=admin

[RSS]
AutoDownloader\DownloadRepacks=true
AutoDownloader\SmartEpisodeFilter=s(\\d+)e(\\d+), (\\d+)x(\\d+), "(\\d{4}[.\\-]\\d{1,2}[.\\-]\\d{1,2})", "(\\d{1,2}[.\\-]\\d{1,2}[.\\-]\\d{4})"
2 changes: 2 additions & 0 deletions Resources/config/qBittorrent/watched_folders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
17 changes: 17 additions & 0 deletions Resources/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3.8"

services:
qbittorrent:
image: linuxserver/qbittorrent
container_name: qbittorrent
environment:
- PUID=1000
- PGID=1000
- UMASK_SET=022
- WEBUI_PORT=24560
volumes:
- ./config:/config
ports:
- 6881:6881
- 6881:6881/udp
- 24560:24560
43 changes: 43 additions & 0 deletions Sources/qBittorrent/Public/Model/AddTorrentConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// AddTorrentConfiguration.swift
//
//
// Created by Adam Borbas on 2021. 10. 07..
//

import Foundation

/// Configuration for adding a new torrent.
public struct AddTorrentConfiguration {

/// Torrent Management
public enum Management {
/// Automatic torrent management with category.
case auto(category: String)

/// Manual torrent management with save path.
case manual(savePath: String)
}

/// Torrent Management.
public let management: Management

/// Add torrents in the paused state.
public let paused: Bool

/// Enable sequential download
public let sequentialDownload: Bool

/// Prioritize download first last piece
public let firstLastPiecePrio: Bool

public init(management: Management = .manual(savePath: ""),
paused: Bool = false,
sequentialDownload: Bool = false,
firstLastPiecePrio: Bool = false) {
self.management = management
self.paused = paused
self.sequentialDownload = sequentialDownload
self.firstLastPiecePrio = firstLastPiecePrio
}
}
27 changes: 27 additions & 0 deletions Sources/qBittorrent/Public/Model/AppPreferences.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// AppPreferences.swift
//
//
// Created by Adam Borbas on 2021. 10. 07..
//

import Foundation

/// Application preferences.
public struct AppPreferences: Codable {
enum CodingKeys: String, CodingKey {
case isAutoTorrentManagementEnabled = "auto_tmm_enabled"
case isStartPausedEnabled = "start_paused_enabled"
case defaultSavePath = "save_path"

}

/// `true` if Automatic Torrent Management is enabled by default.
public let isAutoTorrentManagementEnabled: Bool

/// `true` if torrents should be added in a Paused state
public let isStartPausedEnabled: Bool

/// Default save path for torrents, separated by slashes.
public let defaultSavePath: String
}
Loading

0 comments on commit 62fe1fd

Please sign in to comment.