Skip to content

Instantly share code, notes, and snippets.

@fcallejon
Last active April 13, 2022 21:05
Show Gist options
  • Select an option

  • Save fcallejon/ab57a6b2c35eccc31031090274e62ba1 to your computer and use it in GitHub Desktop.

Select an option

Save fcallejon/ab57a6b2c35eccc31031090274e62ba1 to your computer and use it in GitHub Desktop.
AceStream, Docker and PS
# Requires -RunAsAdministrator
<#
Docker tiene que estar ejecutandose con TCP en el puerto 2375 habiliado
O deberas iniciar Docker y ejecutar el comando de abajo:
docker run -d -p 6878:6878 -p 8621:8621 -e allow_remote=1 jackwzh/acestream-server
Docker needs to be running with TCP enabled on port 2375 enabled
Or you need to start Docker and execute the command below:
docker run -d -p 6878:6878 -p 8621:8621 -e allow_remote=1 jackwzh/acestream-server
#>
param (
[Parameter(Mandatory = $true)]
[string]$Id,
[Parameter(Mandatory = $false)]
[string]$VlcPath = "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
Write-Host "Starting Acestream Server for $Id"
$aceurl = "http://localhost:6878/ace/getstream?format=json&id=$Id"
try {
$dockerProcesses = Get-Process "*docker desktop*"
if ($null -eq $dockerProcesses) {
Write-Host "Starting Docker Desktop ..."
Start-Process -FilePath "C:\Program Files\Docker\Docker\Docker Desktop.exe" -ArgumentList "-d" -Verb runAs
Write-Host "Giving Docker Desktop 10 secs..."
Start-Sleep -Seconds 30
$dockerService = Get-Service 'com.docker.service'
$dockerService.WaitForStatus('Running', '00:01:00')
}
else {
Write-Host "Docker already running"
}
Write-Host "Clearing old Docker Containers for image 'jackwzh/acestream-server'..."
curl -s -X GET "http://localhost:2375/containers/json?all=false"
| ConvertFrom-Json
| Where-Object { $_.Image -ieq "jackwzh/acestream-server" }
| ForEach-Object {
$containerId = $_[0].Id
Write-Host "Stopping Docker Container for image 'jackwzh/acestream-server' with id '$containerId'"
&docker stop $containerId
Write-Host "Removing Docker Container for image 'jackwzh/acestream-server' with id '$containerId'"
&docker rm $containerId
}
Write-Host "Checking if Docker Container for image 'jackwzh/acestream-server' is running..."
$currentContainer =
curl -s -X GET "http://localhost:2375/containers/json?all=false"
| ConvertFrom-Json
| Where-Object { $_.Image -ieq "jackwzh/acestream-server" -and $_.State -ieq "running" }
if ($null -eq $currentContainer -or $currentContainer.Count -eq 0) {
Write-Host "Starting Docker Container for image 'jackwzh/acestream-server' ..."
&docker --% run -d -p 6878:6878 -p 8621:8621 -e allow_remote=1 jackwzh/acestream-server
Start-Sleep -Seconds 2
}
else {
Write-Host "Docker Container for image 'jackwzh/acestream-server' is already running"
}
Write-Host "Getting Acestream URL for $Id using '$aceurl'"
$errorAndPlaybackUrl = curl -s -X GET $aceurl | ConvertFrom-Json | Select-Object Error -ExpandProperty response | Select-Object Error, playback_url
if ($null -ne $errorAndPlaybackUrl.error) {
throw $errorAndPlaybackUrl.error
}
$playbackUrl = $errorAndPlaybackUrl.playback_url
Write-Host "Opening Acestream playback url: $playbackUrl"
&$VlcPath "$playbackUrl"
}
catch {
Write-Host "An error occurred:"
Write-Host $_
Write-Host ""
Write-Host "Remember to start Acestream Docker with: "
Write-Host "docker run -d -p 6878:6878 -p 8621:8621 -e allow_remote=1 jackwzh/acestream-server"
Write-Host ""
exit -1
}
finally {
}
param (
[Parameter(Mandatory = $false)]
[switch]$StopDocker = $false
)
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "This needs to be run as an administrator." -ForegroundColor Red
$currentFolder = $env:UserProfile
$scriptPath = (Get-Variable MyInvocation).Value.MyCommand.Path
$relaunchArgs = '-ExecutionPolicy Unrestricted -file "' + $scriptPath
if ($StopDocker.IsPresent) {
$relaunchArgs += '" -StopDocker'
}
Write-Host "Relaunching script with elevated privileges..."
Write-Host "Current folder: $currentFolder"
Write-Host "Script path: $scriptPath"
Write-Host "Relaunch arguments: $relaunchArgs"
Start-Process pwsh.exe -Verb runAs -ArgumentList $relaunchArgs -WorkingDirectory $currentFolder -PassThru
return
}
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
Write-Host "Closing Acestream containers if any..."
$currentContainer =
curl -s -X GET "http://localhost:2375/containers/json?all=false"
| ConvertFrom-Json
| Where-Object { $_.Image -ieq "jackwzh/acestream-server" }
$currentContainer
| ForEach-Object {
$containerId = $currentContainer[0].Id
Write-Host "Stopping Docker Container for image 'jackwzh/acestream-server' with id '$containerId'"
&docker stop $containerId
Write-Host "Removing Docker Container for image 'jackwzh/acestream-server' with id '$containerId'"
&docker rm $containerId
}
Write-Host "Stopping VLC"
Stop-Process -Name "*vlc*"
if ($StopDocker.IsPresent) {
Write-Host "Stopping Docker"
$isrunning = Get-Process "Docker Desktop" -ErrorAction SilentlyContinue
if ($isrunning) {
$isrunning.CloseMainWindow()
$isrunning | Stop-Process -Force
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment