From 714fbaa394abf4c8fa73654923b8ff74be206e4e Mon Sep 17 00:00:00 2001 From: philpw99 Date: Thu, 21 Oct 2021 21:09:56 -0400 Subject: [PATCH] v1.3 better scraper manager --- Forms/CustomForm.au3 | 22 +- Forms/InitialSettingsForm.au3 | 2 + Forms/Scrapers.isf | 103 +++++++-- Forms/ScrapersForm.au3 | 406 +++++++++++++++++++++++----------- Forms/SettingsForm.au3 | 13 +- Stash_Helper.au3 | 9 +- Stash_Helper.isn | Bin 3478 -> 3414 bytes 7 files changed, 397 insertions(+), 158 deletions(-) diff --git a/Forms/CustomForm.au3 b/Forms/CustomForm.au3 index eeb38ac..e079c8e 100644 --- a/Forms/CustomForm.au3 +++ b/Forms/CustomForm.au3 @@ -12,8 +12,13 @@ Func CustomList($sCategory, ByRef $aCategory) ; aCategory is the array that contains Item_Handle, Item_Title, Item_Link ; Global Enum $ITEM_HANDLE, $ITEM_TITLE, $ITEM_LINK ; Global $iMaxSubItems + + + ; Disable the tray clicks + TraySetClick(0) - $Custom = GUICreate("Customize " & $sCategory,1060,800,-1,-1,-1,-1) + $guiCustom = GUICreate("Customize " & $sCategory,1060,800,-1,-1,-1,-1) + GUISetIcon("helper2.ico") GUICtrlCreateLabel("Customize the list of " & $sCategory & _ ". This is like bookmarks or favorites for Stash. You paste the link from the address bar, then put a title for it, as the examples you see below." _ @@ -57,14 +62,21 @@ Func CustomList($sCategory, ByRef $aCategory) _GUICtrlListView_AddSubItem($customList, $i, $aCategory[$i][$ITEM_LINK], 2) Next - GUISetState(@SW_SHOW, $Custom) + GUISetState(@SW_SHOW, $guiCustom) ; Make list view editable $iLV_Index = _GUIListViewEx_Init($customList, $aList, 0, 0, True, 2) _GUIListViewEx_SetEditStatus($iLV_Index, "1;2", 1, Default) _GUIListViewEx_MsgRegister(True, False, False) ; Now do the loop - While True + While True + ; if click on tray icon, activate the current GUI + $nTrayMsg = TrayGetMsg() + Switch $nTrayMsg + Case $TRAY_EVENT_PRIMARYDOWN, $TRAY_EVENT_SECONDARYDOWN + WinActivate($guiCustom) + EndSwitch + $nMsg = GUIGetMsg() Switch $nMsg Case 0 @@ -88,7 +100,9 @@ Func CustomList($sCategory, ByRef $aCategory) _GUIListViewEx_EventMonitor() Wend - GUIDelete($Custom) + GUIDelete($guiCustom) $customList = 0 + ; restore the tray icon functions. + TraySetClick(9) EndFunc diff --git a/Forms/InitialSettingsForm.au3 b/Forms/InitialSettingsForm.au3 index 671cbc2..0135515 100644 --- a/Forms/InitialSettingsForm.au3 +++ b/Forms/InitialSettingsForm.au3 @@ -12,6 +12,8 @@ Func InitialSettingsForm() ; Create the whole initial setting's GUI $Initial_Settings = GUICreate("Initial Settings",1326,809,-1,-1,-1,-1) + GUISetIcon("helper2.ico") + $tab = GUICtrlCreatetab(41,70,1232,661,-1,-1) GuiCtrlSetState(-1,2048) GUICtrlSetFont(-1,12,400,0,"Tahoma") diff --git a/Forms/Scrapers.isf b/Forms/Scrapers.isf index c0e6644..a83e860 100644 --- a/Forms/Scrapers.isf +++ b/Forms/Scrapers.isf @@ -4,11 +4,12 @@ #include #Include #include +#include If Not (@Compiled ) Then DllCall("User32.dll","bool","SetProcessDPIAware") -$Scrapers = GUICreate("Scrapers Management",1703,1434,-1,-1,$WS_SIZEBOX,-1) -$scraperList = GUICtrlCreatelistview("Website|Scraper|Scene|Gallery|Movie|Performers|Installed|ExtraReq|Contents",40,330,1621,1056,-1,BitOr($LVS_EX_FULLROWSELECT,$LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES,$LVS_EX_DOUBLEBUFFER,$WS_EX_CLIENTEDGE)) +$Scrapers = GUICreate("Scrapers Management",1703,1438,-1,-1,$WS_SIZEBOX,-1) +$scraperList = GUICtrlCreatelistview("Website|Scraper|Scene|Gallery|Movie|Performers|Installed|ExtraReq|Contents",40,290,1621,1056,-1,BitOr($LVS_EX_FULLROWSELECT,$LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES,$LVS_EX_DOUBLEBUFFER,$WS_EX_CLIENTEDGE)) GUICtrlSetFont(-1,10,400,0,"Tahoma") GUICtrlSetResizing(-1,102) ; Website @@ -32,18 +33,24 @@ _GUICtrlListView_SetColumnWidth($scraperList, 6, 130) _GUICtrlListView_JustifyColumn($scraperList, 6, 2) GUICtrlCreateListViewItem("1000facials.com|GammaEntertainment.yml|√|x|x|x|No", $scraperList) -GUICtrlCreateLabel("Scrapers can fetch information about your scenes, studios, performers, tags...etc."&@crlf&"With scrapers, you don't need to type in the information manually any more."&@crlf&" * For performers, you can fetch the info by her/his name."&@crlf&" * For scenes, you put in the URL for that scene, and the scraper can get all the details, including performers, tags, front cover... for that scene."&@crlf&"Therefore, managing scrapers are important for Stash. You don't want too many scrapers, yet you need them to categorize and label your videos quickly."&@crlf&"Here I am trying to give you an easy way to manage the plugins.",240,30,1040,233,-1,-1) +GUICtrlCreateLabel("Scrapers can fetch information about your scenes, studios, performers, tags...etc. With scrapers, you don't need to type in the information manually any more."&@crlf&" * For performers, you can fetch the info by her/his name."&@crlf&" * For scenes, you put in the URL for that scene, and the scraper can get all the details, including performers, tags, front cover... for that scene."&@crlf&"Therefore, managing scrapers are important for Stash. You don't want too many scrapers, yet you need them to categorize and label your videos quickly.",54,30,1597,205,-1,-1) GUICtrlSetFont(-1,10,400,0,"Tahoma") GUICtrlSetBkColor(-1,"-2") -GUICtrlSetResizing(-1,928) -GUICtrlCreateButton("Install",1065,252,167,49,-1,-1) +GUICtrlSetResizing(-1,38) +GUICtrlCreateButton("Install",1065,212,167,49,-1,-1) GUICtrlSetFont(-1,12,400,0,"Tahoma") GUICtrlSetTip(-1,"Install the scrapers with check marks.") GUICtrlSetResizing(-1,804) -GUICtrlCreateButton("Remove",1298,252,167,49,-1,-1) +GUICtrlCreateButton("Remove",1298,212,167,49,-1,-1) GUICtrlSetFont(-1,12,400,0,"Tahoma") GUICtrlSetTip(-1,"Remove the scrapers with check marks.") GUICtrlSetResizing(-1,804) +$inputFilter = GUICtrlCreateInput("",42,218,570,35,-1,$WS_EX_CLIENTEDGE) +GUICtrlSetFont(-1,10,400,0,"Tahoma") +GUICtrlSetResizing(-1,550) +$btnFilter = GUICtrlCreateButton("Find",640,220,148,33,-1,-1) +GUICtrlSetFont(-1,10,400,0,"Tahoma") +GUICtrlSetResizing(-1,804) @@ -53,7 +60,7 @@ Handle_deklaration=default Handle_deklaration_const=false title=Scrapers Management breite=1703 -hoehe=1434 +hoehe=1438 style=$WS_SIZEBOX exstyle=-1 bgcolour=0xF0F0F0 @@ -84,13 +91,13 @@ gui_event_resized= gui_event_dropped= defaultfont=MS Sans Serif defaultfontsize=8 -[0x0016221A] +[0x002B20DA] type=listview handle=432 locked=0 resize=102 x=40 -y=330 +y=290 width=1621 height=1056 func= @@ -113,15 +120,15 @@ tabpage=-1 iconindex= iconlarge=0 textmode=text -[0x000E20CA] +[0x00232366] type=label handle=433 locked=0 -resize=928 -x=240 +resize=38 +x=54 y=30 -width=1040 -height=233 +width=1597 +height=205 func= font=Tahoma fontsize=10 @@ -131,7 +138,7 @@ tooltip= bgimage= textcolour=0x000000 id= -text=Scrapers can fetch information about your scenes, studios, performers, tags...etc.[BREAK]With scrapers, you don't need to type in the information manually any more.[BREAK] * For performers, you can fetch the info by her/his name.[BREAK] * For scenes, you put in the URL for that scene, and the scraper can get all the details, including performers, tags, front cover... for that scene.[BREAK]Therefore, managing scrapers are important for Stash. You don't want too many scrapers, yet you need them to categorize and label your videos quickly.[BREAK]Here I am trying to give you an easy way to manage the plugins. +text=Scrapers can fetch information about your scenes, studios, performers, tags...etc. With scrapers, you don't need to type in the information manually any more.[BREAK] * For performers, you can fetch the info by her/his name.[BREAK] * For scenes, you put in the URL for that scene, and the scraper can get all the details, including performers, tags, front cover... for that scene.[BREAK]Therefore, managing scrapers are important for Stash. You don't want too many scrapers, yet you need them to categorize and label your videos quickly. state=$GUI_SHOW+$GUI_ENABLE style= exstyle= @@ -142,13 +149,13 @@ tabpage=-1 iconindex= iconlarge=0 textmode=text -[0x005621FC] +[0x00722260] type=button handle=434 locked=0 resize=804 x=1065 -y=252 +y=212 width=167 height=49 func= @@ -171,13 +178,13 @@ tabpage=-1 iconindex= iconlarge=0 textmode=text -[0x003A21D2] +[0x001C1838] type=button handle=435 locked=0 resize=804 x=1298 -y=252 +y=212 width=167 height=49 func= @@ -200,4 +207,62 @@ order=4 iconindex= iconlarge=0 textmode=text +[0x001F242E] +type=input +handle=436 +locked=0 +resize=550 +x=42 +y=218 +width=570 +height=35 +func= +font=Tahoma +fontsize=10 +fontstyle=400 +fontattribute=0 +tooltip= +bgimage= +textcolour=0x000000 +id=$inputFilter +text= +state=$GUI_SHOW+$GUI_ENABLE +style= +exstyle=$WS_EX_CLIENTEDGE +bgcolour= +code= +order=5 +tabpage=-1 +iconindex= +iconlarge=0 +textmode=text +[0x002F233A] +type=button +handle=437 +locked=0 +resize=804 +x=640 +y=220 +width=148 +height=33 +func= +font=Tahoma +fontsize=10 +fontstyle=400 +fontattribute=0 +tooltip= +bgimage= +textcolour=0x000000 +id=$btnFilter +text=Find +state=$GUI_SHOW+$GUI_ENABLE +style= +exstyle= +bgcolour= +code= +order=6 +tabpage=-1 +iconindex= +iconlarge=0 +textmode=text #ce diff --git a/Forms/ScrapersForm.au3 b/Forms/ScrapersForm.au3 index 78e7129..9233062 100644 --- a/Forms/ScrapersForm.au3 +++ b/Forms/ScrapersForm.au3 @@ -9,79 +9,24 @@ #include #include -Global $sScraperPath +Global $sScraperPath, $aScraperArray[0], $aScraperFiles[0] Func ScrapersManager() + $sScraperPath = GetScraperPath() + Local $aItemID[0][0] + Local $iCurrentSearchIndex = 0 + If @error Then Return + ; Set both $aScraperArray and $aScraperFiles + SetScraperArray() + If @error Then Return - ; Open the config.xml to see the folder. - $stashPath = StringLeft( $stashFilePath, StringInStr($stashFilePath, "\", 2, -1) ) - ; $stashPath has "\" in the end. - $hFile = FileOpen($stashPath & "config.yml") - If $hFile = -1 Then - MsgBox(16,"Error open config.yml","Error opening the Stash's config file: config.yml",0) - Return - EndIf - - While True - $sLine = FileReadLine($hFile) - If @error = -1 Then - ; Reach the end of the file - $sLine = "scrapers_path: scrapers" - ExitLoop - ElseIf @error Then - MsgBox(16,"Error reading config.yml","Error reading the Stash's config file: config.yml",0) - FileClose($hFile) - Return - EndIf - If StringLeft($sLine, 14) = "scrapers_path:" Then ExitLoop - Wend - FileClose($hFile) - - ; Get scraper path, create the path if it doesn't exist - $sScraperPath = $stashPath & StringMid($sLine, 16 ) & "\" - If Not FileExists($sScraperPath) Then - DirCreate($sScraperPath) - EndIf - - Local $bGetList = True + ; Disable the tray clicks + TraySetClick(0) - If FileExists($sScraperPath & "SCRAPERS-LIST.md") Then - $sTime = FileGetTime($sScraperPath & "SCRAPERS-LIST.md", $FT_CREATED, $FT_STRING) - If stringleft($sTime, 8) = @YEAR & @MON & @MDAY Then - ; If same day, no need to download the file - $bGetList = False - EndIf - EndIf - ; Download the Scraper List raw. - If $bGetList Then - InetGet("https://raw.githubusercontent.com/stashapp/CommunityScrapers/master/SCRAPERS-LIST.md", _ - $sScraperPath & "SCRAPERS-LIST.md") - If @error Then - MsgBox(16,"Error downloading scrapers list","Error downloading the Stash's scraper list from its repo.",0) - Return - EndIf - EndIf - $hFile = FileOpen($sScraperPath & "SCRAPERS-LIST.md") - If $hFile = -1 Then - MsgBox(16,"Error open SCRAPERS-LIST.md","Error opening stash's scraper list file.",0) - Return - EndIf + $guiScrapers = GUICreate("Scrapers Management",1703,1438,-1,-1,$WS_SIZEBOX,-1) + GUISetIcon("helper2.ico") - ; Skip all the lines until "---------" - While True - $sLine = FileReadLine($hFile) - If stringleft($sLine, 10) = "----------" Then - ExitLoop - ElseIf @error Then - MsgBox(16,"Error reading SCRAPERS-LIST.md","Error reading stash's scraper list file.",0) - Return - EndIf - WEnd - - ; Create the GUI first, then read the data later. - - $Scrapers = GUICreate("Scrapers Management",1703,1464,-1,-1,$WS_SIZEBOX,-1) - $scraperList = GUICtrlCreatelistview("Website|Scraper|Scene|Gallery|Movie|Performers|Installed|ExtraReq|Contents",40,330,1620,1056,-1,BitOr($LVS_EX_FULLROWSELECT,$LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES,$LVS_EX_DOUBLEBUFFER,$WS_EX_CLIENTEDGE)) + $scraperList = GUICtrlCreatelistview("Website|Scraper|Scene|Gallery|Movie|Performers|Installed|ExtraReq|Contents",40,290,1621,1056,-1,BitOr($LVS_EX_FULLROWSELECT,$LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES,$LVS_EX_DOUBLEBUFFER,$WS_EX_CLIENTEDGE)) GUICtrlSetFont(-1,10,400,0,"Tahoma") GUICtrlSetResizing(-1,102) ; Website @@ -108,120 +53,240 @@ Func ScrapersManager() ; Content _GUICtrlListView_JustifyColumn($scraperList, 8, 2) - GUICtrlCreateLabel("Scrapers can fetch information about your scenes, studios, performers, tags...etc."&@crlf&"With scrapers, you don't need to type in the information manually any more."&@crlf&" * For performers, you can fetch the info by her/his name."&@crlf&" * For scenes, you put in the URL for that scene, and the scraper can get all the details, including performers, tags, front cover... for that scene."&@crlf&"Therefore, managing scrapers are important for Stash. You don't want too many scrapers, yet you need them to categorize and label your videos quickly."&@crlf&"Here I am trying to give you an easy way to manage the plugins.",130,30,1040,233,-1,-1) + GUICtrlCreateLabel("Scrapers can fetch information about your scenes, studios, performers, tags...etc. With scrapers, you don't need to type in the information manually any more."&@crlf&" * For performers, you can fetch the info by her/his name."&@crlf&" * For scenes, you put in the URL for that scene, and the scraper can get all the details, including performers, tags, front cover... for that scene."&@crlf&"Therefore, managing scrapers are important for Stash. You don't want too many scrapers, yet you need them to categorize and label your videos quickly.",54,30,1597,205,-1,-1) GUICtrlSetFont(-1,10,400,0,"Tahoma") GUICtrlSetBkColor(-1,"-2") - GUICtrlSetResizing(-1,928) + GUICtrlSetResizing(-1,38) - $btnInstall = GUICtrlCreateButton("Install",1065,252,167,49,-1,-1) + $btnInstall = GUICtrlCreateButton("Install",1065,212,167,49,-1,-1) GUICtrlSetFont(-1,12,400,0,"Tahoma") GUICtrlSetTip(-1,"Install the scrapers with check marks.") GUICtrlSetResizing(-1,804) - $btnRemove = GUICtrlCreateButton("Remove",1298,252,167,49,-1,-1) + $btnRemove = GUICtrlCreateButton("Remove",1298,212,167,49,-1,-1) GUICtrlSetFont(-1,12,400,0,"Tahoma") GUICtrlSetTip(-1,"Remove the scrapers with check marks.") GUICtrlSetResizing(-1,804) - GUISetState(@SW_SHOW, $Scrapers) + GUISetState(@SW_SHOW, $guiScrapers) - $aScraperFiles = _FileListToArray($sScraperPath, "*.yml", $FLTA_FILES) + $inputFind = GUICtrlCreateInput("",42,218,570,35,-1,$WS_EX_CLIENTEDGE) + GUICtrlSetFont(-1,10,400,0,"Tahoma") + GUICtrlSetResizing(-1,550) - ; Now read the real data and create all the items. - While True - $sLine = FileReadLine($hFile) - If @error = -1 Then - ; End of the file - ExitLoop - ElseIf @error Then - ; Other errors. - MsgBox(16,"Error reading SCRAPERS-LIST lines","Error reading scraper list lines.",0) - Return - EndIf - - $aData = StringSplit($sLine, "|") - ; Replace the check mark with check symbol, :x: with x - $sLine = StringReplace($sLine, ":heavy_check_mark:", "√", 0, 2) - $sLine = StringReplace($sLine, ":x:", "x", 0, 2) - - ; Get the yml file name - $iPos1 = StringInStr($sLine, "|", 2, 1) - $iPos2 = StringInStr($sLine, "|", 2, 2) - $sYml = StringMid($sLine, $iPos1 + 1, $iPos2-$iPos1-1 ) - ; Search this one in the files array - $result = _ArraySearch($aScraperFiles, $sYml, 0, 0, 0, 2) - $sInstalled = "No|" - If $result <> -1 Then - ; installed. - $sInstalled = "Yes|" - EndIf - - ; Add "Installed" column before the ExtraReq - $iPos = StringInStr($sLine, "|", 2, -2) - $sFinalLine = StringLeft($sLine, $iPos) & $sInstalled & StringMid($sLine, $iPos + 1) - GUICtrlCreateListViewItem($sFinalLine, $scraperList) - Wend - FileClose($hFile) + $btnFind = GUICtrlCreateButton("Find",640,220,148,33,-1,-1) + GUICtrlSetFont(-1,10,400,0,"Tahoma") + GUICtrlSetResizing(-1,804) + + ; Now all the items in the list, [0] is handle [1] is check/uncheck + ReDim $aItemID[UBound($aScraperArray)][2] + For $i = 0 to UBound($aScraperArray) -1 + $aItemID[$i][0] = GUICtrlCreateListViewItem($aScraperArray[$i], $scraperList) + $aItemID[$i][1] = False ; Unchecked. + Next ; Now It's all ready. Wait for "Install" or "Remove" + Local $aFiles[0] + While True + ; if click on tray icon, activate the current GUI + $nTrayMsg = TrayGetMsg() + Switch $nTrayMsg + Case $TRAY_EVENT_PRIMARYDOWN, $TRAY_EVENT_SECONDARYDOWN + WinActivate($guiScrapers) + EndSwitch + + ; Main control loop $nMsg = GUIGetMsg() Switch $nMsg - + Case $inputFind, $btnFind + $sText = GUICtrlRead($inputFind) + $iFound = _GUICtrlListView_FindInText($scraperList, $sText, $iCurrentSearchIndex, False ) + If $iFound = -1 Then + ; Not found, reset the index + $iCurrentSearchIndex = 0 + MsgBox(48,"Not found","Search reach the end and Cannot find your search of " & $sText,0) + Else + ; Found the index, set it highlighted and visible. + $iCurrentSearchIndex = $iFound + _GUICtrlListView_EnsureVisible($scraperList, $iFound ) + _GUICtrlListView_SetItemSelected($scraperList, $iFound) + GUICtrlSetState($scraperList, $GUI_FOCUS) + EndIf Case $btnInstall ; Install scrapers $iCount = _GUICtrlListView_GetItemCount($scraperList) $iTotalInstalled = 0 + ReDim $aFiles[0] ; clear the array For $i = 0 To $iCount -1 - If _GUICtrlListView_GetItemChecked($scraperList, $i) Then + ; go through the whole list + If _GUICtrlListView_GetItemChecked($scraperList, $i) Then $sScraperFile = _GUICtrlListView_GetItemText($scraperList, $i, 1) - FetchScraper($sScraperFile) - If @error Then - MsgBox(48,"Error downloading file","Sorry, cannot download this file from GitHub:" & $sScraperFile,0) - ExitLoop - EndIf - ; Fetch is good. Now set it uncheck and "installed" + If _ArraySearch($aFiles, $sScraperFile) = -1 Then + ; Not in file array + $i = UBound($aFiles) + ReDim $aFiles[$i + 1] + ; Add it to the list + $aFiles[$i] = $sScraperFile + EndIf + ; Now set it uncheck and "installed" _GUICtrlListView_SetItemChecked($scraperList, $i, False) _GUICtrlListView_SetItemText($scraperList, $i, "Yes", 6) - $iTotalInstalled += 1 EndIf Next - If $iTotalInstalled > 0 Then + ; Now go through the file list + For $i = 0 To UBound($aFiles) -1 + FetchScraper($aFiles[$i]) + If @error Then + MsgBox(48,"Error downloading file","Sorry, cannot download this file from GitHub:" & $sScraperFile,0) + Else + $iTotalInstalled += 1 + EndIf + Next + + If $iTotalInstalled > 0 Then + ; Reload scrapers + + ; Set mouse cursor to wait. + $old_cursor = MouseGetCursor() + GUISetCursor(15, 1, $guiScrapers) + OpenURL("http://localhost:9999/settings?tab=scraping") - Sleep(2000) - Alert($iTotalInstalled & " checked Scrapers are installed. Now you still need to click on 'Reload Scrapers' here to take effect.") - EndIf + $sButtonID = _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, '//span[text()="Reload scrapers"]', 500, 10000) ; start at 500ms, expired at 10 seconds + Sleep(1000) + If @error = $_WD_ERROR_Success Then + _WD_ElementAction($sSession, $sButtonID, "Click") + EndIf + + ; Set cursor back. + GUISetCursor($old_cursor, 1, $guiScrapers) + MsgBox(64,$iTotalInstalled & " Scrapers Installed",$iTotalInstalled & " Scrapers are now installed and working.",20) + EndIf Case $btnRemove ; Remove scrapers $iCount = _GUICtrlListView_GetItemCount($scraperList) $iTotalRemoved = 0 + ReDim $aFiles[0] ; clear the array For $i = 0 To $iCount -1 + ; go through the whole list If _GUICtrlListView_GetItemChecked($scraperList, $i) Then $sScraperFile = _GUICtrlListView_GetItemText($scraperList, $i, 1) - FileDelete($sScraperPath & $sScraperFile) - $sPyFile = Stringleft($sScraperFile, stringinstr($sScraperFile, ".", 2, -1) -1) & ".py" - If FileExists($sScraperPath & $sPyFile) Then - FileDelete($sScraperPath & $sPyFile) - EndIf + If _ArraySearch($aFiles, $sScraperFile) = -1 Then + ; Not in file array + $i = UBound($aFiles) + ReDim $aFiles[$i + 1] + ; Add it to the list + $aFiles[$i] = $sScraperFile + EndIf _GUICtrlListView_SetItemChecked($scraperList, $i, False) _GUICtrlListView_SetItemText($scraperList, $i, "No", 6) - $iTotalRemoved += 1 + EndIf + Next + ; Now go through the file list + For $i = 0 To UBound($aFiles)-1 + FileDelete($sScraperPath & $sScraperFile) + $sPyFile = Stringleft($sScraperFile, stringinstr($sScraperFile, ".", 2, -1) -1) & ".py" + If FileExists($sScraperPath & $sPyFile) Then + FileDelete($sScraperPath & $sPyFile) EndIf + $iTotalRemoved += 1 Next + If $iTotalRemoved > 0 Then + ; Reload scrapers + + ; Set mouse cursor to wait. + $old_cursor = MouseGetCursor() + GUISetCursor(15, 1, $guiScrapers) + OpenURL("http://localhost:9999/settings?tab=scraping") - Sleep(2000) - Alert($iTotalRemoved & " checked Scrapers are removed. Now you still need to click on 'Reload Scrapers' here to take effect.") + $sButtonID = _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, '//span[text()="Reload scrapers"]', 500, 10000) ; start at 500ms, expired at 10 seconds + Sleep(1000) + If @error = $_WD_ERROR_Success Then + _WD_ElementAction($sSession, $sButtonID, "Click") + EndIf + + + ; Set cursor back. + GUISetCursor($old_cursor, 1, $guiScrapers) + + MsgBox(64,$iTotalRemoved & " Scrapers removed",$iTotalRemoved & " Scrapers are now removed.",20) EndIf Case $GUI_EVENT_CLOSE ExitLoop EndSwitch + ; Match the Items + For $i = 0 to UBound($aItemID)-1 + If $nMsg = $aItemID[$i][0] Then + ; Item ID matched. + ; if search, search from here. + $iCurrentSearchIndex = $i + + $bItemChecked = _GUICtrlListView_GetItemChecked($scraperList, $i) + If $bItemChecked <> $aItemID[$i][1] Then + ; Check status changed. + $aItemID[$i][1] = $bItemChecked + ; Now set all the item with same yml file to the same check status + $sYMLfile = StringStripWS( _GUICtrlListView_GetItemText($scraperList, $i, 1), 3) + ; Find the item with same file + For $j = 0 To UBound($aScraperArray) -1 + Local $aStr = StringSplit($aScraperArray[$j], "|") + If StringStripWS($aStr[2], 3) = $sYMLfile Then + ; This item matches + _GUICtrlListView_SetItemChecked($scraperList, $j, $bItemChecked) + $aItemID[$j][1] = $bItemChecked + EndIf + Next + EndIf + ; Click on only 1 item, so once a match is found, it's good. + ExitLoop + EndIf + Next Wend - GUIDelete($Scrapers) + GUIDelete($guiScrapers) + ; Restore tray icon functions. + TraySetClick(9) EndFunc + + +Func GetScraperPath() + ; Open the config.xml to see the folder. + ; Return: the path string to the scrapers + Local $stashPath = StringLeft( $stashFilePath, StringInStr($stashFilePath, "\", 2, -1) ) + ; $stashPath has "\" in the end. + Local $hFile = FileOpen($stashPath & "config.yml") + If $hFile = -1 Then + MsgBox(16,"Error open config.yml","Error opening the Stash's config file: config.yml",0) + Return SetError(1) + EndIf + Local $sLine + ; Read the config.yml + While True + $sLine = FileReadLine($hFile) + If @error = -1 Then + ; Reach the end of the file, set to default as last resort + $sLine = "scrapers_path: scrapers" + ExitLoop + ElseIf @error Then + MsgBox(16,"Error reading config.yml","Error reading the Stash's config file: config.yml",0) + FileClose($hFile) + Return SetError(1) + EndIf + If StringLeft($sLine, 14) = "scrapers_path:" Then ExitLoop + Wend + FileClose($hFile) + + ; Get scraper path, create the path if it doesn't exist + Local $sPath = $stashPath & StringMid($sLine, 16 ) & "\" + If Not FileExists($sPath) Then + DirCreate($sPath) + EndIf + Return $sPath +EndFunc + Func FetchScraper($sFile) ; Global $stashFilePath, $sScraperPath ; Download it from GitHub @@ -252,3 +317,82 @@ Func FetchScraper($sFile) EndIf WEnd EndFunc +Func SetScraperArray() + ; Set the global $aScraperArray + $iCount = 0 + + Local $bGetList = True, $sLine + $aScraperFiles = _FileListToArray($sScraperPath, "*.yml", $FLTA_FILES) + + If FileExists($sScraperPath & "SCRAPERS-LIST.md") Then + Local $sTime = FileGetTime($sScraperPath & "SCRAPERS-LIST.md", $FT_CREATED, $FT_STRING) + If stringleft($sTime, 8) = @YEAR & @MON & @MDAY Then + ; If same day, no need to download the file + $bGetList = False + EndIf + EndIf + ; Download the Scraper List raw. + If $bGetList Then + InetGet("https://raw.githubusercontent.com/stashapp/CommunityScrapers/master/SCRAPERS-LIST.md", _ + $sScraperPath & "SCRAPERS-LIST.md") + If @error Then + MsgBox(16,"Error downloading scrapers list","Error downloading the Stash's scraper list from its repo.",0) + Return SetError(1) + EndIf + EndIf + + $hFile = FileOpen($sScraperPath & "SCRAPERS-LIST.md") + If $hFile = -1 Then + MsgBox(16,"Error open SCRAPERS-LIST.md","Error opening stash's scraper list file.",0) + Return SetError(1) + EndIf + + ; Skip all the lines until "---------" + While True + $sLine = FileReadLine($hFile) + If stringleft($sLine, 10) = "----------" Then + ExitLoop + ElseIf @error Then + MsgBox(16,"Error reading SCRAPERS-LIST.md","Error reading stash's scraper list file.",0) + Return SetError(1) + EndIf + WEnd + + ; Read the data and set them in the array + While True + $sLine = FileReadLine($hFile) + If @error = -1 Then + ; End of the file + ExitLoop + ElseIf @error Then + ; Other errors. + MsgBox(16,"Error reading SCRAPERS-LIST lines","Error reading scraper list lines.",0) + Return SetError(1) + EndIf + + Local $aData = StringSplit($sLine, "|") + ; Replace the check mark with check symbol, :x: with x + $sLine = StringReplace($sLine, ":heavy_check_mark:", "√", 0, 2) + $sLine = StringReplace($sLine, ":x:", "x", 0, 2) + + ; Get the yml file name + $iPos1 = StringInStr($sLine, "|", 2, 1) + $iPos2 = StringInStr($sLine, "|", 2, 2) + $sYml = StringMid($sLine, $iPos1 + 1, $iPos2-$iPos1-1 ) + + ; Search this one in the files array + $result = _ArraySearch($aScraperFiles, $sYml, 0, 0, 0, 2) + $sInstalled = ($result= -1 )? "No|" : "Yes|" + + ; Add "Installed" to the array before the ExtraReq + $iPos = StringInStr($sLine, "|", 2, -2) + $sFinalLine = StringLeft($sLine, $iPos) & $sInstalled & StringMid($sLine, $iPos + 1) + + ; Add the whole line to the end of the array. + ReDim $aScraperArray[$iCount + 1] + $aScraperArray[$iCount] = $sFinalLine + $iCount += 1 + Wend + FileClose($hFile) + $hCurrentGUI = 0 +EndFunc \ No newline at end of file diff --git a/Forms/SettingsForm.au3 b/Forms/SettingsForm.au3 index 614f78c..097e054 100644 --- a/Forms/SettingsForm.au3 +++ b/Forms/SettingsForm.au3 @@ -8,6 +8,9 @@ Func ShowSettings() ; Global $stashBrowser, $stashFilePath, $stashURL, $sMediaPlayerLocation Local $sBrowser Local $guiSettings = GUICreate("Settings",801,1042,-1,-1,-1,-1) + GUISetIcon("helper2.ico") + ; Disable the tray clicks + TraySetClick(0) GUICtrlCreateLabel("Boss Coming Key: Ctrl + Enter"&@crlf&"Hit this key combination will immediately close the Stash browser.",100,40,574,129,-1,-1) GUICtrlSetFont(-1,12,400,0,"Palatino Linotype") @@ -133,7 +136,14 @@ Func ShowSettings() While True Sleep(10) - $nMsg = GUIGetMsg() + ; if click on tray icon, activate the current GUI + $nTrayMsg = TrayGetMsg() + Switch $nTrayMsg + Case $TRAY_EVENT_PRIMARYDOWN, $TRAY_EVENT_SECONDARYDOWN + WinActivate($guiSettings) + EndSwitch + + $nMsg = GUIGetMsg() Switch $nMsg Case $btnBrowseStash Local $sFile = FileOpenDialog("Open the Stash-Win.exe:", _ @@ -274,4 +284,5 @@ Func ShowSettings() EndSwitch Wend GUIDelete($guiSettings) + TraySetClick(9) EndFunc \ No newline at end of file diff --git a/Stash_Helper.au3 b/Stash_Helper.au3 index bd15663..e7d3743 100644 --- a/Stash_Helper.au3 +++ b/Stash_Helper.au3 @@ -20,11 +20,12 @@ DllCall("User32.dll","bool","SetProcessDPIAware") -Global Const $currentVersion = "v1.2" +Global Const $currentVersion = "v1.3" ; This already declared in Custom.au3 Global Enum $ITEM_HANDLE, $ITEM_TITLE, $ITEM_LINK Global Const $iMaxSubItems = 11 + TraySetIcon("helper2.ico") #Region Globals Initialization @@ -123,7 +124,7 @@ EndIf Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. ; Now create the top level tray menu items. If $stashVersion <> "" Then - TrayTip("Stash is Active", $stashVersion, 10, $TIP_ICONASTERISK+$TIP_NOSOUND ) + TrayTip("Stash is Active", $stashVersion, 5, $TIP_ICONASTERISK+$TIP_NOSOUND ) EndIf TrayCreateItem("Stash Helper " & $currentVersion ) ; 0 @@ -209,7 +210,9 @@ Global $sBrowserHandle #EndRegion Globals #Region Tray Menu Handling + CreateSubMenu() + TraySetState($TRAY_ICONSTATE_SHOW) ; Launch the web page OpenURL($stashURL) @@ -219,7 +222,7 @@ While True $nMsg = TrayGetMsg() Switch $nMsg Case 0 - ; Nothing should be here. + ; Nothing should be here, but Case 0 here is very necessary. Case $trayAbout MsgBox(64,"Stash Helper " & $currentVersion,"Stash helper " & $currentVersion & ", written by Philip Wang, at your service." _ & @CRLF & "Hopefully this little program will make you navigate the powerful Stash App more easily." _ diff --git a/Stash_Helper.isn b/Stash_Helper.isn index 350ef5db583c049d90bedb77014d2a2beabb8a51..065dd4079afc1ad10724d1f620d0edfbcd4c1957 100644 GIT binary patch delta 133 zcmbOxeNAe@HhxP6QwDPe10XgAvWzDloyly(U^F?A(OA}yL65-@D5b|>1SE}sYy}{; zV6XzR%_eVT^qgGB#5egFv%%y(7QV@sm^>z1F!fBXVHKFH#jG>AfK_d>4vW;}H!L=j cCo#JK<#;wLv4}7NH7QKK$11aV6YCRp0QMIl)Bpeg delta 129 zcmca6HBEZLHhyykOCU67FkvtT(gqWc&SW-Zu$-L8Xe?{MpvPdy03wZmq!Ey<0K}FI zRt%;L=94!vdQO&M=9|2Zg=4Z7i^=3!ObwI!SokKpF?mduVz!z5hQ(&`C1#h&KNuY* Z_c8HoR$>uh1Zqf_Jdagoa}nzkb^u{iAb0=(