AutoHotkey script to concatenate AgentDVR videos

This AutoHotkey script concatenates video files using FFmpeg and plays the output with mpv. Below is a breakdown including what needs editing for use on another computer.


What the Script Does

The script:

  1. Reads file paths from the clipboard.
  2. Creates a text file (mylist.txt) listing video files for FFmpeg.
  3. Concatenates videos into a single file (output.mkv or output.mp4) using FFmpeg.
  4. Renames existing output files with a timestamp to avoid overwriting.
  5. Plays the resulting video with mpv.

Script Breakdown

  • Input Check: Ensures the clipboard contains file paths and the first path includes D:\windows (a specific folder check).
  • Folder Processing:
  • Strips quotes from the base path and sets it as the working directory.
  • Loops through clipboard lines, formats paths for mylist.txt (e.g., file 'video1.mp4').
  • Sorts the file list and writes it to mylist.txt.
  • Detects if .mkv files are present to set output format (.mkv or .mp4).
  • Runs FFmpeg with -f concat to merge files without re-encoding (-c copy).
  • Plays the output with mpv.
  • File Management: If the output file exists, it’s renamed with a timestamp (e.g., output_2025-05-11-14-30.mp4).

What Needs Editing

To make the script work on another computer, modify these elements:

  1. Clipboard Path Check:
  • The script checks for D:\windows in the first clipboard line. Replace with a relevant path or remove the check:
    autohotkey if (!InStr(firstLine, "D:\windows")) { ExitApp }
    Fix: Comment out or replace "D:\windows" with the user’s base path (e.g., C:\Videos).
  1. FFmpeg Path:
  • The script assumes ffmpeg is in the system’s PATH. Ensure FFmpeg is installed and accessible.
    • Fix: Install FFmpeg and add it to PATH, or specify the full path:
      autohotkey ffmpegCmd := """C:\path\to\ffmpeg.exe"" -f concat -safe 0 -i """ . listFile . """ -c copy """ . FileName . """"
  1. mpv Path:
  • The script uses mpv.exe to play the output. Ensure mpv is installed and in PATH.
    • Fix: Install mpv and add to PATH, or specify the full path:
      autohotkey Run, """C:\path\to\mpv.exe"" ""%FileName%"""
  1. Base Path:
  • The script derives the base path from the clipboard. Ensure clipboard paths match the user’s folder structure.
    • Fix: Test with paths relative to the user’s video folder (e.g., C:\Videos\video1.mp4).
  1. File Extensions:
  • The script assumes .mkv or .mp4. If other formats are used, modify the extension logic:
    autohotkey isMKV := InStr(a, ".mkv") FileName := isMKV ? basePath . "output.mkv" : basePath . "output.mp4"
    Fix: Add checks for other extensions (e.g., .avi, .mov).
  1. AutoHotkey:

Example Customization

For a user with videos in C:\Videos, FFmpeg at C:\FFmpeg\bin\ffmpeg.exe, and mpv at C:\mpv\mpv.exe:

if (!InStr(firstLine, "C:\Videos")) ; Update path
{
    ExitApp
}
ffmpegCmd := """C:\FFmpeg\bin\ffmpeg.exe"" -f concat -safe 0 -i """ . listFile . """ -c copy """ . FileName . """"
Run, """C:\mpv\mpv.exe"" ""%FileName%"""

Usage

  1. Install AutoHotkey, FFmpeg, and mpv.
  2. Copy paths of video files to the clipboard. (Select the videos and hold down Shift + Right Click and select Copy as path in the Windows Explorer context menu.)
  3. Run the script.
  4. Check the output video (output.mkv or output.mp4) in the base folder.

Notes

  • Ensure all video files have the same codec and resolution for seamless concatenation.
  • Test the script with a small set of files first.
  • Backup important files before running to avoid accidental overwrites.

ProcessFolder(basePath) {    
    ; Remove any leading/trailing quotes from basePath
    basePath := StrReplace(basePath, """", "")    
    SetWorkingDir %basePath%   
    a := ""
    insert := "file '"
    Loop, parse, Clipboard, `n, `r
    {
        if (A_LoopField != "")
        {
            filePath := StrReplace(A_LoopField, basePath, "")
            filePath := StrReplace(filePath, """", "")
            a .= insert . filePath . "'`r`n"
        }
    }   
    
    Clipboard := a
    Sort, a
    
    isMKV := InStr(a, ".mkv")  
    listFile := basePath . "mylist.txt"   
    FileDelete, %listFile%
    MyFileObj := FileOpen(listFile, "w")
    bytesWritten := MyFileObj.Write(a)
    MyFileObj.Close()
    Sleep, 500    
    FileName := isMKV ? basePath . "output.mkv" : basePath . "output.mp4"
    
    IfExist, %FileName%
    {
        SplitPath, FileName,, Dir, Ext, NameNoExt
        FormatTime, DateTimeNow,, yyyy-MM-dd-HH-mm
        NewFileName := Dir "\" NameNoExt "_" DateTimeNow "." Ext
        FileMove, %FileName%, %NewFileName%
    }    
    ffmpegCmd := "ffmpeg -f concat -safe 0 -i """ . listFile . """ -c copy """ . FileName . """"
	RunWait, cmd.exe /c %ffmpegCmd% 2>&1, , Hide
    Run, "mpv.exe" "%FileName%"   
    return
}

; Check if clipboard is empty
if (Clipboard = "")
{
    ExitApp
}

Loop, parse, Clipboard, `n, `r
{
    firstLine := A_LoopField
    break
}

if (!InStr(firstLine, "D:\windows"))
{
    ExitApp
}

SplitPath, firstLine,, basePath
basePath := RTrim(basePath, "\") . "\"

if (basePath)
    ProcessFolder(basePath)
else
    MsgBox, Could not determine folder path from clipboard!

Managing Sven Co-op Maps with Custom Scripts

https://sbmesh.com/delete_map.ps1

https://sbmesh.com/delete_map.sh

Sven Co-op players often download custom maps, but managing them can be tedious. To simplify map cleanup, I’ve created two scripts—one for Windows (PowerShell) and one for Linux (Bash)—that delete specific maps and optionally their series counterparts, including associated .res and .cfg files. These scripts work in the default Sven Co-op map download folders and handle map names with leading zeros or trailing text (e.g., mapname01.bsp, othermap2etc.bsp).

Windows PowerShell Script

The PowerShell script operates in C:\Program Files (x86)\Steam\steamapps\common\Sven Co-op\svencoop_downloads\maps. It prompts for a map name (without needing .bsp), deletes the specified map, and offers to delete all maps in the same series.

Features

  • Deletes .bsp, .res, and .cfg files for the specified map.
  • Recognizes series maps (e.g., a_jungle_01, a_jungle_2etc) and deletes all in the series if confirmed.
  • No need to type .bsp extension.

Usage

  1. Save the script as delete_map.ps1 in the maps folder.
  2. Run it in PowerShell.
  3. Enter a map name (e.g., a_jungle_1).
  4. Confirm if you want to delete series maps (e.g., a_jungle_*.bsp, .res, .cfg).

Linux Bash Script

The Bash script works in ~/.local/share/Steam/steamapps/common/Sven Co-op/svencoop_downloads/maps. It mirrors the PowerShell script’s functionality for Linux users.

Features

  • Deletes .bsp, .res, and .cfg files for the entered map.
  • Handles series maps with leading zeros or trailing text.
  • .bsp extension is optional.

Usage

  1. Save the script as delete_map.sh in the maps folder.
  2. Make it executable: chmod +x delete_map.sh.
  3. Run it: ./delete_map.sh.
  4. Enter a map name and confirm series deletion if prompted.

Why Use These Scripts?

Both scripts streamline map management by:

  • Automating deletion of related files.
  • Handling complex map naming conventions.
  • Offering series deletion for quick cleanup.

Place the scripts in their respective map folders, and enjoy a clutter-free Sven Co-op experience!

Exploring the Ozon3 Perl Module for Air Quality Data

https://sbmesh.com/Ozon3.pm

The Ozon3 Perl module is a lightweight interface to the World Air Quality Index (WAQI) API, designed to fetch real-time air quality data based on geographic coordinates. Modeled after the Python Ozon3 library, it provides a robust way to retrieve Air Quality Index (AQI) and pollutant metrics with optional rate limiting.

Key Features

  • WAQI API Integration: Connects to https://api.waqi.info/ to retrieve air quality data.
  • Rate Limiting: Supports up to 1000 API calls per second using Schedule::RateLimiter (optional).
  • Error Handling: Comprehensive checks for invalid tokens, rate limits, and API errors.
  • Data Extraction: Returns detailed AQI, pollutant levels (e.g., PM2.5, PM10, NO2), and health implications.

Core Components

Initialization (new)

  • Requires a WAQI API token.
  • Sets up LWP::UserAgent for HTTP requests and Schedule::RateLimiter for throttling.
  • Validates the token by querying the API with a test request for London.

Fetching Data (get_air_quality)

  • Takes latitude and longitude as inputs.
  • Constructs a URL with escaped parameters and the API token.
  • Returns a hashref containing AQI, pollutant concentrations, station details, and health implications.

Data Processing (_extract_live_data)

  • Extracts metrics like AQI, PM2.5, PM10, CO, and meteorological data (e.g., temperature, humidity).
  • Normalizes pollutant names (e.g., pm25 to pm2.5).
  • Converts AQI into human-readable meanings and health implications.

Utility Methods

  • _check_token_validity: Verifies the API token.
  • _check_and_get_data_obj: Handles HTTP responses and API errors.
  • _aqi_meaning: Maps AQI values to categories (e.g., “Good,” “Unhealthy”) and health risks.
  • _as_float: Ensures numeric values are properly formatted.

Usage Example

use Ozon3;
my $ozon3 = Ozon3->new(token => 'your_waqi_token');
my $aq = $ozon3->get_air_quality(37.7749, -122.4194); # San Francisco
if ($aq) {
    print "AQI: $aq->{aqi} ($aq->{aqi_meaning})\n";
    print "PM2.5: $aq->{pm2.5} µg/m³\n";
}

Dependencies

  • LWP::UserAgent: For HTTP requests.
  • JSON::MaybeXS: For parsing API responses.
  • URI::Escape: For URL encoding.
  • Schedule::RateLimiter: Optional, for rate limiting.

Notes

  • The module gracefully handles missing dependencies or failed initializations.
  • Rate limiting is optional; if Schedule::RateLimiter fails, the module proceeds without it.
  • Comprehensive error messages aid debugging (e.g., invalid tokens, unknown stations).

Conclusion

The Ozon3 module is a reliable tool for developers needing air quality data in Perl applications. Its robust error handling and flexible design make it suitable for both small scripts and large systems.

Source: Adapted from the Ozon3 Python library by Ozon3Org.

Auto