;// #jotify.au3#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;// Author : =|)arkSprout= [June09]
;// Purpose : Spotify Playlist/Album Manager
;// Local Functions:=
;// ReadTextFile()
;// AddToListBox($f_Artist = "", $f_Album = "", $f_Link = "", $f_Tag = "", $f_index = -1)
;// RebuildList($listBox, $cboTags, $tagFilter)
;// SaveFile()
;// Trim($strIn)
;// ShortSpotifyURI($strIn
;// HTTPSpotifyLink($strIn)
;// Not My Functions:=
;// MyGUICtrlCreateListViewItem($sText, $nCtrlID, $nIndex)
;// GetSubItemText($nCtrlID, $nItemID, $nColumn)
;// LVSort2($hWnd, $nItem1, $nItem2, $nColumn)
;// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <GUIListBox.au3>
#include <ComboConstants.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
;#include <Debug.au3>
;_DebugSetup ( "debug_jotify" )
;#AutoIt3Wrapper_icon=jotify.ico
Global $artistArray[1]
Global $albumArray[1]
Global $linksArray[1]
Global $tagsArray[1]
Global $arraySearchIndex
Global $file
;// List Box Globals //
Global $nCurCol = -1
Global $nSortDir = 1
Global $bSet = 0
Global $nCol = -1
_Main()
;==>ExitScrpt
Func _Main()
Local $returnAdd, $strOut, $arraySize, $strCombo
$nCurCol = -1
$nSortDir = 1
$bSet = 0
$nCol = -1
#Region ### START Koda GUI section ### Form=
;// Form //
$frm_jotify = GUICreate("jotify", 740, 445, 192, 124, BitOR($WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS))
;// Menu //
$masterMenu = GUICtrlCreateMenu("Ac&tions")
$mnuImportLinkList = GUICtrlCreateMenuItem("* Import &Link List", $masterMenu)
$mnuSeparator1 = GUICtrlCreateMenuItem("", $masterMenu)
$mnuSortItems = GUICtrlCreateMenu("So&rt", $masterMenu)
$submnuSortArtist = GUICtrlCreateMenuItem("* Sort by &Artist", $mnuSortItems)
$submnuSortAlbum = GUICtrlCreateMenuItem("* Sort by Al&bum", $mnuSortItems)
$submnuSortTags = GUICtrlCreateMenuItem("* Sort by &Tags", $mnuSortItems)
$mnuSeparator2 = GUICtrlCreateMenuItem("", $masterMenu)
$mnuClipHTTP_Link = GUICtrlCreateMenuItem("Copy Spotify UR&L To Clipboard", $masterMenu)
$mnuClipSpotyLink = GUICtrlCreateMenuItem("Copy Spotify UR&I To Clipboard", $masterMenu)
$mnuSeparator3 = GUICtrlCreateMenuItem("", $masterMenu)
$mnuClose = GUICtrlCreateMenuItem("&Close", $masterMenu)
;// List Box //
$listBox = GUICtrlCreateListView("Artist|Album|Spotify Link", 112, 24, 610, 350)
GUICtrlRegisterListViewSort(-1, "LVSort2"); Register the function "SortLV" for the sorting callback
;// Combo Box //
$cboTags = GUICtrlCreateCombo("", 112,389, 225, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
;// Buttons //
$cmdOpen = GUICtrlCreateButton("&Open Link", 16, 32, 81, 41, $BS_DEFPUSHBUTTON)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$cmdEdit = GUICtrlCreateButton("&Edit", 16, 88, 81, 41, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$cmdAdd = GUICtrlCreateButton("&Add", 16, 144, 81, 41, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$cmdDelete = GUICtrlCreateButton("&Delete", 16, 200, 81, 41, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;// Load in text file //
ReadTextFile()
;// Fill list box //
For $x = 1 to UBound($artistArray) -1
MyGUICtrlCreateListViewItem( $artistArray[$x] & "|" & $albumArray[$x] & "|" & $linksArray[$x], $listBox, -1)
Next
;// Fill ComboBox //
GUICtrlSetData($cboTags, "All" & BuildTagList($tagsArray), "All")
;// Main Loop | Wait for button press //
Do
$msg = GUIGetMsg()
;If $msg <> 0 Then _DebugOut($nMsg,1);\\ Track Button Presses
Select
Case $msg = $cboTags;// Filter listBox based on Tag in ComboBox
RebuildList($listBox, $cboTags, GUICtrlRead($cboTags))
Case $msg = $cmdOpen
$arraySearchIndex = _ArraySearch($linksArray, GetSubItemText($listBox,GUICtrlRead($listBox),2))
If $arraySearchIndex > 0 Then
ShellExecute("spotify:" & $linksArray[$arraySearchIndex])
EndIf
Case $msg = $cmdEdit;// Edit Selection
$arraySearchIndex = _ArraySearch($linksArray, GetSubItemText($listBox,GUICtrlRead($listBox),2))
If $arraySearchIndex > 0 Then
$returnAdd = AddToListBox($artistArray[$arraySearchIndex],$albumArray[$arraySearchIndex], _
$linksArray[$arraySearchIndex], $tagsArray[$arraySearchIndex], $arraySearchIndex)
If $returnAdd <> "" Then
GUICtrlSetData($listBox, $returnAdd)
RebuildList($listBox, $cboTags, "All")
EndIf
EndIf
Case $msg = $cmdAdd;// Add to list box
If AddToListBox() = True Then
RebuildList($listBox, $cboTags, "All")
EndIf
Case $msg = $cmdDelete;// Delete Selection
$arraySearchIndex = _ArraySearch($linksArray, GetSubItemText($listBox,GUICtrlRead($listBox),2))
If $arraySearchIndex > 0 Then
If MsgBox(292, "jotify ~ Question", "Are you sure you wish to delete:" & @CRLF & @CRLF & _
$artistArray[$arraySearchIndex] & " - " & $albumArray[$arraySearchIndex] & "?") = 6 Then
_ArrayDelete($artistArray,$arraySearchIndex)
_ArrayDelete($albumArray,$arraySearchIndex)
_ArrayDelete($linksArray,$arraySearchIndex)
_ArrayDelete($tagsArray, $arraySearchIndex)
RebuildList($listBox, $cboTags, "All")
EndIf
EndIf
Case $msg = $listBox
ContinueCase
;// Menu //
Case $msg = $mnuClipHTTP_Link;// Copy HTTTP (hyperlink) version of Spotify Link to the Clipboard
$arraySearchIndex = _ArraySearch($linksArray, GetSubItemText($listBox,GUICtrlRead($listBox),2))
If $arraySearchIndex > 0 Then
ClipPut(HTTPSpotifyLink($linksArray[$arraySearchIndex]))
EndIf
Case $msg = $mnuClipSpotyLink;// Copy Spotify Link {URI) to the Clipboard
$arraySearchIndex = _ArraySearch($linksArray, GetSubItemText($listBox,GUICtrlRead($listBox),2))
If $arraySearchIndex > 0 Then
ClipPut("Spotify:" & ShortSpotifyURI($linksArray[$arraySearchIndex]))
EndIf
Case $msg = $mnuClose;// Close Form Requested
#cs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
This is a Bug I Can't Fix
If ListBox has a selection value of 14 then [Close] is called
$mnuClose - has a value of 14 ???
#ce ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
If GUICtrlRead($listBox) = 14 Then ContinueCase
ExitLoop
EndSelect
Until $msg = $GUI_EVENT_CLOSE
GUIDelete()
SaveFile();// Save Arrays
EndFunc;==>_Main
Func ReadTextFile()
Dim $file
Dim $iMsgBoxAnswer
Dim $loopCount = 1
Dim $splitArray[4]
If Not FileExists("jotify_database.jtb") Then
;// File Missing | Create New? //
$iMsgBoxAnswer = MsgBox(292, "jotify ~ Question","Database File Not Found!" & @CRLF & @CRLF & "Do you wish to create a new one?")
Select
Case $iMsgBoxAnswer = 6;// Yes
$file = FileOpen("jotify_database.jtb", 10);// Create [jotify_database.jtb]
Case Else
Exit
EndSelect
Else
;// File Exists //
$file = FileOpen("jotify_database.jtb", 0)
While 1
$line = FileReadLine($file)
If @error = -1 Then ExitLoop
$splitArray = StringSplit($line,"|")
;// Add to arrays //
_ArrayAdd($artistArray,Trim($splitArray[1]))
_ArrayAdd($albumArray, Trim($splitArray[2]))
_ArrayAdd($linksArray, Trim($splitArray[3]))
_ArrayAdd($tagsArray, Trim($splitArray[4]))
Wend
FileClose($file)
EndIf
EndFunc;==>ReadTextFile
Func AddToListBox($f_Artist = "", $f_Album = "", $f_Link = "", $f_Tag = "", $f_index = -1)
Dim $blComplete
Dim $artist
Dim $album
Dim $link
Dim $tag
$blComplete = False
#Region ### START Koda GUI section ### Form=
$frmInput = GUICreate("Spotify Data Input", 435, 210, 286, 224, BitOR($WS_EX_TOPMOST,$WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS))
$artistInput = GUICtrlCreateInput($f_Artist, 157, 32, 250, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label1 = GUICtrlCreateLabel("Artist", 37, 32, 44, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x008000)
$InputAlbum = GUICtrlCreateInput($f_Album, 157, 65, 250, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label2 = GUICtrlCreateLabel("Album", 37, 65, 53, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x008000)
$inputLink = GUICtrlCreateInput($f_Link, 157, 98, 250, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label3 = GUICtrlCreateLabel("Spotify Link", 35, 98, 95, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x008000)
$inputTags = GUICtrlCreateInput($f_Tag, 157, 131, 250, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetTip(-1,'Seperate by commas for mutible tags ~ e.g. Dance, 1980s, Electro')
$Label4 = GUICtrlCreateLabel("Tag", 35, 131, 95, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x008000)
$cmdCancel = GUICtrlCreateButton("&Cancel", 101, 164, 97, 33, $BS_DEFPUSHBUTTON )
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$cmdDone = GUICtrlCreateButton("&Done", 245, 164, 97, 33, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsgInput = GUIGetMsg()
Switch $nMsgInput
Case $cmdCancel
$blComplete = False
ExitLoop
Case $cmdDone
$blComplete = True
ExitLoop
Case $inputLink
GUICtrlSetData($inputLink, ShortSpotifyURI(GUICtrlRead($inputLink)))
EndSwitch
WEnd
;// Store values before form closes //
$artist = GUICtrlRead($artistInput)
$album = GUICtrlRead($InputAlbum)
$link = GUICtrlRead($inputLink)
$tag = GUICtrlRead($inputTags)
;// Close Form //
GUIDelete()
;// Return value | insert into array //
If $blComplete = True Then
If $f_index = -1 Then
_ArrayAdd($artistArray, $artist);// Add
_ArrayAdd($albumArray, $album)
_ArrayAdd($linksArray, $link)
_ArrayAdd($tagsArray, $tag)
Else
$artistArray[$f_index] = $artist;// Insert
$albumArray[$f_index] = $album
$linksArray[$f_index] = $link
$tagsArray[$f_index] = $tag
EndIf
EndIf
Return $blComplete
EndFunc;==>AddToListBox
;// Delete and rebuild listbox with selected items //
Func RebuildList($listBox, $cboTags, $tagFilter)
Dim $strCombo
GUICtrlDelete($listBox)
GUICtrlDelete($cboTags)
;// Make List Box //
$listBox = GUICtrlCreateListView("Artist|Album|Spotify Link", 112, 24, 610, 350, -1)
GUICtrlRegisterListViewSort(-1, "LVSort2");// Register the function "SortLV" for the sorting callback
;// Fill List Box | filtered by Tag //
For $x = 1 to UBound($artistArray) -1
If $tagFilter = "All" Or StringInStr($tagsArray[$x], $tagFilter, 0) > 0 Then
MyGUICtrlCreateListViewItem( $artistArray[$x] & "|" & $albumArray[$x] & "|" & $linksArray[$x], $listBox, -1)
EndIf
Next
;// Combo Box //
$cboTags = GUICtrlCreateCombo("", 112,389, 225, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
GUICtrlSetData(-1, "All" & BuildTagList($tagsArray), $tagFilter)
EndFunc;==>RebuildList
;// Write back array contents //
Func SaveFile()
Dim $x
$file = FileOpen("jotify_database.jtb", 10);// Overwrite [jotify_database.jtb]
For $x = 1 to UBound($artistArray)-1
If StringLen(Trim($artistArray[$x])) > 0 Then
FileWriteLine($file, $artistArray[$x] & "|" & $albumArray[$x] & "|" & $linksArray[$x] & "|" & $tagsArray[$x] & @CRLF)
EndIf
Next
FileClose($file)
EndFunc;==>SaveFile
;// Build Unique List of all Tags | Buggy as hell not sorting Unique yet! //
Func BuildTagList($arrayIn)
Dim $returnString
$tagsUniqueArray = _ArrayUnique($arrayIn)
For $x = 1 To UBound($tagsUniqueArray) - 1
$splitArray = StringSplit($tagsUniqueArray[$x],",")
For $y = 1 To UBound($splitArray) - 1
$returnString = $returnString & Trim($splitArray[$y]) & "|"
Next
Next
Return $returnString
EndFunc;==>BuildTagList
;// Strip Leading and Trailing White Space //
Func Trim($strIn)
return StringStripWS(StringStripWS($strIn, 1), 2)
EndFunc;==>Trim
Func ShortSpotifyURI($strIn)
;// Shorten URI //
$strIn = StringReplace($strIn,"http://open.spotify.com/","")
$strIn = StringReplace($strIn,"/",":")
$strIn = StringReplace($strIn,"spotify:","")
Return $strIn
EndFunc;==>ShortSpotifyURI
Func HTTPSpotifyLink($strIn)
;// Create HTTP hyperlink //
$strIn = StringReplace($strIn,"http://open.spotify.com/","")
$strIn = StringReplace($strIn,"spotify:","")
$strIn = StringReplace($strIn,":","/")
$strIn = "http://open.spotify.com/" & $strIn
Return $strIn
EndFunc;==>HTTPSpotifyLink
;// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GUI CONTROLS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
;// Create and insert items directly into the listview //
Func MyGUICtrlCreateListViewItem($sText, $nCtrlID, $nIndex)
Local $stLvItem = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int;")
Local $stText = DllStructCreate("char[260]")
Local $arText = StringSplit($sText, "|")
If $nIndex = -1 Then $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_GETITEMCOUNT, 0, 0)
DllStructSetData($stText, 1, $arText[1]);// Save the item text in the struct
DllStructSetData($stLvItem, 1, BitOR($LVIF_TEXT, $LVIF_PARAM))
DllStructSetData($stLvItem, 2, $nIndex)
DllStructSetData($stLvItem, 6, DllStructGetPtr($stText))
;// Set the lParam of the struct to the line index - unique within the listview //
DllStructSetData($stLvItem, 9, $nIndex)
$nIndex = GUICtrlSendMsg($nCtrlID, $LVM_INSERTITEMA, 0, DllStructGetPtr($stLvItem))
If $nIndex > -1 Then
;// Insert now the rest of the column text //
For $i = 2 To $arText[0]
DllStructSetData($stText, 1, $arText[$i])
DllStructSetData($stLvItem, 3, $i - 1);// Store the subitem index
GUICtrlSendMsg($nCtrlID, $LVM_SETITEMTEXTA, $nIndex, DllStructGetPtr($stLvItem))
Next
EndIf
$stText = 0
$stLvItem = 0
;// Change the column width to fit the item text //
For $i = 0 To 2
GUICtrlSendMsg($nCtrlID, $LVM_SETCOLUMNWIDTH, $i, -1)
GUICtrlSendMsg($nCtrlID, $LVM_SETCOLUMNWIDTH, $i, -2)
Next
EndFunc ;==>MyGUICtrlCreateListViewItem
;// Retrieve the text of a listview item in a specified column //
Func GetSubItemText($nCtrlID, $nItemID, $nColumn)
Local $stLvfi = DllStructCreate("uint;ptr;int;int[2];int")
Local $nIndex, $stBuffer, $stLvi, $sItemText
DllStructSetData($stLvfi, 1, $LVFI_PARAM)
DllStructSetData($stLvfi, 3, $nItemID)
$stBuffer = DllStructCreate("char[260]")
$nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi));
$stLvi = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int")
DllStructSetData($stLvi, 1, $LVIF_TEXT)
DllStructSetData($stLvi, 2, $nIndex)
DllStructSetData($stLvi, 3, $nColumn)
DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer))
DllStructSetData($stLvi, 7, 260)
GUICtrlSendMsg($nCtrlID, $LVM_GETITEMA, 0, DllStructGetPtr($stLvi));
$sItemText = DllStructGetData($stBuffer, 1)
$stLvi = 0
$stLvfi = 0
$stBuffer = 0
Return $sItemText
EndFunc ;==>GetSubItemText
;// Our sorting callback funtion //
Func LVSort2($hWnd, $nItem1, $nItem2, $nColumn)
Local $nSort, $val1, $val2, $nResult
;// Switch the sorting direction //
If $nColumn = $nCurCol Then
If Not $bSet Then
$nSortDir = $nSortDir * - 1
$bSet = 1
EndIf
Else
$nSortDir = 1
EndIf
$nCol = $nColumn
$val1 = GetSubItemText($hWnd, $nItem1, $nColumn)
$val2 = GetSubItemText($hWnd, $nItem2, $nColumn)
;// If it is the 3rd colum (column starts with 0) then compare the dates //
If $nColumn = 2 Then
$val1 = StringRight($val1, 4) & StringMid($val1, 4, 2) & StringLeft($val1, 2)
$val2 = StringRight($val2, 4) & StringMid($val2, 4, 2) & StringLeft($val2, 2)
EndIf
$nResult = 0;// No change of item1 and item2 positions
If $val1 < $val2 Then
$nResult = -1;// Put item2 before item1
ElseIf $val1 > $val2 Then
$nResult = 1;// Put item2 behind item1
EndIf
$nResult = $nResult * $nSortDir
Return $nResult
EndFunc ;==>LVSort2