Skip to content

Commit

Permalink
Fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianDMG authored and BrianDMG committed Sep 18, 2021
2 parents 3e042ff + bcc962d commit c509ce8
Show file tree
Hide file tree
Showing 12 changed files with 775 additions and 308 deletions.
5 changes: 4 additions & 1 deletion files/cfg/config.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ cleanup:
#'true' enables garbage collection feature, 'false' disabled it
enable: true
#File types to delete on each run
include_file_types: "*.nfo"
include_file_types: "*.nfo"
notifications:
#Set to false to disable update notifications in the script and webUI
check_for_updates: true
13 changes: 8 additions & 5 deletions files/functions/Convert-File.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,22 @@ Function Convert-File {

$handbrake = Convert-Path "$($cfg.paths.handbrake)\$($bin)"

$singleQuoteRegex = @("'","","","´")
$containsSingleQuote = $null -ne ( $singleQuoteRegex | ? { $sourceFile -match $_ } )

If ($ConvertType -eq "Handbrake") {
# Handbrake CLI: https://trac.handbrake.fr/wiki/CLIGuide#presets
# Handbrake arguments
$hbArgs = @()
$hbArgs += "-i " #Flag to designate input file
If ( $sourceFile.Contains("'") ) {
If ( $containsSingleQuote ) {
$hbArgs += "`"$($sourceFile)`"" #Input file
}
Else {
$hbArgs += "`'$($sourceFile)`'" #Input file
}
$hbArgs += "-o " #Flag to designate output file
If ( $targetFile.Contains("'") ) {
If ( $containsSingleQuote ) {
$hbArgs += "`"$($targetFile)`"" #Output file
}
Else {
Expand Down Expand Up @@ -99,7 +102,7 @@ Function Convert-File {
$ffArgs += "-fflags " #Allows setting of formal flags
$ffArgs += "+genpts " #Suppresses pointer warning messages
$ffArgs += "-i " #Flag to designate input file
If ( $sourceFile.Contains("'") ) {
If ( $containsSingleQuote ) {
$ffArgs += "`"$($sourceFile)`""
}
Else {
Expand Down Expand Up @@ -194,7 +197,7 @@ Function Convert-File {
}

If ($KeepSubs) {
If ( $sourceFile.Contains("'") ) {
If ( $containsSingleQuote ) {
$info = Invoke-Expression "$($ffprobe) -i `"$($sourceFile)`" 2>&1"
}
Else {
Expand All @@ -215,7 +218,7 @@ Function Convert-File {
$ffArgs += "-sn " #Option to remove any existing subtitles
}
$ffArgs+= "-f mp4 "
If ( $targetFile.Contains("'") ) {
If ( $containsSingleQuote ) {
$ffArgs += "`"$($targetFile)`"" #Output file
}
Else {
Expand Down
5 changes: 4 additions & 1 deletion files/functions/Get-Codec.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Function Get-Codec {

$ffprobe = Convert-Path $(Join-Path "$($cfg.paths.ffmpeg)" "$($bin)")

$singleQuoteRegex = @("'","","","´")
$containsSingleQuote = $null -ne ( $singleQuoteRegex | ? { $sourceFile -match $_ } )

# Check codec with ffprobe
$ffprobeArgs += "-v "
$ffprobeArgs += "error "
Expand All @@ -40,7 +43,7 @@ Function Get-Codec {

$ffprobeArgs += "-of "
$ffprobeArgs += "default=noprint_wrappers=1:nokey=1 "
If ( $sourceFile.Contains("'") ) {
If ( $containsSingleQuote ) {
$ffprobeArgs += "`"$($sourceFile)`""
}
Else {
Expand Down
31 changes: 31 additions & 0 deletions files/functions/Get-LatestVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Function Get-LatestVersion {

Param(
[String]$CurrentVersion
)

Try {
#Set up API request
$request = Invoke-WebRequest -Uri "$($prop.urls.dockerhub_tag_api)"
$requestObj = $request.Content | ConvertFrom-Json

$dockerHubLatestTag = $requestObj.results[1].name

[Int] $currentTagInt = $CurrentVersion.replace('.','')
[Int] $dockerHubLatestTagInt = $requestObj.results[1].name.replace('v','').replace('.','')

$dockerHubLatestTagSha = $requestObj.results[1].images[0].digest.replace(':','-')
$dockerHubImageURL = $prop.urls.dockerhub_tag_url_a + $dockerHubLatestTag + $prop.urls.dockerhub_tag_url_b + $dockerHubLatestTagSha + $prop.urls.dockerhub_tag_url_c

If ( $dockerHubLatestTagInt -gt $currentTagInt ) {
Add-Log "`n🔔 Update available: $($dockerHubLatestTag) @ $($dockerHubImageURL)"
return $True
}

}
Catch {
Add-Log "Unable to check for updates."
Add-Log "ERROR: $($_)"
}

}
6 changes: 5 additions & 1 deletion files/functions/Write-Version.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Function Write-Version {

Add-Log "conv2mp4 - platform: $($prop.platform) ver: $($prop.version) rev: $($env:REVISION)`n$($prop.urls.gitlab) / $($prop.urls.dockerhub)"
Add-Log "conv2mp4 - platform: $($prop.platform) ver: $($prop.version) rev: $($env:REVISION)`n$($prop.urls.gitlab) | $($prop.urls.dockerhub)"

If ($cfg.notifications.check_for_updates) {
Get-LatestVersion -CurrentVersion $prop.version
}

}
21 changes: 0 additions & 21 deletions files/functions/validation/Confirm-ConfigBooleans.ps1

This file was deleted.

6 changes: 1 addition & 5 deletions files/init/preflight.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,13 @@ If ([Environment]::GetEnvironmentVariable('MEDIA_PATH')) {
Confirm-MediaPath -Path $cfg.paths.media

#Validate OutPath
If ($cfg.paths.use_out_path -eq 'true') {
If ($cfg.paths.use_out_path) {
If ([Environment]::GetEnvironmentVariable('OUTPATH')) {
$cfg.paths.out_path = $([Environment]::GetEnvironmentVariable('OUTPATH'))
}
Confirm-OutPath -Path $cfg.paths.out_path
}

#Validate config booleans
#TODO: REWORK for non-flat path
#Confirm-ConfigBooleans

#Rotate logs
If ($cfg.logging.rotate -gt 0) {
Remove-ExpiredLogs -LogPath $prop.paths.files.logDir -ExpiredLogInterval $cfg.logging.rotate
Expand Down
63 changes: 32 additions & 31 deletions files/listener/daemon.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,37 @@ $env:LOG_PATH = $prop.paths.files.logDir
#Start Pode Server
Start-PodeServer {

#Define Pode endpoint
Add-PodeEndpoint -Address $prop.listener.bind_host -Port $prop.listener.port -Protocol $prop.listener.protocol

Set-PodeViewEngine -Type Pode

Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
$logs = $(Get-ChildItem -Path $env:LOG_PATH -Recurse -Include *.log | Sort-Object -Descending -Property LastWriteTime -Top 10)
$stats = $(Get-Content $env:USAGE_STATISTICS | ConvertFrom-Yaml)
Write-PodeViewResponse -Path 'index' -Data @{ prop = $using:prop; cfg = $using:cfg; logs = $logs; stats = $stats; }
}

#Listener health check
Add-PodeRoute -Method Get -Path '/health' -ScriptBlock {
Write-PodeJsonResponse -Value @{ 'value' = "It's alive!" }
}

#Manual script execution
Add-PodeRoute -Method Get -Path '/run' -ScriptBlock {
Use-PodeScript -Path ./wrapper.ps1
}

#Scheduled script execution
Add-PodeSchedule -Name 'date' -Cron "$($cfg.schedule.run_schedule)" -ScriptBlock {
Use-PodeScript -Path ./wrapper.ps1
}

#View logs
Add-PodeRoute -Method Get -Path '/logs' -ScriptBlock {
$logs = $(Get-ChildItem -Path $env:LOG_PATH -Recurse -Include *.log | Sort-Object -Descending -Property LastWriteTime)
Write-PodeViewResponse -Path 'logs' -Data @{ prop = $using:prop; logs = $logs; }
}
#Define Pode endpoint
Add-PodeEndpoint -Address $prop.listener.bind_host -Port $prop.listener.port -Protocol $prop.listener.protocol

Set-PodeViewEngine -Type Pode

Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
$logs = $(Get-ChildItem -Path $env:LOG_PATH -Recurse -Include *.log | Sort-Object -Descending -Property LastWriteTime -Top 10)
$stats = $(Get-Content $env:USAGE_STATISTICS | ConvertFrom-Yaml)

Write-PodeViewResponse -Path 'index' -Data @{ prop = $using:prop; cfg = $using:cfg; logs = $logs; stats = $stats; }
}

#Listener health check
Add-PodeRoute -Method Get -Path '/health' -ScriptBlock {
Write-PodeJsonResponse -Value @{ 'value' = "It's alive!" }
}

#Manual script execution
Add-PodeRoute -Method Get -Path '/run' -ScriptBlock {
Use-PodeScript -Path ./wrapper.ps1
}

#Scheduled script execution
Add-PodeSchedule -Name 'date' -Cron "$($cfg.schedule.run_schedule)" -ScriptBlock {
Use-PodeScript -Path ./wrapper.ps1
}

#View logs
Add-PodeRoute -Method Get -Path '/logs' -ScriptBlock {
$logs = $(Get-ChildItem -Path $env:LOG_PATH -Recurse -Include *.log | Sort-Object -Descending -Property LastWriteTime)
Write-PodeViewResponse -Path 'logs' -Data @{ prop = $using:prop; logs = $logs; }
}

}
Loading

0 comments on commit c509ce8

Please sign in to comment.