Skip to content

Commit

Permalink
Add travis.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
cemolcay committed Apr 1, 2017
2 parents 5dff3f1 + 5970757 commit 4db3edd
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 8 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: objective-c

workspace: ChordDetector.xcworkspace
scheme: ChordDetector
test_scheme: ChordDetectorTests
osx_image: xcode8.3
xcode_sdk: macosx10.12

script:
- pod install
- xcodebuild -workspace ChordDetector.xcworkspace -scheme ChordDetector ONLY_ACTIVE_ARCH=NO CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO

- xcodebuild test -workspace ChordDetector.xcworkspace -scheme ChordDetectorTests ONLY_ACTIVE_ARCH=NO CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
4 changes: 2 additions & 2 deletions ChordDetector.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -468,7 +468,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0830"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B2C64CC11E8E6A0200E7B74F"
BuildableName = "ChordDetectorTests.xctest"
BlueprintName = "ChordDetectorTests"
ReferencedContainer = "container:ChordDetector.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B27643A61E8494DB00B67425"
BuildableName = "Chord Detector.app"
BlueprintName = "ChordDetector"
ReferencedContainer = "container:ChordDetector.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B27643A61E8494DB00B67425"
BuildableName = "Chord Detector.app"
BlueprintName = "ChordDetector"
ReferencedContainer = "container:ChordDetector.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B27643A61E8494DB00B67425"
BuildableName = "Chord Detector.app"
BlueprintName = "ChordDetector"
ReferencedContainer = "container:ChordDetector.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
<dict>
<key>SchemeUserState</key>
<dict>
<key>ChordDetector.xcscheme</key>
<key>ChordDetector.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>ChordDetectorTests.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>7</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
Expand Down
16 changes: 16 additions & 0 deletions ChordDetector/ChordDetector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,19 @@ class ChordDetector: NSObject, NSUserNotificationCenterDelegate {

private func parseChords(string: String, artist: String, song: String) {
guard let html = HTML(html: string, encoding: .utf8) else { return }

// Get chord rows from result table sorted by their rating and parse their urls
let chords = html
.xpath("//table[@class=\"tresults \"]//tr[contains(.,\"chords\")]")
.sorted(by: {
(($0.xpath("./td/span/b[@class=\"ratdig\"]").first?.text ?? "") as NSString).intValue >
(($1.xpath("./td/span/b[@class=\"ratdig\"]").first?.text ?? "") as NSString).intValue
}).flatMap({ $0.xpath("./td/div/a[@class=\"song result-link js-search-spelling-link\"]").first })

// Get most rated chord url
guard let url = chords.first?["href"] else { return }

// Push a notification after 1sec of song change to bypass iTunes/Spotify notification.
let notification = NSUserNotification()
notification.title = "Chord Detected!"
notification.informativeText = "\(artist) - \(song)"
Expand All @@ -165,6 +169,18 @@ class ChordDetector: NSObject, NSUserNotificationCenterDelegate {
"url": url,
]

Timer.scheduledTimer(
timeInterval: 1,
target: self,
selector: #selector(fireNotification(timer:)),
userInfo: ["notification": notification],
repeats: false)
}

func fireNotification(timer: Timer) {
guard let dict = timer.userInfo as? [String: Any],
let notification = dict["notification"] as? NSUserNotification
else { return }
NSUserNotificationCenter.default.deliver(notification)
}

Expand Down
17 changes: 13 additions & 4 deletions ChordDetectorTests/ChordDetectorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,31 @@ class ChordDetectorTests: XCTestCase {
url += "\(artist.replacingOccurrences(of: " ", with: "+"))+"
url += "\(song.replacingOccurrences(of: " ", with: "+"))"

guard let chordUrl = URL(string: url) else { return XCTFail("URL not parsed") }
guard let chordUrl = URL(string: url) else { return XCTFail("URL not parsed.") }

Alamofire.request(chordUrl).responseString(completionHandler: {response in
switch response.result {
case .success(let string):
guard let html = HTML(html: string, encoding: .utf8) else { return XCTFail("HTML not parsed.") }

// Parse chord rows in result table and sort them in order to rating
let chords = html
.xpath("//table[@class=\"tresults \"]//tr[contains(.,\"chords\")]")
.sorted(by: {
(($0.xpath("./td/span/b[@class=\"ratdig\"]").first?.text ?? "") as NSString).intValue >
(($1.xpath("./td/span/b[@class=\"ratdig\"]").first?.text ?? "") as NSString).intValue
}).flatMap({ $0.xpath("./td/div/a[@class=\"song result-link js-search-spelling-link\"]").first })
})
XCTAssertGreaterThan(chords.count, 0, "No chord found.")

// Parse urls of chord rows
let urls = chords.flatMap({ $0.xpath("./td/div/a[@class=\"song result-link js-search-spelling-link\"]").first })
XCTAssertGreaterThan(urls.count, 0, "Chord URLs not parsed.")

let url = chords.first?["href"]
XCTAssertNotNil(url, "Chord not found.")
// Get most rated chord url
let url = urls.first?["href"]
XCTAssertNotNil(url, "Chord URL not found.")
case .failure:
// Request error
XCTFail("URL Request error. Check internet connection.")
}
})
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ChordDetector
ChordDetector
===

[![Build Status](https://travis-ci.org/cemolcay/ChordDetector.svg?branch=master)](https://travis-ci.org/cemolcay/ChordDetector)
A tiny menu bar app that listens iTunes and Spotify to detect chords of songs!

Demo
Expand Down

0 comments on commit 4db3edd

Please sign in to comment.