Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to fetch track artwork as Base 64 #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 90 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,90 @@
node_modules
# Created by https://www.gitignore.io

### OSX ###
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
.nb-gradle/


### Windows ###
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk


### Node ###
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
4 changes: 0 additions & 4 deletions applescripts/ApplicationLib.applescript

This file was deleted.

Binary file removed applescripts/ApplicationLib.scpt
Binary file not shown.
230 changes: 121 additions & 109 deletions applescripts/ITunesTransport.applescript
Original file line number Diff line number Diff line change
@@ -1,142 +1,154 @@
property ApplicationLib : load script POSIX file "ApplicationLib.scpt"
on ApplicationIsRunning(appName)
tell application "System Events" to set appNameIsRunning to exists (processes where name is appName)
return appNameIsRunning
end ApplicationIsRunning

on IsRunning()
tell ApplicationLib
return ApplicationIsRunning("iTunes")
end tell
return ApplicationIsRunning("iTunes")
end IsRunning

on IsPlaying()
tell ApplicationLib
if ApplicationIsRunning("iTunes") then
tell application "iTunes"
return player state is playing
end tell
else
return false
end if
end tell
if ApplicationIsRunning("iTunes") then
tell application "iTunes"
return player state is playing
end tell
else
return false
end if
end IsPlaying

on GetCurrentArt()
if IsPlaying() then
tell application "iTunes"
if not (exists current track) then return null
return (get raw data of artwork 1 of current track)
end tell
else
return "null"
end if
end GetCurrentArt

on GetCurrentTrack()
if IsPlaying() then
tell application "iTunes"
if not (exists current track) then return null
set trackName to (get name of current track)
set trackArtist to (get artist of current track)
set trackAlbum to (get album of current track)
return "{\"name\":\"" & trackName & "\",\"artist\":\"" & trackArtist & "\",\"album\":\"" & trackAlbum & "\"}"
end tell
else
return "null"
end if
if IsPlaying() then
tell application "iTunes"
if not (exists current track) then return null
set trackName to (get name of current track)
set trackArtist to (get artist of current track)
set trackAlbum to (get album of current track)
return "{\"name\":\"" & trackName & "\",\"artist\":\"" & trackArtist & "\",\"album\":\"" & trackAlbum & "\"}"
end tell
else
return "null"
end if
end GetCurrentTrack

on PausePlaying()
if IsRunning() then
tell application "iTunes"
pause
end tell
end if
return "{\"ok\":true}"
if IsRunning() then
tell application "iTunes"
pause
end tell
end if
return "{\"ok\":true}"
end PausePlaying

on StartPlaying()
tell application "iTunes"
launch
play
end tell
return GetCurrentTrack()
tell application "iTunes"
launch
play
end tell
return GetCurrentTrack()
end StartPlaying

on StopPlaying()
if IsRunning() then
tell application "iTunes" to stop
end if
return "{\"ok\":true}"
if IsRunning() then
tell application "iTunes" to stop
end if
return "{\"ok\":true}"
end StopPlaying

on PlayNextTrack()
if not IsRunning() then
tell application "iTunes"
activate
end tell
end if
tell application "iTunes"
next track
end tell
StartPlaying()
if not IsRunning() then
tell application "iTunes"
activate
end tell
end if
tell application "iTunes"
next track
end tell
StartPlaying()
end PlayNextTrack

on PlayPreviousTrack()
if not IsRunning() then
tell application "iTunes"
activate
end tell
end if
tell application "iTunes"
previous track
end tell
StartPlaying()
if not IsRunning() then
tell application "iTunes"
activate
end tell
end if
tell application "iTunes"
previous track
end tell
StartPlaying()
end PlayPreviousTrack

on FadeOut()
if IsRunning() and IsPlaying()
tell application "iTunes"
set originalVol to sound volume
set currentVol to sound volume
repeat with currentVol from sound volume to 0 by -1
set sound volume to currentVol
delay 0.02
end repeat
end tell
StopPlaying()
tell application "iTunes"
set sound volume to originalVol
end tell
end if
if IsRunning() and IsPlaying() then
tell application "iTunes"
set originalVol to sound volume
set currentVol to sound volume
repeat with currentVol from sound volume to 0 by -1
set sound volume to currentVol
delay 0.02
end repeat
end tell
StopPlaying()
tell application "iTunes"
set sound volume to originalVol
end tell
end if
end FadeOut

on FadeIn()
if not IsRunning() then
tell application "iTunes"
activate
end tell
end if
if not IsPlaying() then
tell application "iTunes"
set originalVol to sound volume
set currentVol to 0
set sound volume to 0
play
repeat with currentVol from 0 to originalVol by 1
set sound volume to currentVol
delay 0.02
end repeat
end tell
return GetCurrentTrack()
end if
if not IsRunning() then
tell application "iTunes"
activate
end tell
end if
if not IsPlaying() then
tell application "iTunes"
set originalVol to sound volume
set currentVol to 0
set sound volume to 0
play
repeat with currentVol from 0 to originalVol by 1
set sound volume to currentVol
delay 0.02
end repeat
end tell
return GetCurrentTrack()
end if
end FadeIn

on run argv
set command to item 1 of argv
if command is "currenttrack" then
return GetCurrentTrack()
else if command is "play"
StartPlaying()
else if command is "pause"
PausePlaying()
else if command is "stop"
StopPlaying()
else if command is "next"
PlayNextTrack()
else if command is "previous"
PlayPreviousTrack()
else if command is "fadeout"
FadeOut()
else if command is "fadein"
FadeIn()
else
return "{\"error\":\"Unsupported command\"}"
end if
set command to item 1 of argv
if command is "currenttrack" then
return GetCurrentTrack()
else if command is "play" then
StartPlaying()
else if command is "pause" then
PausePlaying()
else if command is "stop" then
StopPlaying()
else if command is "next" then
PlayNextTrack()
else if command is "previous" then
PlayPreviousTrack()
else if command is "fadeout" then
FadeOut()
else if command is "fadein" then
FadeIn()
else if command is "art" then
return GetCurrentArt()
else
return "{\"error\":\"Unsupported command\"}"
end if
end run
Binary file modified applescripts/ITunesTransport.scpt
Binary file not shown.
4 changes: 2 additions & 2 deletions demo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var t = require('./');
var t = require('./')();
t.on('playing', function(data){ console.dir(data);} );
t.on('paused', function(data){ console.log('paused');} );
t.play();
t.play();
Loading