Skip to content

Commit

Permalink
Convert to Swift package and add tests (#5)
Browse files Browse the repository at this point in the history
Signed-off-by: Ethan Dye <mrtops03@gmail.com>
  • Loading branch information
ecdye authored Sep 19, 2024
1 parent 8e4628c commit 74d20c4
Show file tree
Hide file tree
Showing 45 changed files with 750 additions and 1,049 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ updates:
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
32 changes: 21 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ name: Build
on:
push:
branches: [ "main" ]
paths:
- '**/*.swift'
pull_request:
branches: [ "main" ]
paths:
- '**/*.swift'

jobs:
build:
Expand All @@ -15,22 +19,28 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build with Xcode
- name: Select Xcode
uses: mxcl/xcodebuild@v3
with:
xcode: 16.0
platform: macOS
arch: arm64
action: build
scheme: macSup2Srt
verbosity: verbose
configuration: release
swift: 6.0
action: none

- name: Archive
run: tar cvJf ~/macSup2Srt.tar.xz -C /Users/runner/Library/Developer/Xcode/DerivedData/macSup2Srt-ceucuocfsoahbsgjtnfgwrlnyxsv/Build/Products/Release macSup2Srt
- name: Build
run: |
xcrun swift build --configuration release --arch arm64 --arch x86_64
tar -cvJf macSubtitleOCR.tar.xz -C .build/apple/Products/Release macSubtitleOCR
- name: Test
run: xcrun swift test

- name: Periphery
run: |
brew install peripheryapp/periphery/periphery
periphery scan --skip-build --index-store-path .build/debug/index/store
- name: Save artifacts
uses: actions/upload-artifact@v4
with:
name: macSup2Srt
path: ~/macSup2Srt.tar.xz
name: macSubtitleOCR.tar.xz
path: macSubtitleOCR.tar.xz
16 changes: 10 additions & 6 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ name: CodeQL
on:
push:
branches: [ "main" ]
paths:
- '**/*.swift'
pull_request:
branches: [ "main" ]
paths:
- '**/*.swift'
schedule:
- cron: '19 12 * * 6'

Expand All @@ -26,15 +30,15 @@ jobs:
languages: swift
build-mode: manual

- name: Build with Xcode
- name: Select Xcode
uses: mxcl/xcodebuild@v3
with:
xcode: 16.0
platform: macOS
arch: arm64
action: build
scheme: macSup2Srt
configuration: release
swift: 6.0
action: none

- name: Build
run: xcrun swift build --configuration release --arch arm64 --arch x86_64

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Lint
on:
push:
paths:
- '**/*.swift'
pull_request:
paths:
- '**/*.swift'

jobs:
lint:
name: Lint
runs-on: macos-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: SwiftFormat
run: swiftformat --lint . --reporter github-actions-log --disable fileHeader # seems to be broken currently in Actions env
20 changes: 10 additions & 10 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ jobs:
build:
name: Build
runs-on: macos-latest
permissions:
contents: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build with Xcode
- name: Select Xcode
uses: mxcl/xcodebuild@v3
with:
xcode: 16.0
platform: macOS
arch: arm64
action: build
scheme: macSup2Srt
verbosity: verbose
configuration: release
swift: 6.0
action: none

- name: Archive
run: tar cvJf ~/macSup2Srt.tar.xz -C /Users/runner/Library/Developer/Xcode/DerivedData/macSup2Srt-ceucuocfsoahbsgjtnfgwrlnyxsv/Build/Products/Release macSup2Srt
- name: Build
run: |
xcrun swift build --configuration release --arch arm64 --arch x86_64
tar -cvJf macSubtitleOCR.tar.xz -C .build/apple/Products/Release macSubtitleOCR
- name: Publish
uses: softprops/action-gh-release@v2
Expand All @@ -34,5 +34,5 @@ jobs:
with:
name: nightly
tag_name: nightly
files: ~/macSup2Srt.tar.xz
files: macSubtitleOCR.tar.xz
prerelease: true
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DS_Store
macSup2Srt.xcodeproj/project.xcworkspace/xcuserdata
macSup2Srt.xcodeproj/xcuserdata
build
/.build/
/.swiftpm/
/.vscode/
tests/images
tests/*.json
tests/*.srt
3 changes: 3 additions & 0 deletions .periphery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# retain_public: true
targets:
- macSubtitleOCR
40 changes: 15 additions & 25 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
--exclude /Volumes/Developer/macSup2Srt/build
--exclude .build
--minversion 0
--symlinks ignore
--acronyms ID,URL,UUID
--allman false
--anonymousforeach convert
--assetliterals visual-width
--asynccapturing
--beforemarks
--asynccapturing
--beforemarks
--binarygrouping none
--callsiteparen default
--categorymark "MARK: %c"
--classthreshold 0
--closingparen balanced
--closingparen same-line
--closurevoid remove
--commas always
--complexattrs preserve
--computedvarattrs preserve
--condassignment after-property
--conflictmarkers reject
--dateformat system
--decimalgrouping none
--doccomments before-declarations
--elseposition same-line
Expand All @@ -33,10 +32,10 @@
--fractiongrouping disabled
--fragment false
--funcattributes preserve
--generictypes
--generictypes
--groupedextension "MARK: %c"
--guardelse auto
--header "\n{file}\nmacSup2Srt\n\nCreated by {author.name} on {created}.\nCopyright © {year} {author.name}. All rights reserved.\n"
--header "\n{file}\nmacSubtitleOCR\n\nCreated by {author.name} on {created}.\nCopyright © {year} {author.name}. All rights reserved.\n"
--hexgrouping 4,8
--hexliteralcase uppercase
--ifdef indent
Expand All @@ -45,19 +44,18 @@
--indentcase false
--indentstrings false
--initcodernil false
--lifecycle
--lifecycle
--lineaftermarks true
--linebreaks lf
--markcategories true
--markextensions always
--marktypes always
--maxwidth none
--modifierorder
--nevertrailing
--modifierorder
--nevertrailing
--nilinit remove
--noncomplexattrs
--nospaceoperators
--nowrapoperators
--noncomplexattrs
--nospaceoperators
--octalgrouping none
--onelineforeach ignore
--operatorfunc spaced
Expand All @@ -66,34 +64,26 @@
--patternlet hoist
--ranges spaced
--redundanttype infer-locals-only
--self insert
--selfrequired
--semicolons never
--shortoptionals except-properties
--smarttabs enabled
--someany true
--storedvarattrs preserve
--stripunusedargs always
--structthreshold 0
--swiftversion 5
--swiftversion 6
--tabwidth unspecified
--throwcapturing
--timezone system
--trailingclosures
--throwcapturing
--trailingclosures
--trimwhitespace always
--typeattributes preserve
--typeblanklines remove
--typedelimiter space-after
--typemark "MARK: - %t"
--voidtype void
--wraparguments preserve
--wrapcollections preserve
--wrapconditions preserve
--wrapeffects preserve
--wrapenumcases always
--wrapparameters after-first
--wrapreturntype preserve
--wrapcollections before-first
--wrapternary default
--wraptypealiases preserve
--xcodeindentation disabled
--yodaswap always
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "59ba1edda695b389d6c9ac1809891cd779e4024f505b0ce1a9d5202b6762e38a",
"originHash" : "d18bff28eb0112efae908d1bc6cac45b09cd50befd488fcb3e2bc6de20e463ac",
"pins" : [
{
"identity" : "swift-argument-parser",
Expand Down
31 changes: 31 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "macSubtitleOCR",
platforms: [
.macOS("13.0"),
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "macSubtitleOCR",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]),
.testTarget(
name: "macSubtitleOCRTests",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.target(name: "macSubtitleOCR"),
],
resources: [
.process("Resources"),
]),
])
29 changes: 19 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# macSup2Srt
[![License](https://img.shields.io/github/license/ecdye/macSup2Srt)](https://github.com/ecdye/macSup2Srt/blob/main/LICENSE.md)
[![CodeQL](https://github.com/ecdye/macSup2Srt/actions/workflows/codeql.yml/badge.svg)](https://github.com/ecdye/macSup2Srt/actions/workflows/codeql.yml)
# macSubtitleOCR
[![License](https://img.shields.io/github/license/ecdye/macSubtitleOCR)](https://github.com/ecdye/macSubtitleOCR/blob/main/LICENSE.md)
[![CodeQL](https://github.com/ecdye/macSubtitleOCR/actions/workflows/codeql.yml/badge.svg)](https://github.com/ecdye/macSubtitleOCR/actions/workflows/codeql.yml)


## Overview

macSup2Srt is used to covert a file containing a PGS Subtitle stream to SubRip subtitles using OCR.
macSubtitleOCR is used to covert a file containing a PGS Subtitle stream to SubRip subtitles using OCR.
Currently the supported input file types are `.mkv` and `.sup`.
It uses the built in OCR engine in macOS to perform the text recognition, which works really well.
For more information on accuracy, see [Accuracy](#accuracy) below.
Expand All @@ -21,17 +21,26 @@ For more information on accuracy, see [Accuracy](#accuracy) below.
### Building

> [!IMPORTANT]
> This project requires at least Xcode 16 to work properly due to breaking changes, made by Apple, to the Xcode project format.
> This project requires Swift 6 work properly!
To get started with macSup2Srt, clone the repository and then build the project with Xcode.
To get started with macSubtitleOCR, clone the repository and then build the project with Swift.

``` shell
git clone https://github.com/ecdye/macSup2Srt
cd macSup2Srt
xcodebuild -scheme macSup2Srt build
git clone https://github.com/ecdye/macSubtitleOCR
cd macSubtitleOCR
swift build
```

The completed build should be available in the build directory.
The completed build should be available in the `.build/debug` directory.

### Testing

Tests compare the output to a know good output.
We target a match of at least 90% as different machines will produce different output.

``` shell
swift test
```

### Accuracy

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// DataExtensions.swift
// macSup2Srt
// macSubtitleOCR
//
// Created by Ethan Dye on 9/16/24.
// Copyright © 2024 Ethan Dye. All rights reserved.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// TextOutputStreamExtensions.swift
// macSup2Srt
// macSubtitleOCR
//
// Created by Ethan Dye on 9/16/24.
// Copyright © 2024 Ethan Dye. All rights reserved.
//

import Foundation

public struct StandardErrorOutputStream: TextOutputStream {
struct StandardErrorOutputStream: TextOutputStream {
public mutating func write(_ string: String) { fputs(string, stderr) }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// EBML.swift
// macSup2Srt
// macSubtitleOCR
//
// Created by Ethan Dye on 9/16/24.
// Copyright © 2024 Ethan Dye. All rights reserved.
Expand Down
Loading

0 comments on commit 74d20c4

Please sign in to comment.