by markstuartwalker » Sat Oct 26, 2013 11:58 am
I'm not sure what you might make of it ...
Code: Select all
procedure DEVICE_NotifyPlaylist( DeviceHandle : integer; M3UFileName, M3UTitle : PWideChar;
TrackCount : integer; Tracks : PWideCharArr); stdcall;
begin
log.text(3,'DEVICE_NotifyPlaylist start',M3UTitle,TrackCount);
try
DeviceiTunesCreatePlaylist( DeviceHandle , M3UFileName, M3UTitle, TrackCount, Tracks);
except
on e: exception do
begin
log.exception('DEVICE_NotifyPlaylist', e);
DeviceInterf.TerminateThreads(DeviceHandle);
end;
end;
log.text(3,'DEVICE_NotifyPlaylist end');
end;
/ create playlists
// this provides a playlist name and an array of tracknames
procedure DeviceiTunesCreatePlaylist(DeviceHandle :Integer ; M3UFileName: PWideChar; M3UTitle: PWideChar;
mmTrackCount: integer; mmTracks: PWideCharArr);
var
pl: iituserplaylist;
// upl: iituserplaylist;
v1,v2: oleVariant;
i,j,firstDifferent: integer;
id: integer;
FQN, DeviceTrackPath: WideString;
itTrack: IITTrack;
itTrackCached: TitTrack;
myApp: IiTunes;
dev:TDevice;
run:Boolean;
begin
log.text(2, 'iTunesCreatePlaylist', M3UTitle);
dev:=DeviceList.getByHandle(DeviceHandle);
if dev=nil then exit;
run:=true;
// take this out of the delete list
// s othat it does not get deleted later
removeFromDeleteList( dev,M3UTitle ) ;
case dev.Config.iTunesMode of
0:
begin
if not dev.g.iTunesRunning then run:=false;
myApp := getiTunesApp();
if myApp=nil then run:=false
end;
end;
if run then
begin
// determine it's full name
FQN := FQname(M3UTitle,dev.Config);
log.text(2, 'Playlist FQN', FQN);
if dev.g.BlackList.onBlacklist(FQN) then
log.text(1, 'Blacklisted doNotCreatePlaylistsFor',dev.Config.doNotCreatePlaylistsFor, FQN)
else
begin
// dump to a text file
case dev.Config.iTunesMode of
0:
begin
// reuse an existing one or create a new one
pl := reuseOrCreatePlaylist(dev,myApp, FQN,dev.config) as IITUserPlaylist;
// upl:=pl as IItUserPlaylist;
// only bother if the lists are different lengths or tracks
// if dev.Config.checkPlaylistsWithSameLength or ( mmTrackCount <> pl.Tracks.count ) then
if differentPlaylists(myApp, pl, mmTrackCount, mmTracks) then
begin
log.text(2, FQN + ' different lengths (MM,iT)', mmTrackCount,
pl.Tracks.count);
// remove any tracks which are differnt
// returns the number of the first different track
firstDifferent:=findFirstDifferentTrack(myApp, pl, mmTrackCount, mmTracks);
// remove all the tracks in the iTunes playlist that we don't need
deleteItPlaylistTracks(pl,firstDifferent,pl.tracks.count);
// and append the outstanding ones to the end of the remaining list
// from the MM playlist to the iTunes playlist
for i := firstDifferent to mmTrackCount do
begin
// read the combined highlow name from the MM list
DeviceTrackPath := mmTracks[i-1];
log.text(2, 'Track name', DeviceTrackPath);
// look it up in the cached iTunes library?
id:=DeviceTrackPathToID(DeviceTrackPath);
itTrackCached :=dev.g.TrackCache.getByTrackID(id);
if itTrackCached <> nil then
begin
itTrack := itTrackCached.itPointer(myApp);
if itTrack <> nil then
begin
for j := 0 to 9 do
begin
// append an existing track to the end of the playlist's list
log.text(2, 'Add track to playlist by ID', DeviceTrackPath);
try
v1 := pl;
v2 := itTrack ;
v1.AddTrack(v2);
// if we got this far then we've succeeded
break ;
except
on e: exception do
log.exception( pl.Name + ' AddTrack(itTrack) ' + inttostr(j) + ' ' + DeviceTrackPath, e);
end;
sleep(100);
end;
end
else
begin
// SHOULD NEVER HAPPEN, ALL FILES SHOULD BE ADDED BY THIS POINT
log.exception('Track='+itTrackCached.name+' not available in iTunes to add to playlist='+FQN+' '+DeviceTrackPath ,nil);
end;
end;
end;
// and shuffle them
if dev.Config.setAllPlaylistsToShuffle then
pl.Shuffle := true;
end
else
log.text(2, M3UTitle + ' same lengths ' + inttostr(mmTrackCount), '(skipped)');
end;
1:
begin
// don't be clever - simply re-create it every time
createM3Ufile(dev.g.TrackCache,
mmTrackCount,
mmTracks,
makeCachePlaylistFilename(dev.Config.cacheFolder,safeFilename(FQN)), //M3UTitle),
(dev.Config.iTunesMode=1));
end;
end;
end;
end;
end;
I'm not sure what you might make of it ...
[code]
procedure DEVICE_NotifyPlaylist( DeviceHandle : integer; M3UFileName, M3UTitle : PWideChar;
TrackCount : integer; Tracks : PWideCharArr); stdcall;
begin
log.text(3,'DEVICE_NotifyPlaylist start',M3UTitle,TrackCount);
try
DeviceiTunesCreatePlaylist( DeviceHandle , M3UFileName, M3UTitle, TrackCount, Tracks);
except
on e: exception do
begin
log.exception('DEVICE_NotifyPlaylist', e);
DeviceInterf.TerminateThreads(DeviceHandle);
end;
end;
log.text(3,'DEVICE_NotifyPlaylist end');
end;
/ create playlists
// this provides a playlist name and an array of tracknames
procedure DeviceiTunesCreatePlaylist(DeviceHandle :Integer ; M3UFileName: PWideChar; M3UTitle: PWideChar;
mmTrackCount: integer; mmTracks: PWideCharArr);
var
pl: iituserplaylist;
// upl: iituserplaylist;
v1,v2: oleVariant;
i,j,firstDifferent: integer;
id: integer;
FQN, DeviceTrackPath: WideString;
itTrack: IITTrack;
itTrackCached: TitTrack;
myApp: IiTunes;
dev:TDevice;
run:Boolean;
begin
log.text(2, 'iTunesCreatePlaylist', M3UTitle);
dev:=DeviceList.getByHandle(DeviceHandle);
if dev=nil then exit;
run:=true;
// take this out of the delete list
// s othat it does not get deleted later
removeFromDeleteList( dev,M3UTitle ) ;
case dev.Config.iTunesMode of
0:
begin
if not dev.g.iTunesRunning then run:=false;
myApp := getiTunesApp();
if myApp=nil then run:=false
end;
end;
if run then
begin
// determine it's full name
FQN := FQname(M3UTitle,dev.Config);
log.text(2, 'Playlist FQN', FQN);
if dev.g.BlackList.onBlacklist(FQN) then
log.text(1, 'Blacklisted doNotCreatePlaylistsFor',dev.Config.doNotCreatePlaylistsFor, FQN)
else
begin
// dump to a text file
case dev.Config.iTunesMode of
0:
begin
// reuse an existing one or create a new one
pl := reuseOrCreatePlaylist(dev,myApp, FQN,dev.config) as IITUserPlaylist;
// upl:=pl as IItUserPlaylist;
// only bother if the lists are different lengths or tracks
// if dev.Config.checkPlaylistsWithSameLength or ( mmTrackCount <> pl.Tracks.count ) then
if differentPlaylists(myApp, pl, mmTrackCount, mmTracks) then
begin
log.text(2, FQN + ' different lengths (MM,iT)', mmTrackCount,
pl.Tracks.count);
// remove any tracks which are differnt
// returns the number of the first different track
firstDifferent:=findFirstDifferentTrack(myApp, pl, mmTrackCount, mmTracks);
// remove all the tracks in the iTunes playlist that we don't need
deleteItPlaylistTracks(pl,firstDifferent,pl.tracks.count);
// and append the outstanding ones to the end of the remaining list
// from the MM playlist to the iTunes playlist
for i := firstDifferent to mmTrackCount do
begin
// read the combined highlow name from the MM list
DeviceTrackPath := mmTracks[i-1];
log.text(2, 'Track name', DeviceTrackPath);
// look it up in the cached iTunes library?
id:=DeviceTrackPathToID(DeviceTrackPath);
itTrackCached :=dev.g.TrackCache.getByTrackID(id);
if itTrackCached <> nil then
begin
itTrack := itTrackCached.itPointer(myApp);
if itTrack <> nil then
begin
for j := 0 to 9 do
begin
// append an existing track to the end of the playlist's list
log.text(2, 'Add track to playlist by ID', DeviceTrackPath);
try
v1 := pl;
v2 := itTrack ;
v1.AddTrack(v2);
// if we got this far then we've succeeded
break ;
except
on e: exception do
log.exception( pl.Name + ' AddTrack(itTrack) ' + inttostr(j) + ' ' + DeviceTrackPath, e);
end;
sleep(100);
end;
end
else
begin
// SHOULD NEVER HAPPEN, ALL FILES SHOULD BE ADDED BY THIS POINT
log.exception('Track='+itTrackCached.name+' not available in iTunes to add to playlist='+FQN+' '+DeviceTrackPath ,nil);
end;
end;
end;
// and shuffle them
if dev.Config.setAllPlaylistsToShuffle then
pl.Shuffle := true;
end
else
log.text(2, M3UTitle + ' same lengths ' + inttostr(mmTrackCount), '(skipped)');
end;
1:
begin
// don't be clever - simply re-create it every time
createM3Ufile(dev.g.TrackCache,
mmTrackCount,
mmTracks,
makeCachePlaylistFilename(dev.Config.cacheFolder,safeFilename(FQN)), //M3UTitle),
(dev.Config.iTunesMode=1));
end;
end;
end;
end;
end;
[/code]