Script link from the original forum:
http://www.autohotkey.com/board/topic/9 ... bookmarks/
Author: maestrith
Spoiler
Code: Select all
;http://msdn.microsoft.com/en-us/library/windows/desktop/dd564085(v=vs.85).aspx
#SingleInstance,Force
settings:=new xml("settings")
global settings
new mp()
if settings.ssn("//loop").text{
mp.loop()
GuiControl,,Toggle Loop,1
}
if settings.ssn("//shuffle").text{
mp.shuffle()
GuiControl,,Toggle Shuffle,1
}
Menu,rcm,Add,Remove,remove
pos:
global wmp
WinSetTitle,ahk_id%hwnd%,,% wmp.currentmedia.name " - " wmp.controls.currentPositionString()
return
GuiContextMenu:
MouseGetPos,,,,Control
menu,rcm,Delete
text:=SubStr(control,0,1)=2?"Remove Selected":"Remove"
Menu,rcm,Add,%text%,remove
Menu,rcm,Show
return
t(x*){
for a,b in x
list.=b "`n"
ToolTip,%list%
}
m(x*){
for a,b in x
list.=b "`n"
MsgBox,% list
}
listview:
if Asc(ErrorLevel)=67
settings.add(clean(d(1).text) "/" clean(d(2,A_EventInfo).text),{skip:1})
if Asc(ErrorLevel)=99
settings.add(clean(d(1).text) "/" clean(d(2,A_EventInfo).text),{skip:0})
if A_GuiEvent!=Doubleclick
return
lv:
d(2)
track:=LV_GetNext()?LV_GetNext():1
d(1)
if !LV_GetNext()
return
LV_GetText(list,LV_GetNext())
pl:=wmp.playlistcollection.getbyname(list).item(0)
wmp.currentplaylist:=pl
wmp.controls.playitem(pl.item(track-1))
ff:=settings.sn("//" clean(wmp.currentplaylist.name) "/" clean(wmp.controls.currentitem.name) "/*")
d(3),LV_Delete()
while,bm:=ff.item(A_Index-1).text
LV_Add("",bm)
return
wmp_CurrentItemChange(){
global wmp,hwnd,list
if wmp.controls.currentitem.name{
d(2)
n:=wmp.controls.currentitem.getiteminfo("PlaylistIndex")+1
LV_Modify(0,"-select"),LV_Modify(n,"Select Focus Vis")
if (n=LV_GetNext(LV_GetNext()-1,"C"))
wmp.controls.next()
bmch()
}
if settings.ssn("//repeat").text{
if wmp.currentplaylist.name=settings.ssn("//repeat/@playlist").text
if wmp.controls.currentitem.name=settings.ssn("//repeat/@song").text
return
else
{
pl:=wmp.playlistcollection.getbyname(settings.ssn("//repeat/@playlist").text).item(0)
Loop,% pl.Count
if pl.item(A_Index-1).name=settings.ssn("//repeat/@song").text
{
wmp.controls.playitem(pl.item(A_Index-1))
break
}
}
}
WinSetTitle,ahk_id%hwnd%,,% wmp.controls.currentitem.name
}
bmch(){
ff:=settings.sn("//" clean(wmp.currentplaylist.name) "/" clean(wmp.controls.currentitem.name) "/*")
d(3),LV_Delete()
while,bm:=ff.item(A_Index-1).text
LV_Add("",bm)
}
/*
wmp_openStateChange(a){
if a=8
{
if settings.ssn("//repeat").text{
if wmp.currentplaylist.name=settings.ssn("//repeat/@playlist").text
if wmp.controls.currentitem.name=settings.ssn("//repeat/@song").text
m("Nice")
else
t(wmp.controls.currentitem.name,settings.ssn("//repeat/@song").text)
;pl:=wmp.playlistcollection.getbyname(settings.ssn("//repeat/@playlist").text).item(0)
;loop,% pl.Count
;if (pl.item(A_Index-1).name=settings.ssn("//repeat/@song").text){
;wmp.controls.playitem(pl.item(A_Index-1))
;return
;}
;t(settings.ssn("//repeat/@playlist").text,settings.ssn("//repeat/@song").text)
}
}
}
*/
*/
d(x,row="",y=1){
Gui,ListView,SysListView32%x%
row:=row?row:LV_GetNext()
LV_GetText(text,row,y)
info:={num:LV_GetNext(),text:text}
return info
}
remove:
d1:=d(1),d2:=d(2)
if !d1.num
return
pl:=wmp.playlistcollection.getbyname(d1.text).item(0)
if (A_ThisMenuItem="remove selected"&&d2.num){
ll:=[]
while,LV_GetNext()
ll[A_Index]:=lv_getnext(),LV_Modify(LV_GetNext(),"-select")
Loop,% ll.MaxIndex()
pl.removeitem(pl.item(ll[ll.maxindex()-(A_Index-1)]-1))
}
if (A_ThisMenuItem="remove"){
MsgBox,4,Are you sure,Can not be undone
IfMsgBox,Yes
wmp.playlistcollection.remove(pl),populate()
}
mp.showlist(1)
return
GuiEscape:
GuiClose:
settings.add("last",{playlist:wmp.currentplaylist.name,song:wmp.controls.currentitem.name,time:WMP.Controls.currentPosition})
settings.save()
ExitApp
return
class xml{
__New(param*){
ref:=param.1,root:=param.2,file:=param.3
file:=file?file:ref ".xml",root:=!root?ref:root
temp:=ComObjCreate("MSXML2.DOMDocument"),temp.setProperty("SelectionLanguage","XPath")
ifexist %file%
temp.load(file),this.xml:=temp
else
this.xml:=xml.CreateElement(temp,root)
this.file:=file
xml.xk({ref:ref,obj:this})
}
xk(xml=""){
static list:=[]
if IsObject(xml)
return list[xml.ref]:=xml.obj
if !xml
return list
if list[xml]
return list[xml]
}
__Get(x=""){
return this.xml.xml
}
CreateElement(doc,root){
x:=doc.CreateElement(root),doc.AppendChild(x)
return doc
}
add(path="",att="",text="",dup="",find="",under=""){
main:=this.xml.SelectSingleNode("*")
for a,b in find
if found:=main.SelectSingleNode("//" path "[@" a "='" b "']"){
for a,b in att
found.setattribute(a,b)
found.text:=text
return found
}
if under
{
p:=under
new:=this.xml.CreateElement(path),p.AppendChild(new)
for a,b in att
new.SetAttribute(a,b)
if !(text="")
new.text:=text
return new
}
if p:=this.xml.SelectSingleNode(path)
for a,b in att
p.SetAttribute(a,b)
else
{
p:=main
Loop,Parse,path,/
{
total.=A_LoopField "/"
if dup
new:=this.xml.CreateElement(A_LoopField),p.AppendChild(new)
else if !new:=p.SelectSingleNode("//" Trim(total,"/"))
new:=this.xml.CreateElement(A_LoopField),p.AppendChild(new)
p:=new
}
for a,b in att
p.SetAttribute(a,b)
if Text!=""
p.text:=text
}
return p
}
remove(){
this.xml:=""
}
save(){
this.xml.transformNodeToObject(xml.style(),this.xml)
this.xml.save(this.file)
}
transform(){
this.xml.transformNodeToObject(xml.style(),this.xml)
}
ssn(node){
return this.xml.SelectSingleNode(node)
}
sn(node){
return this.xml.SelectNodes(node)
}
style(){
static
if !IsObject(xsl){
xsl:=ComObjCreate("MSXML2.DOMDocument")
style=
(
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:for-each select="@*">
<xsl:text></xsl:text>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
)
xsl.loadXML(style), style:=null
}
return xsl
}
easyatt(node,notext=""){
list:=[],nodes:=sn(node,"@*")
while,n:=nodes.item[A_Index-1]
list[n.nodename]:=n.text
if !notext
list[1]:=node.text
return list
}
}
ssn(node,path){
return node.SelectSingleNode(path)
}
sn(node,path){
return node.SelectNodes(path)
}
clean(x){
return RegExReplace(RegExReplace(x,"[^a-zA-Z]")," ","_")
}
bookmarks:
if A_GuiEvent!=Normal
return
d(3),LV_GetText(pos,LV_GetNext())
wmp.controls.currentPosition:=pos
return
populate(lastpl=""){
global wmp,remember
d(1),LV_Delete()
item:=wmp.playlistcollection.getall()
loop,% wmp.playlistcollection.getall().count
{
i:=item.item(A_Index-1).name
if (lastpl=i)
remember:=A_Index
LV_Add("",i)
}
return remember
}
class mp{
__new(){
static
global hwnd
Gui, +LastFound +hwndhwnd
Hotkey,IfWinActive,ahk_id%hwnd%
Hotkey,^p,PlayPause,On
Gui,Add,ActiveX,xm ym w620 h300 vWMP,WMPLayer.OCX
ComObjConnect(wmp,"wmp_")
Gui,Add,ListView,w200 r15 gshowlist vlist -Multi AltSubmit NoSortHdr,Playlist
Gui,Add,ListView,x+10 w300 r15 glistview AltSubmit NoSortHdr Checked,Songs
Gui,Add,ListView,x+10 w100 r15 gbookmarks AltSubmit,Bookmarks
for a,b in [["","create","Create Playlist","xm"],["","add","Add Content","x+10"]
,["","move","Move Selected Item Up","x+10"],["","mark","Create Bookmark","x+10"],["Checkbox","loop","Toggle Loop","xm"]
,["Checkbox","shuffle","Toggle Shuffle"],["Checkbox","repeat","Toggle Repeat"]]
Gui,Add,% b.1?b.1:"Button",% "gb v" b.2 " " b.4,% b.3
Gui,Add,Text,,1) Create a new playlist`n2) Select the new playlist`n3) Add Content`n4) Double Click on the content to play it`n`nSelect multiple songs, Right click a song to remove it
Gui,Show,AutoSize Center,Player GUI
Gui,ListView,SysListView321
lastpl:=settings.ssn("//last/@playlist").text,d(1)
remember:=populate(lastpl)
lastsong:=settings.ssn("//last/@song").text
if !lastsong
return
d(1),LV_Modify(remember,"Select Focus Vis")
ls:=mp.showlist(lastsong)
if ls
d(2),LV_Modify(ls,"Select Focus Vis")
gosub,lv
wmp.controls.currentPosition:=settings.ssn("//last/@time").text
return
}
showlist(lastsong=""){
showlist:
if (A_GuiEvent!="Normal"&&A_ThisLabel="showlist")
return
next:
d(1)
if !LV_GetNext()
return
d(1),LV_GetText(list,LV_GetNext())
pl:=wmp.playlistcollection.getbyname(list).item(0)
d(2),LV_Delete()
Loop,% pl.count
{
item:=pl.item(A_Index-1).name
if (lastsong=item)
ls:=A_Index
skip:=settings.ssn("//" clean(list) "/" clean(item) "/@skip").text
check:=skip?"Check":""
LV_Add(check,item)
}
LV_ModifyCol(1,"AutoHDR")
return ls
}
add(){
FileSelectFile,file,M,,Select WMP Compatable File:
if Errorlevel
return
if !d(1).num
return
LV_GetText(list,LV_GetNext())
Loop,Parse,file,`n,`n
t:=A_Index=1?dir:=A_LoopField "\":mp.additem(dir A_LoopField,list)
mp.showlist(1)
}
button(){
b:
mp[A_GuiControl]()
return
}
create(){
InputBox,newlist,Create a new playlist,Enter a new playlist name
if !newlist
return
if !wmp.playlistcollection.getbyname(newlist).count
wmp.PlaylistCollection.newPlaylist(newlist),d(1),LV_Delete()
else
m("Please choose another name")
loop,% wmp.playlistcollection.getall().count{
item:=wmp.playlistcollection.getall().item(A_Index-1).name
if (lastpl=item)
remember:=A_Index
LV_Add("",item)
}
}
move(){
pl:=wmp.currentplaylist
if d(2).num>1{
current:=LV_GetNext()
pl.moveitem(current-1,current-2)
mp.showlist(1)
LV_Modify(current-1,"Select Focus Vis")
}
}
mark(){
mark:
if !new:=settings.ssn("//" clean(wmp.currentplaylist.name) "/" clean(wmp.controls.currentitem.name))
settings.add(clean(wmp.currentplaylist.name) "/" clean(wmp.controls.currentitem.name) "/bookmark","",WMP.Controls.currentPosition)
else
settings.add("bookmark","",WMP.Controls.currentPosition,"","",new)
bmch()
return
}
shuffle(){
static
shuffle:=shuffle?0:1
wmp.settings.setmode("shuffle",shuffle)
settings.add("shuffle","",shuffle)
}
loop(){
static
loop:=loop?0:1
wmp.settings.setmode("loop",loop)
settings.add("loop","",loop)
}
additem(file,list){
global wmp
o:=wmp.newMedia(file)
newitem:=wmp.playlistcollection.getbyname(list).item(0)
newitem.appendItem(o)
}
repeat(){
static
repeat:=repeat?0:1
wmp.settings.setmode("repeat",repeat)
settings.add("repeat",{playlist:wmp.currentplaylist.name,song:wmp.controls.currentitem.name},repeat)
}
}
playpause:
if (wmp.status="paused")
wmp.controls.play()
else
wmp.controls.pause()
return