Skip to content

Commit

Permalink
Fixed issues with the elapsed time
Browse files Browse the repository at this point in the history
  • Loading branch information
kkevinm committed Aug 8, 2020
1 parent 109e363 commit 3a31963
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 57 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.kevinmussi</groupId>
<artifactId>itunes-discord-rp</artifactId>
<version>1.5.4</version>
<version>1.5.5</version>
<packaging>jar</packaging>
<name>iTunes Discord RP</name>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ set STR_PAUSED to "PAUSED"

set state to ""

property savedTrack : missing value
property savedPlayerState : missing value

repeat
delay 1
# If iTunes is not running, set the state to "STOPPED" and do nothing
Expand All @@ -28,23 +25,14 @@ repeat
log state
end if
else
set currentTrack to current track

# If the current song or the player status has changed, log the new track information
if currentPlayerState is not savedPlayerState or currentTrack is not savedTrack then
if currentPlayerState is playing then
set state to STR_PLAYING
else
set state to STR_PAUSED
end if

# Write the track main information in the log
log name of current track & ";;" & artist of current track & ";;" & album of current track & ";;" & state & ";;" & player position & ";;" & duration of current track & ";;" & track number of current track & ";;" & track count of current track
if currentPlayerState is playing then
set state to STR_PLAYING
else
set state to STR_PAUSED
end if

# Update the player state and song name to detect when the track changes
set savedPlayerState to currentPlayerState
set savedTrack to currentTrack

# Write the track main information in the log
log name of current track & ";;" & artist of current track & ";;" & album of current track & ";;" & state & ";;" & player position & ";;" & duration of current track & ";;" & track number of current track & ";;" & track count of current track
end if
end tell
on error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ set STR_PAUSED to "PAUSED"

set state to ""

property savedTrack : missing value
property savedPlayerState : missing value

repeat
delay 1
# If iTunes is not running, set the state to "STOPPED" and do nothing
Expand All @@ -28,23 +25,14 @@ repeat
log state
end if
else
set currentTrack to current track

# If the current song or the player status has changed, log the new track information
if currentPlayerState is not savedPlayerState or currentTrack is not savedTrack then
if currentPlayerState is playing then
set state to STR_PLAYING
else
set state to STR_PAUSED
end if

# Write the track main information in the log
log name of current track & ";;" & artist of current track & ";;" & album of current track & ";;" & state & ";;" & player position & ";;" & duration of current track & ";;" & track number of current track & ";;" & track count of current track
if currentPlayerState is playing then
set state to STR_PLAYING
else
set state to STR_PAUSED
end if

# Update the player state and song name to detect when the track changes
set savedPlayerState to currentPlayerState
set savedTrack to currentTrack

# Write the track main information in the log
log name of current track & ";;" & artist of current track & ";;" & album of current track & ";;" & state & ";;" & player position & ";;" & duration of current track & ";;" & track number of current track & ";;" & track count of current track
end if
end tell
on error
Expand Down
19 changes: 1 addition & 18 deletions src/main/resources/scripts/windows/itunes_track_info_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ var sQuery = "SELECT * FROM Win32_Process WHERE Name = 'iTunes.exe'";
var stderr = WScript.CreateObject("Scripting.FileSystemObject").GetStandardStream(2);

var iTunesApp = null;
var savedTrack = null;
var savedState = null;
var state = "";

function WaitForITunes() {
Expand Down Expand Up @@ -31,10 +29,7 @@ function MainLoop() {
var playerState = iTunesApp.PlayerState;
if(currentTrack == null || playerState == null) {
LogStopped();
} else if(!EqualTracks(currentTrack, savedTrack) || playerState != savedState) {
savedTrack = currentTrack;
savedState = playerState;

} else {
if(playerState == 0) {
state = "PAUSED";
} else {
Expand All @@ -49,8 +44,6 @@ function MainLoop() {
} catch(err) {
// If iTunes stops, reset the variables and do nothing
iTunesApp = null;
savedTrack = null;
savedState = null;
}
}
}
Expand All @@ -63,15 +56,5 @@ function LogStopped() {
}
}

function EqualTracks(track1, track2) {
if((track1 == null && track2 != null) || (track1 != null && track2 == null)) {
return false;
} else if(track1 == null && track2 == null) {
return true;
} else {
return track1.Name == track2.Name && track1.Artist == track2.Artist && track1.Album == track2.Album;
}
}

WaitForITunes();
MainLoop();

0 comments on commit 3a31963

Please sign in to comment.