<commit_before>//
//  ITunesNotificationHandler.swift
//  Notify
//
//  Created by <NAME> on 9/21/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation
import Cocoa
import Alamofire
import SwiftyJSON

class ITunesNotificationHandler: NSObject, NSUserNotificationCenterDelegate, NotificationHandler {
    let track = Song()
    let client: Client = .iTunes
    
    /**
    Called when the application changes its playback state
    @param notification, an NSNotification passed in when state changes
    **/
    func iTunesStateChanged(notification: NSNotification) {
        self.stateChanged(notification)
    }
    
    /**********************
    * Getters and Setters *
    **********************/
    func setCurrentTrack(info: NSDictionary) {
        // Set the current track
        track.name = info["Name"] as! String
        if let artist = info["Album Artist"] {
            track.artist = artist as! String
        }
        else {
            track.artist = info["Artist"] as! String
        }
        track.album = info["Album"] as! String
        
        // Get the album art for the track
        let storeUrl = info["Store URL"] as! String
        NSLog("%@", info)
        let albumId = getQueryStringParameter(storeUrl, param: "p")
        if (albumId != nil) {
            let itunesApiUrl = "https://itunes.apple.com/lookup?id=" + albumId!
            NSLog("%@", itunesApiUrl)
            Alamofire.request(.GET, itunesApiUrl, parameters: nil)
                .responseJSON { (req, res, result) in
                    if (result.isFailure) {
                        NSLog("Error: \(result.error)")
                    }
                    else {
                        var json = JSON(result.value!)
                        if (json["resultCount"] > 0) {
                            // Get the album art. Size doesn't matter.
                            let albumArtworkUrl: NSURL = NSURL(string: json["results"][0]["artworkUrl100"].stringValue)!
                            let albumArtwork = NSImage(contentsOfURL: albumArtworkUrl)
                            if (albumArtwork != nil) {
                                self.track.image = albumArtwork!
                            }
                        }
                    
                        // Send the notification
                        self.sendNotification()
                    }<commit_msg>Remove debug logging<commit_after>//
//  ITunesNotificationHandler.swift
//  Notify
//
//  Created by <NAME> on 9/21/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation
import Cocoa
import Alamofire
import SwiftyJSON

class ITunesNotificationHandler: NSObject, NSUserNotificationCenterDelegate, NotificationHandler {
    let track = Song()
    let client: Client = .iTunes
    
    /**
    Called when the application changes its playback state
    @param notification, an NSNotification passed in when state changes
    **/
    func iTunesStateChanged(notification: NSNotification) {
        self.stateChanged(notification)
    }
    
    /**********************
    * Getters and Setters *
    **********************/
    func setCurrentTrack(info: NSDictionary) {
        // Set the current track
        track.name = info["Name"] as! String
        if let artist = info["Album Artist"] {
            track.artist = artist as! String
        }
        else {
            track.artist = info["Artist"] as! String
        }
        track.album = info["Album"] as! String
        
        // Get the album art for the track
        let storeUrl = info["Store URL"] as! String
        let albumId = getQueryStringParameter(storeUrl, param: "p")
        if (albumId != nil) {
            let itunesApiUrl = "https://itunes.apple.com/lookup?id=" + albumId!
            Alamofire.request(.GET, itunesApiUrl, parameters: nil)
                .responseJSON { (req, res, result) in
                    if (result.isFailure) {
                        NSLog("Error: \(result.error)")
                    }
                    else {
                        var json = JSON(result.value!)
                        if (json["resultCount"] > 0) {
                            // Get the album art. Size doesn't matter.
                            let albumArtworkUrl: NSURL = NSURL(string: json["results"][0]["artworkUrl100"].stringValue)!
                            let albumArtwork = NSImage(contentsOfURL: albumArtworkUrl)
                            if (albumArtwork != nil) {
                                self.track.image = albumArtwork!
                            }
                        }
                    
                        // Send the notification
                        self.sendNotification()
                    }
{'fraction_non_alphanumeric': 0.11132115101869355, 'fraction_numerical': 0.0058811174123083385, 'mean_word_length': 1.5643511039310716, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '395301', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1168, 'n_words': 322}