Skip to content

Commit

Permalink
#13 Fixed doubule quotes and comma seperated titles
Browse files Browse the repository at this point in the history
  • Loading branch information
joeykamsteeg committed Jul 3, 2019
1 parent f96b3f1 commit 9545c73
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
11 changes: 10 additions & 1 deletion scripts/currentTrack.applescript
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
35 changes: 15 additions & 20 deletions src/Factories/TrackFactory.ts
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;
}
}
1 change: 1 addition & 0 deletions src/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default class Player {
if( app.appState === "running" ){
this.iTunes.getCurrentTrack()
.then( ( track: any ) => {
console.log( track );
track = TrackFactory.create( track );

if( track.artist != null && track.name != null ){
Expand Down

0 comments on commit 9545c73

Please sign in to comment.