-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#13 Fixed doubule quotes and comma seperated titles
- Loading branch information
1 parent
f96b3f1
commit 9545c73
Showing
3 changed files
with
26 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
if application "iTunes" is running then | ||
tell application "iTunes" | ||
set itrack to {artist:artist of current track, name:name of current track, album:album of current track, kind:media kind of current track, state:player state, volume:sound volume, muted:mute, shuffle:shuffle enabled, repeat_song:song repeat} | ||
set itrack to artist of current track & "|" | ||
set itrack to itrack & name of current track & "|" | ||
set itrack to itrack & album of current track & "|" | ||
set itrack to itrack & media kind of current track & "|" | ||
set itrack to itrack & player state & "|" | ||
set itrack to itrack & sound volume & "|" | ||
set itrack to itrack & mute & "|" | ||
set itrack to itrack & shuffle enabled & "|" | ||
set itrack to itrack & song repeat | ||
|
||
return itrack | ||
end tell | ||
end if |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,22 @@ | ||
import ITrack from "../ITrack"; | ||
import ITrack, { MediaType } from "../ITrack"; | ||
|
||
export default class TrackFactory { | ||
public static create( trackData: any[] ): ITrack { | ||
const track: ITrack = {}; | ||
|
||
trackData.map( ( str ) => { | ||
if( str !== "null" ) { | ||
const keyvalue = str.split(":"); | ||
const key = keyvalue[0]; | ||
let value = keyvalue[1]; | ||
|
||
// Remove quotes around value if the are exists | ||
if( value[0] === "\"" && value[ value.length - 1] === "\"") { | ||
value = value.substring(1, keyvalue[1].length - 1 ); | ||
} | ||
public static create( trackData: string ): ITrack { | ||
console.log( trackData ); | ||
|
||
// Unescape double quotes | ||
value = value.replace(/\\\"/g, '"'); | ||
|
||
track[key] = value; | ||
} | ||
}); | ||
const track: ITrack = {}; | ||
const data = trackData.split("|"); | ||
track.artist = data[0]; | ||
track.name = data[1]; | ||
track.album = data[2]; | ||
track.kind = data[3] as MediaType; | ||
track.state = data[4]; | ||
track.volume = parseInt( data[5], 0); | ||
track.muted = data[6] === "false" ? false : true; | ||
track.shuffle = data[7]; | ||
track.repeat_song = data[8]; | ||
|
||
console.log( track ); | ||
return track; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters