diff --git a/LiquipediaMenu.xcodeproj/project.pbxproj b/LiquipediaMenu.xcodeproj/project.pbxproj index c065cee..0f6b6fe 100644 --- a/LiquipediaMenu.xcodeproj/project.pbxproj +++ b/LiquipediaMenu.xcodeproj/project.pbxproj @@ -9,7 +9,7 @@ /* Begin PBXBuildFile section */ 3F49E946216B86150047B0FE /* Match.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F49E945216B86150047B0FE /* Match.swift */; }; 3F49E948216B862B0047B0FE /* StatusBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F49E947216B862B0047B0FE /* StatusBarController.swift */; }; - 3F49E94A216BE87B0047B0FE /* MatchesAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F49E949216BE87B0047B0FE /* MatchesAPI.swift */; }; + 3F49E94A216BE87B0047B0FE /* LiquipediaMatchesAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F49E949216BE87B0047B0FE /* LiquipediaMatchesAPI.swift */; }; 3F50154321DBD37200AC9639 /* LiquipediaMenuTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F50154221DBD37200AC9639 /* LiquipediaMenuTests.swift */; }; 3F50154B21DBD43E00AC9639 /* MatchesAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F50154A21DBD43E00AC9639 /* MatchesAPITests.swift */; }; 3F563E07216E640D00AA3C06 /* MatchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F563E06216E640D00AA3C06 /* MatchView.swift */; }; @@ -35,7 +35,7 @@ 37CBB27C5544ABC18BCC3124 /* Pods_LiquipediaMenu.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LiquipediaMenu.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 3F49E945216B86150047B0FE /* Match.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Match.swift; sourceTree = ""; }; 3F49E947216B862B0047B0FE /* StatusBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBarController.swift; sourceTree = ""; }; - 3F49E949216BE87B0047B0FE /* MatchesAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchesAPI.swift; sourceTree = ""; }; + 3F49E949216BE87B0047B0FE /* LiquipediaMatchesAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiquipediaMatchesAPI.swift; sourceTree = ""; }; 3F50154021DBD37100AC9639 /* LiquipediaMenuTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LiquipediaMenuTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 3F50154221DBD37200AC9639 /* LiquipediaMenuTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiquipediaMenuTests.swift; sourceTree = ""; }; 3F50154421DBD37200AC9639 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -113,7 +113,7 @@ children = ( 3FB6BB47216B8594000BF5AA /* AppDelegate.swift */, 3F49E947216B862B0047B0FE /* StatusBarController.swift */, - 3F49E949216BE87B0047B0FE /* MatchesAPI.swift */, + 3F49E949216BE87B0047B0FE /* LiquipediaMatchesAPI.swift */, 3F49E945216B86150047B0FE /* Match.swift */, 3FF66CDE21DE80BA005A93D0 /* MatchMenuItem.swift */, 3F563E06216E640D00AA3C06 /* MatchView.swift */, @@ -293,7 +293,7 @@ 3F563E07216E640D00AA3C06 /* MatchView.swift in Sources */, 3F49E948216B862B0047B0FE /* StatusBarController.swift in Sources */, 3FF66CDF21DE80BA005A93D0 /* MatchMenuItem.swift in Sources */, - 3F49E94A216BE87B0047B0FE /* MatchesAPI.swift in Sources */, + 3F49E94A216BE87B0047B0FE /* LiquipediaMatchesAPI.swift in Sources */, 3F49E946216B86150047B0FE /* Match.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LiquipediaMenu/MatchesAPI.swift b/LiquipediaMenu/LiquipediaMatchesAPI.swift similarity index 81% rename from LiquipediaMenu/MatchesAPI.swift rename to LiquipediaMenu/LiquipediaMatchesAPI.swift index 685c7a3..32165b4 100644 --- a/LiquipediaMenu/MatchesAPI.swift +++ b/LiquipediaMenu/LiquipediaMatchesAPI.swift @@ -9,7 +9,7 @@ import Foundation import SwiftSoup -class MatchesAPI { +class LiquipediaMatchesAPI { func fetchMatches(for game: String) -> [Match]? { let games = ["dota2", "starcraft", "starcraft2", "heroes", "counterstrike", "rocketleague", "rainbowsix", "overwatch"] @@ -47,8 +47,13 @@ class MatchesAPI { let newMatch = Match() newMatch.ongoing = true - // TODO: Handle what happens when there is no twitch page. Currently it just opens Twicht main page. - newMatch.streamLink = try "https://twitch.tv/" + match.getElementsByClass("timer-object").attr("data-stream-twitch") + + // Tries to extract the stream link. If there is none, the string streamLink will be empty. + // TODO: data-stream-twitch doesn't always contain the twitch user, so it can't always be used to go to the twitch site. + print(try match.getAllElements().toString()) + print(try match.getElementsByClass("timer-object-countdown")) + newMatch.streamLink = try match.getElementsByClass("timer-object-countdown").select("span").attr("href") + newMatch.league = try match.select("tr > td > div > div > a").text() newMatch.team1name = try match.getElementsByClass("team-left").text() newMatch.team1score = leftscore diff --git a/LiquipediaMenu/StatusBarController.swift b/LiquipediaMenu/StatusBarController.swift index 21168a9..31c9250 100644 --- a/LiquipediaMenu/StatusBarController.swift +++ b/LiquipediaMenu/StatusBarController.swift @@ -16,7 +16,7 @@ class StatusBarController: NSObject, NSMenuItemValidation { let statusBar = NSMenu() let statusBarItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) - let matchesAPI = MatchesAPI() + let matchesAPI = LiquipediaMatchesAPI() var matches = [Match]() override func awakeFromNib() { @@ -54,7 +54,7 @@ class StatusBarController: NSObject, NSMenuItemValidation { } } - if let matches = self.matchesAPI.fetchMatches(for: "dota2") { + if let matches = self.matchesAPI.fetchMatches(for: "counterstrike") { for match in matches { let newItem = MatchMenuItem.init(for: match, action: #selector(self.openStreamLink)) newItem.tag = 1