TypesettingTools / Myaamori-Aegisub-Scripts

Overengineering is my middle name.
MIT License
37 stars 7 forks source link

Sub Digest: Script to Python #27

Open MrFanservice-png opened 2 weeks ago

MrFanservice-png commented 2 weeks ago

How do I convert this script into a working python (.py) file where I can drag and drop the subtitle files to extract the necessary text from it? for %I in (*.ass) do python -m subdigest -i "%I" --selection-set "text" "\\p" --remove-selected --selection-set style "Sign|OP|ED|op|ed|kfx|Karaoke|Eyecatch|Signs" --remove-selected --remove-all-tags --remove-comments --get-field text -o "%~nI.txt"

FichteFoll commented 2 weeks ago

via ChatGPT:

How do I convert this batch script into one file where I can drag and drop the subtitle files to extract the necessary text from it?

for %I in (*.ass) do python -m subdigest -i "%I" --selection-set "text" "\p" --remove-selected --selection-set style "Sign|OP|ED|op|ed|kfx|Karaoke|Eyecatch|Signs" --remove-selected --remove-all-tags --remove-comments --get-field text -o "%~nI.txt"


To convert this batch script into one file that can process subtitle files by drag-and-dropping them onto it, you need to adapt it to work as a standalone script. This is achieved by using the following approach:

  1. Convert the batch script logic to handle drag-and-drop: When you drag and drop files onto a batch script, the dropped file paths are passed as arguments to the script. You need to loop through these arguments and apply the command to each file.

  2. Replace %I with appropriate syntax for processing each dropped file: The %1, %2, etc., will represent the file paths of the dropped files.

Here is how you can modify the script: New Batch Script

@echo off
:: Loop through all files dragged and dropped onto the batch script
for %%I in (%*) do (
    :: Run your python command for each file
    python -m subdigest -i "%%~I" --selection-set "text" "\\p" --remove-selected --selection-set style "Sign|OP|ED|op|ed|kfx|Karaoke|Eyecatch|Signs" --remove-selected --remove-all-tags --remove-comments --get-field text -o "%%~nI.txt"
)
pause

Explanation:

Usage:

This way, you don't have to run the script manually for each file. Just drag and drop the files onto the batch script.