Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Related Scripting + Code Updates #8

Open
wants to merge 13 commits into
base: config-scripting
Choose a base branch
from
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ An XAPI integrated VLC player

### Setup

#### Linux/MacOS/WSL
0) (optional) `make configure` will setup the configuration files for the plugin. to override defaults, run the command with the appropriate overrides. Example being: `make configure THRESHOLD=0.87`. The following is a list of variables and what they mean.
- `THRESHOLD` - Decimal value between 0 and 1 that represents point in video considered a completion. Once a video reaches this threshold, the plugin will issue a completion statement
- `API_KEY` - API key for LRS
Expand All @@ -20,11 +21,17 @@ An XAPI integrated VLC player
- API Secret: Secret for LRS
- API Endpoint: Endpoint for LRS (example: https://localhost:8080/xapi)

4) Play a video of your choice and verify the data is flowing from the LRS.
4) Play a video of your choice and verify the data is flowing from an LRS.

#### Windows
1) double click the installation script located at .\scripts\windows\install.bat
2) (optional) fill out the fields appropriately
3) Open VLC, click the view dropdown and click 'xAPI Integration.' If you did step 2 those fields should be filled out already.
4) Play a video of your choice and verify the data is flowing from an LRS.

### Dev

All code is located at `xapi.lua`. In VLC you can go to the console log (via ctrl+M) to see what the code is doing. If you wish to update the plugin, just save your changes to `xapi.lua` and run `make install` again.
- All code is located at `xapi.lua`. In VLC you can go to the console log (via ctrl+M) to see what the code is doing. If you wish to update the plugin, just save your changes to `xapi.lua` and run `make install` again.

### License

Expand Down
6 changes: 6 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/bash
source "$(dirname "$0")/get-config-dir.sh"

# copy template into config directory
TARGET_TEMPLATE_PATH="$(get_vlc_config_directory)xapi.json.template"
SOURCE_TEMPLATE="templates/xapi.json.template"
cp "$SOURCE_TEMPLATE" "$TARGET_TEMPLATE_PATH"

# Set the source file path
SOURCE_FILE="xapi.lua"
Expand Down
32 changes: 32 additions & 0 deletions scripts/windows/get-config-dir.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Define a function to get the VLC configuration directory
function Get-VLCConfigDirectory {
# Get the APPDATA environment variable
$configDir = "$env:APPDATA\vlc\"

# Check if the directory path is defined
if (-not $configDir) {
Write-Error "Could not determine VLC configuration directory."
return $null
}

# Ensure the directory exists; create it if it doesn't
if (-not (Test-Path -Path $configDir)) {
try {
New-Item -ItemType Directory -Path $configDir -Force | Out-Null
} catch {
Write-Error "Failed to create directory: $configDir"
return $null
}
}

# Output the config directory path
return $configDir
}

# Call the function and store the result in a variable
$configDir = Get-VLCConfigDirectory

# Display the configuration directory path if successful
if ($configDir) {
Write-Output "VLC configuration directory: $configDir"
}
11 changes: 11 additions & 0 deletions scripts/windows/install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo off
:: Check if PowerShell is available
where powershell >nul 2>&1
if %errorlevel% neq 0 (
echo PowerShell is not installed on this system.
exit /b 1
)

:: Call the PowerShell script with bypassed execution policy
powershell.exe -ExecutionPolicy Bypass -File "%~dp0ps-configure.ps1"
powershell.exe -ExecutionPolicy Bypass -File "%~dp0ps-install.ps1"
102 changes: 102 additions & 0 deletions scripts/windows/ps-configure.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Load the get-config-dir.ps1 script
. "$PSScriptRoot\get-config-dir.ps1"

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

# Function to create the input form
function Show-ConfigForm {
$form = New-Object System.Windows.Forms.Form
$form.Text = "Configuration"
$form.Size = New-Object System.Drawing.Size(400, 300)
$form.StartPosition = "CenterScreen"

# Labels and text boxes
$labels = @("API Key:", "API Secret:", "API Endpoint:", "Threshold:", "Homepage:")
$inputs = @{}
$yPos = 20

foreach ($labelText in $labels) {
# Create label
$label = New-Object System.Windows.Forms.Label
$label.Text = $labelText
$label.Location = New-Object System.Drawing.Point(10, $yPos)
$label.AutoSize = $true
$form.Controls.Add($label)

# Create text box
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Size = New-Object System.Drawing.Size(250, 20)
$textBox.Location = New-Object System.Drawing.Point(120, $yPos)
$form.Controls.Add($textBox)

# Store text box in a dictionary
$inputs[$labelText] = $textBox
$yPos += 40
}

# OK button
$okButton = New-Object System.Windows.Forms.Button
$okButton.Text = "OK"
$okButton.Location = New-Object System.Drawing.Point(150, $yPos)
$okButton.Add_Click({
$form.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.Close()
})
$form.Controls.Add($okButton)

# Show the form and get the result
if ($form.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
return @{
ApiKey = $inputs["API Key:"].Text
ApiSecret = $inputs["API Secret:"].Text
ApiEndpoint = $inputs["API Endpoint:"].Text
Threshold = $inputs["Threshold:"].Text
Homepage = $inputs["Homepage:"].Text
}
}
return $null
}

# Function to delete a file if it exists
function Delete-IfExists {
param ([string]$FilePath)
if (Test-Path -Path $FilePath) {
Write-Output "File exists: $FilePath"
Remove-Item -Path $FilePath -Force
Write-Output "File deleted: $FilePath"
} else {
Write-Output "File does not exist: $FilePath"
}
}

# Get user input via form
$userInput = Show-ConfigForm
if (-not $userInput) {
Write-Output "Configuration canceled."
exit
}

# Get VLC config directory
$configDir = Get-VLCConfigDirectory
if (-not $configDir) {
Write-Error "Failed to retrieve VLC configuration directory."
exit 1
}

# Define config files
$xapiConfigFile = Join-Path -Path $configDir -ChildPath "xapi-extension-config.txt"
$thresholdConfigFile = Join-Path -Path $configDir -ChildPath "xapi-threshold-config.txt"

# Delete existing config files
Delete-IfExists -FilePath $xapiConfigFile
Delete-IfExists -FilePath $thresholdConfigFile

# Write user inputs to the appropriate config files
if ($userInput.ApiKey) { Add-Content -Path $xapiConfigFile -Value "api_key = $($userInput.ApiKey)" }
if ($userInput.ApiSecret) { Add-Content -Path $xapiConfigFile -Value "api_secret = $($userInput.ApiSecret)" }
if ($userInput.ApiEndpoint) { Add-Content -Path $xapiConfigFile -Value "api_endpoint = $($userInput.ApiEndpoint)" }
if ($userInput.Threshold) { Add-Content -Path $thresholdConfigFile -Value "threshold = $($userInput.Threshold)" }
if ($userInput.Homepage) { Add-Content -Path $xapiConfigFile -Value "api_homepage = $($userInput.Homepage)" }

Write-Output "Config written to $xapiConfigFile and threshold written to $thresholdConfigFile."
62 changes: 62 additions & 0 deletions scripts/windows/ps-install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Load the Get-VLCConfigDirectory function from get-config-dir.ps1
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$scriptDir\get-config-dir.ps1"

# Get the VLC configuration directory
$configDir = Get-VLCConfigDirectory
if (-not $configDir) {
Write-Error "Failed to retrieve VLC configuration directory."
exit 1
}

# Get the project root directory
$projectRoot = Split-Path -Parent (Split-Path -Parent $scriptDir)

# Define the source template and target paths
$sourceTemplate = "$projectRoot\templates\xapi.json.template"
$targetTemplatePath = Join-Path -Path $configDir -ChildPath "xapi.json.template"

# Copy the template to the config directory
try {
Copy-Item -Path $sourceTemplate -Destination $targetTemplatePath -Force
Write-Output "Template copied to: $targetTemplatePath"
} catch {
Write-Error "Failed to copy template: $($_.Exception.Message)"
exit 1
}

# Define the source Lua file path
$sourceFile = "$projectRoot\xapi.lua"

# Check if the source Lua file exists
if (-not (Test-Path -Path $sourceFile)) {
Write-Error "Error: $sourceFile not found."
exit 1
}

# Define the target directory for VLC extensions
$targetDir = Join-Path -Path "$env:APPDATA\vlc" -ChildPath "lua\extensions"

# Ensure the target directory exists
if (-not (Test-Path -Path $targetDir)) {
try {
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
Write-Output "Created VLC extensions directory at: $targetDir"
} catch {
Write-Error "Failed to create VLC extensions directory: $($_.Exception.Message)"
exit 1
}
}

# Copy the Lua file to the target directory
try {
Copy-Item -Path $sourceFile -Destination $targetDir -Force
Write-Output "xapi.lua has been successfully copied to $targetDir. Restart VLC to enable extension."
} catch {
Write-Error "Error: Failed to copy xapi.lua"
exit 1
}

# Pause at the end to allow the user to review logs
Add-Type -AssemblyName PresentationFramework
[System.Windows.MessageBox]::Show("xapi.lua has been successfully copied to $targetDir. Restart VLC to enable extension.", "xAPI VLC Installer") | Out-Null
24 changes: 24 additions & 0 deletions templates/xapi.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"actor": {
"account": {
"homePage": #API_HOMEPAGE,
"name": #API_USERID
},
"objectType": "Agent"
},
"verb": {
"id": #VERB
},
"object": {
"id": #OBJECT,
"objectType": "Activity"
},
"result": {
"extensions": {
#DURATION_URL: #DURATION,
#PROGRESS_URL: #PROGRESS,
#STATUS_URL: #STATUS,
#CURRENT_TIME_URL: #CURRENT_TIME
}
}
}
Loading