by onkel_enno » Tue Jan 10, 2006 6:48 am
New Version of my RemoveFromPlayList-Script
Code: Select all
option explicit
'#################################################
' Language Constants
'#################################################
const strRemoveFrom = "Entfernen aus ..."
const strConfirmation = "Wirklich alle %1 Titel aus Playliste '%2' löschen?" '%1=Number of Files, %2 = Playlist-Name
'#################################################
' Object-Names (for future use)
'#################################################
const strObjNP = "RemoveFromPlaylistNP" 'unique Object Name of SubMenu and Dictionary in Now Playing-Menu
const strObjTray = "RemoveFromPlaylistTray" 'unique Object Name of SubMenu and Dictionary in TrayIcon-SubMenu
const strObjMain = "RemoveFromPlaylistMain" 'unique Object Name of SubMenu and Dictionary in MainMenuIcon-SubMenu
'#################################################
' Start-Up Function (Create Main-Menu)
'#################################################
Sub OnStartUp
dim MenuItem
'Adds Menu to Now Playing
set MenuItem = SDB.Objects("mnu" & strObjNP)
if MenuItem is nothing then
set MenuItem = SDB.UI.AddMenuItemSub(SDB.UI.Menu_Pop_NP, 3, 2)
MenuItem.IconIndex = 56
MenuItem.Caption =strRemoveFrom 'SDB.Localize("Remove") & " ..."
MenuItem.Hint = Mid("mnu" & strObjNP, 4)
MenuItem.Enabled = True
MenuItem.UseScript = Script.ScriptPath
MenuItem.OnClickFunc = "AddPlaylists"
SDB.Objects("mnu" & strObjNP) = MenuItem
end if
Set MenuItem = Nothing
'Adds Menu to Tray Icon
set MenuItem = SDB.Objects("mnu" & strObjTray)
if MenuItem is nothing then
SDB.UI.AddMenuItemSep SDB.UI.Menu_TrayIcon, -2, -1
set MenuItem = SDB.UI.AddMenuItemSub(SDB.UI.Menu_TrayIcon, -2, -1) 'vorletzte Sektion, letzter Eintrag
MenuItem.IconIndex = 56
MenuItem.Caption = strRemoveFrom 'SDB.Localize("Remove") & " ..."
MenuItem.Hint = Mid("dic" & strObjTray, 4)
MenuItem.Enabled = True
MenuItem.UseScript = Script.ScriptPath
MenuItem.OnClickFunc = "AddPlaylists"
SDB.Objects("mnu" & strObjTray) = MenuItem
end if
Set MenuItem = Nothing
'Adds Menu to Main Track Window
set MenuItem = SDB.Objects("mnu" & strObjMain)
if MenuItem is nothing then
SDB.UI.AddMenuItemSep SDB.UI.Menu_Pop_TrackList, -2, -1
set MenuItem = SDB.UI.AddMenuItemSub(SDB.UI.Menu_Pop_TrackList, -2, -1) 'vorletzte Sektion, letzter Eintrag
MenuItem.IconIndex = 56
MenuItem.Caption = strRemoveFrom 'SDB.Localize("Remove") & " ..."
MenuItem.Hint = Mid("dic" & strObjMain, 4)
MenuItem.Enabled = True
MenuItem.UseScript = Script.ScriptPath
MenuItem.OnClickFunc = "AddPlaylists"
SDB.Objects("mnu" & strObjTray) = MenuItem
end if
Set MenuItem = Nothing
end Sub
'#################################################
' Add Sub-Menus (Playlists)
'#################################################
Sub AddPlaylists(Item)
dim SubMenuItem
dim dsPlaylist
Dim Song
Dim SongIDs()
dim itm
dim PlaylistID
dim PlaylistName
dim Terms
Dim TermsSep
dim strObjMenu
strObjMenu = "mnu" & Item.Hint
dim strObjDictMenu
strObjDictMenu = "dic" & Item.Hint
'Dictionary for Playlisten-IDs
'-> to know which Menu-Entries are already created
dim DictRemoveFromPlaylist
set DictRemoveFromPlaylist = SDB.Objects(strObjDictMenu)
if DictRemoveFromPlaylist is nothing then
Set DictRemoveFromPlaylist = CreateObject("Scripting.Dictionary")
SDB.Objects(strObjDictMenu) = DictRemoveFromPlaylist
end if
'Disable all Playlists
Dim ObjectNames
ObjectNames = DictRemoveFromPlaylist.Items
for itm = 0 to DictRemoveFromPlaylist.Count - 1
SDB.Objects(ObjectNames(itm)).Enabled = False
next
if strObjMenu = "mnu" & strObjNP then
Redim SongIDs(SDB.SelectedSongList.Count)
for itm=0 to SDB.SelectedSongList.Count-1
SongIDs(itm+1) = SDB.SelectedSongList.Item(itm).ID
next
elseif strObjMenu = "mnu" & strObjTray then
Redim SongIDs(1)
SongIDs(1) = SDB.Player.CurrentSong.ID
elseif strObjMenu = "mnu" & strObjMain then
Redim SongIDs(1)
Redim SongIDs(SDB.SelectedSongList.Count)
for itm=0 to SDB.SelectedSongList.Count-1
SongIDs(itm+1) = SDB.SelectedSongList.Item(itm).ID
next
end if
If Ubound(SongIDs)>0 then
for itm=1 to Ubound(SongIDs)
Song = SongIDs(itm)
if terms = "" then
terms = Song
else
terms = terms & " OR IDSong = " & Song
end if
TermsSep = "|" & Song & TermsSep
next
TermsSep = Mid(TermsSep, 2)
'only Playlists that include these Songs
set dsPlaylist = SDB.Database.OpenSQL("SELECT Playlists.IDPlaylist, Playlists.PlaylistName, x.IDPlaylist as vorhanden FROM Playlists INNER JOIN (SELECT PlaylistSongs.IDPlaylist FROM PlaylistSongs WHERE PlaylistSongs.IDSong=" & terms & " GROUP BY PlaylistSongs.IDPlaylist) as X ON x.IDPlaylist=Playlists.IDPlaylist where Playlists.IsAutoPlaylist is null GROUP BY Playlists.IDPlaylist, Playlists.PlaylistName, x.IDPlaylist")
'all Playlists
'set dsPlaylist = SDB.Database.OpenSQL("SELECT Playlists.IDPlaylist, Playlists.PlaylistName, x.IDPlaylist as vorhanden FROM Playlists INNER JOIN (SELECT PlaylistSongs.IDPlaylist FROM PlaylistSongs WHERE PlaylistSongs.IDSong=" & terms & " GROUP BY PlaylistSongs.IDPlaylist) as X ON x.IDPlaylist=Playlists.IDPlaylist where Playlists.IsAutoPlaylist is null GROUP BY Playlists.IDPlaylist, Playlists.PlaylistName, x.IDPlaylist")
while not dsPlaylist.EoF
PlaylistID = dsPlaylist.StringByIndex(0)
PlaylistName = dsPlaylist.StringByIndex(1)
If DictRemoveFromPlaylist.Exists(PlaylistID) then
set SubMenuItem = SDB.Objects(strObjMenu & PlaylistID)
else
set SubMenuItem=SDB.UI.AddMenuItem(Item, 1, 1 )
SubMenuItem.Caption = PlaylistName
SubMenuItem.IconIndex = 17
SubMenuItem.useScript = Script.ScriptPath
DictRemoveFromPlaylist.Add PlaylistID, strObjMenu & PlaylistID
SDB.Objects(strObjMenu & PlaylistID) = SubMenuItem
end if
if dsPlaylist.StringByIndex(2)="" then
'Playlist doesn't include the Title
SubMenuItem.Enabled=False
else
SubMenuItem.Hint = PlaylistID & "|" & Ubound(SongIDs) & "|" & TermsSep 'Playliste, Anzahl Songs, Songs
SubMenuItem.OnClickFunc = "DeleteFromPlaylist"
SubMenuItem.Enabled=True
end if
dsPlaylist.next
wend
Set dsPlaylist = Nothing
End If
Set DictRemoveFromPlaylist = Nothing
end Sub
'#################################################
' Delete selected Tracks from Playlist
'#################################################
Sub DeleteFromPlaylist(Item)
Dim Params
dim Tracklist
dim Song
dim SongItem
dim terms
dim ReallyDo
Params = Split(Item.Hint, "|")
if Params(1)>0 then
if Params(1)>1 then
ReallyDo = (SDB.MessageBox(Replace(Replace(strConfirmation, "%2", Item.Caption), "%1", Params(1)), mtConfirmation, Array(mbYes, mbNo)) = mrYes)
else
ReallyDo = True
end if
if ReallyDo then
for SongItem=2 to Ubound(Params)
'Skip if currently playing
if SDB.Player.CurrentSong.ID = Int(Params(SongItem)) then SDB.Player.Next
'Remove from Now Playing
DeleteFromNowPlaying Params(SongItem) 'Song.ID =! Index in Playlist
if terms = "" then
terms = Params(SongItem)
else
terms = terms & " OR IDSong = " & Params(SongItem)
end if
next
'Remove from Playlist
SDB.DataBase.ExecSQL("Delete from PlaylistSongs WHERE IDPlaylist=" & Params(0) & " and (IDSong = " & terms & ")")
SDB.MainTracksWindow.Refresh
end if
end if
end Sub
'#################################################
' Delete Track from Now Playing
'#################################################
Sub DeleteFromNowPlaying(IDSong)
dim Tracklist
dim SongItem
IDSong=Int(IDSong)
Set Tracklist = SDB.Player.CurrentSongList
if Tracklist.Count>0 then
for SongItem=Tracklist.Count-1 to 0 Step -1 'Count down
if Tracklist.Item(SongItem).ID = IDSong then
SDB.Player.PlaylistDelete(SongItem)
end if
next
end if
end Sub
New Version of my RemoveFromPlayList-Script :lol:
[code]
option explicit
'#################################################
' Language Constants
'#################################################
const strRemoveFrom = "Entfernen aus ..."
const strConfirmation = "Wirklich alle %1 Titel aus Playliste '%2' löschen?" '%1=Number of Files, %2 = Playlist-Name
'#################################################
' Object-Names (for future use)
'#################################################
const strObjNP = "RemoveFromPlaylistNP" 'unique Object Name of SubMenu and Dictionary in Now Playing-Menu
const strObjTray = "RemoveFromPlaylistTray" 'unique Object Name of SubMenu and Dictionary in TrayIcon-SubMenu
const strObjMain = "RemoveFromPlaylistMain" 'unique Object Name of SubMenu and Dictionary in MainMenuIcon-SubMenu
'#################################################
' Start-Up Function (Create Main-Menu)
'#################################################
Sub OnStartUp
dim MenuItem
'Adds Menu to Now Playing
set MenuItem = SDB.Objects("mnu" & strObjNP)
if MenuItem is nothing then
set MenuItem = SDB.UI.AddMenuItemSub(SDB.UI.Menu_Pop_NP, 3, 2)
MenuItem.IconIndex = 56
MenuItem.Caption =strRemoveFrom 'SDB.Localize("Remove") & " ..."
MenuItem.Hint = Mid("mnu" & strObjNP, 4)
MenuItem.Enabled = True
MenuItem.UseScript = Script.ScriptPath
MenuItem.OnClickFunc = "AddPlaylists"
SDB.Objects("mnu" & strObjNP) = MenuItem
end if
Set MenuItem = Nothing
'Adds Menu to Tray Icon
set MenuItem = SDB.Objects("mnu" & strObjTray)
if MenuItem is nothing then
SDB.UI.AddMenuItemSep SDB.UI.Menu_TrayIcon, -2, -1
set MenuItem = SDB.UI.AddMenuItemSub(SDB.UI.Menu_TrayIcon, -2, -1) 'vorletzte Sektion, letzter Eintrag
MenuItem.IconIndex = 56
MenuItem.Caption = strRemoveFrom 'SDB.Localize("Remove") & " ..."
MenuItem.Hint = Mid("dic" & strObjTray, 4)
MenuItem.Enabled = True
MenuItem.UseScript = Script.ScriptPath
MenuItem.OnClickFunc = "AddPlaylists"
SDB.Objects("mnu" & strObjTray) = MenuItem
end if
Set MenuItem = Nothing
'Adds Menu to Main Track Window
set MenuItem = SDB.Objects("mnu" & strObjMain)
if MenuItem is nothing then
SDB.UI.AddMenuItemSep SDB.UI.Menu_Pop_TrackList, -2, -1
set MenuItem = SDB.UI.AddMenuItemSub(SDB.UI.Menu_Pop_TrackList, -2, -1) 'vorletzte Sektion, letzter Eintrag
MenuItem.IconIndex = 56
MenuItem.Caption = strRemoveFrom 'SDB.Localize("Remove") & " ..."
MenuItem.Hint = Mid("dic" & strObjMain, 4)
MenuItem.Enabled = True
MenuItem.UseScript = Script.ScriptPath
MenuItem.OnClickFunc = "AddPlaylists"
SDB.Objects("mnu" & strObjTray) = MenuItem
end if
Set MenuItem = Nothing
end Sub
'#################################################
' Add Sub-Menus (Playlists)
'#################################################
Sub AddPlaylists(Item)
dim SubMenuItem
dim dsPlaylist
Dim Song
Dim SongIDs()
dim itm
dim PlaylistID
dim PlaylistName
dim Terms
Dim TermsSep
dim strObjMenu
strObjMenu = "mnu" & Item.Hint
dim strObjDictMenu
strObjDictMenu = "dic" & Item.Hint
'Dictionary for Playlisten-IDs
'-> to know which Menu-Entries are already created
dim DictRemoveFromPlaylist
set DictRemoveFromPlaylist = SDB.Objects(strObjDictMenu)
if DictRemoveFromPlaylist is nothing then
Set DictRemoveFromPlaylist = CreateObject("Scripting.Dictionary")
SDB.Objects(strObjDictMenu) = DictRemoveFromPlaylist
end if
'Disable all Playlists
Dim ObjectNames
ObjectNames = DictRemoveFromPlaylist.Items
for itm = 0 to DictRemoveFromPlaylist.Count - 1
SDB.Objects(ObjectNames(itm)).Enabled = False
next
if strObjMenu = "mnu" & strObjNP then
Redim SongIDs(SDB.SelectedSongList.Count)
for itm=0 to SDB.SelectedSongList.Count-1
SongIDs(itm+1) = SDB.SelectedSongList.Item(itm).ID
next
elseif strObjMenu = "mnu" & strObjTray then
Redim SongIDs(1)
SongIDs(1) = SDB.Player.CurrentSong.ID
elseif strObjMenu = "mnu" & strObjMain then
Redim SongIDs(1)
Redim SongIDs(SDB.SelectedSongList.Count)
for itm=0 to SDB.SelectedSongList.Count-1
SongIDs(itm+1) = SDB.SelectedSongList.Item(itm).ID
next
end if
If Ubound(SongIDs)>0 then
for itm=1 to Ubound(SongIDs)
Song = SongIDs(itm)
if terms = "" then
terms = Song
else
terms = terms & " OR IDSong = " & Song
end if
TermsSep = "|" & Song & TermsSep
next
TermsSep = Mid(TermsSep, 2)
'only Playlists that include these Songs
set dsPlaylist = SDB.Database.OpenSQL("SELECT Playlists.IDPlaylist, Playlists.PlaylistName, x.IDPlaylist as vorhanden FROM Playlists INNER JOIN (SELECT PlaylistSongs.IDPlaylist FROM PlaylistSongs WHERE PlaylistSongs.IDSong=" & terms & " GROUP BY PlaylistSongs.IDPlaylist) as X ON x.IDPlaylist=Playlists.IDPlaylist where Playlists.IsAutoPlaylist is null GROUP BY Playlists.IDPlaylist, Playlists.PlaylistName, x.IDPlaylist")
'all Playlists
'set dsPlaylist = SDB.Database.OpenSQL("SELECT Playlists.IDPlaylist, Playlists.PlaylistName, x.IDPlaylist as vorhanden FROM Playlists INNER JOIN (SELECT PlaylistSongs.IDPlaylist FROM PlaylistSongs WHERE PlaylistSongs.IDSong=" & terms & " GROUP BY PlaylistSongs.IDPlaylist) as X ON x.IDPlaylist=Playlists.IDPlaylist where Playlists.IsAutoPlaylist is null GROUP BY Playlists.IDPlaylist, Playlists.PlaylistName, x.IDPlaylist")
while not dsPlaylist.EoF
PlaylistID = dsPlaylist.StringByIndex(0)
PlaylistName = dsPlaylist.StringByIndex(1)
If DictRemoveFromPlaylist.Exists(PlaylistID) then
set SubMenuItem = SDB.Objects(strObjMenu & PlaylistID)
else
set SubMenuItem=SDB.UI.AddMenuItem(Item, 1, 1 )
SubMenuItem.Caption = PlaylistName
SubMenuItem.IconIndex = 17
SubMenuItem.useScript = Script.ScriptPath
DictRemoveFromPlaylist.Add PlaylistID, strObjMenu & PlaylistID
SDB.Objects(strObjMenu & PlaylistID) = SubMenuItem
end if
if dsPlaylist.StringByIndex(2)="" then
'Playlist doesn't include the Title
SubMenuItem.Enabled=False
else
SubMenuItem.Hint = PlaylistID & "|" & Ubound(SongIDs) & "|" & TermsSep 'Playliste, Anzahl Songs, Songs
SubMenuItem.OnClickFunc = "DeleteFromPlaylist"
SubMenuItem.Enabled=True
end if
dsPlaylist.next
wend
Set dsPlaylist = Nothing
End If
Set DictRemoveFromPlaylist = Nothing
end Sub
'#################################################
' Delete selected Tracks from Playlist
'#################################################
Sub DeleteFromPlaylist(Item)
Dim Params
dim Tracklist
dim Song
dim SongItem
dim terms
dim ReallyDo
Params = Split(Item.Hint, "|")
if Params(1)>0 then
if Params(1)>1 then
ReallyDo = (SDB.MessageBox(Replace(Replace(strConfirmation, "%2", Item.Caption), "%1", Params(1)), mtConfirmation, Array(mbYes, mbNo)) = mrYes)
else
ReallyDo = True
end if
if ReallyDo then
for SongItem=2 to Ubound(Params)
'Skip if currently playing
if SDB.Player.CurrentSong.ID = Int(Params(SongItem)) then SDB.Player.Next
'Remove from Now Playing
DeleteFromNowPlaying Params(SongItem) 'Song.ID =! Index in Playlist
if terms = "" then
terms = Params(SongItem)
else
terms = terms & " OR IDSong = " & Params(SongItem)
end if
next
'Remove from Playlist
SDB.DataBase.ExecSQL("Delete from PlaylistSongs WHERE IDPlaylist=" & Params(0) & " and (IDSong = " & terms & ")")
SDB.MainTracksWindow.Refresh
end if
end if
end Sub
'#################################################
' Delete Track from Now Playing
'#################################################
Sub DeleteFromNowPlaying(IDSong)
dim Tracklist
dim SongItem
IDSong=Int(IDSong)
Set Tracklist = SDB.Player.CurrentSongList
if Tracklist.Count>0 then
for SongItem=Tracklist.Count-1 to 0 Step -1 'Count down
if Tracklist.Item(SongItem).ID = IDSong then
SDB.Player.PlaylistDelete(SongItem)
end if
next
end if
end Sub
[/code]