diff --git a/.gitignore b/.gitignore index 1d5b7b8..d4b4b9c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ archive test.py a.py subprocess_time.py +env2/** +venv3/** +.gitignore +bin/** \ No newline at end of file diff --git a/install-pyenv-win.ps1 b/install-pyenv-win.ps1 new file mode 100644 index 0000000..85b023c --- /dev/null +++ b/install-pyenv-win.ps1 @@ -0,0 +1,156 @@ +<# + .SYNOPSIS + Installs pyenv-win + + .DESCRIPTION + Installs pyenv-win to $HOME\.pyenv + If pyenv-win is already installed, try to update to the latest version. + + .PARAMETER Uninstall + Uninstall pyenv-win. Note that this uninstalls any Python versions that were installed with pyenv-win. + + .INPUTS + None. + + .OUTPUTS + None. + + .EXAMPLE + PS> install-pyenv-win.ps1 + + .LINK + Online version: https://pyenv-win.github.io/pyenv-win/ +#> + +param ( + [Switch] $Uninstall = $False +) + +$PyEnvDir = "${env:USERPROFILE}\.pyenv" +$PyEnvWinDir = "${PyEnvDir}\pyenv-win" +$BinPath = "${PyEnvWinDir}\bin" +$ShimsPath = "${PyEnvWinDir}\shims" + +Function Remove-PyEnvVars() { + $PathParts = [System.Environment]::GetEnvironmentVariable('PATH', "User") -Split ";" + $NewPathParts = $PathParts.Where{ $_ -ne $BinPath }.Where{ $_ -ne $ShimsPath } + $NewPath = $NewPathParts -Join ";" + [System.Environment]::SetEnvironmentVariable('PATH', $NewPath, "User") + + [System.Environment]::SetEnvironmentVariable('PYENV', $null, "User") + [System.Environment]::SetEnvironmentVariable('PYENV_ROOT', $null, "User") + [System.Environment]::SetEnvironmentVariable('PYENV_HOME', $null, "User") +} + +Function Remove-PyEnv() { + Write-Host "Removing $PyEnvDir..." + If (Test-Path $PyEnvDir) { + Remove-Item -Path $PyEnvDir -Recurse + } + Write-Host "Removing environment variables..." + Remove-PyEnvVars +} + +Function Get-CurrentVersion() { + $VersionFilePath = "$PyEnvDir\.version" + If (Test-Path $VersionFilePath) { + $CurrentVersion = Get-Content $VersionFilePath + } + Else { + $CurrentVersion = "" + } + + Return $CurrentVersion +} + +Function Get-LatestVersion() { + $LatestVersionFilePath = "$PyEnvDir\latest.version" + (New-Object System.Net.WebClient).DownloadFile("https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/.version", $LatestVersionFilePath) + $LatestVersion = Get-Content $LatestVersionFilePath + + Remove-Item -Path $LatestVersionFilePath + + Return $LatestVersion +} + +Function Main() { + If ($Uninstall) { + Remove-PyEnv + If ($? -eq $True) { + Write-Host "pyenv-win successfully uninstalled." + } + Else { + Write-Host "Uninstallation failed." + } + exit + } + + $BackupDir = "${env:Temp}/pyenv-win-backup" + + $CurrentVersion = Get-CurrentVersion + If ($CurrentVersion) { + Write-Host "pyenv-win $CurrentVersion installed." + $LatestVersion = Get-LatestVersion + If ($CurrentVersion -eq $LatestVersion) { + Write-Host "No updates available." + exit + } + Else { + Write-Host "New version available: $LatestVersion. Updating..." + + Write-Host "Backing up existing Python installations..." + $FoldersToBackup = "install_cache", "versions", "shims" + ForEach ($Dir in $FoldersToBackup) { + If (-not (Test-Path $BackupDir)) { + New-Item -ItemType Directory -Path $BackupDir + } + Move-Item -Path "${PyEnvWinDir}/${Dir}" -Destination $BackupDir + } + + Write-Host "Removing $PyEnvDir..." + Remove-Item -Path $PyEnvDir -Recurse + } + } + + New-Item -Path $PyEnvDir -ItemType Directory + + $DownloadPath = "$PyEnvDir\pyenv-win.zip" + + (New-Object System.Net.WebClient).DownloadFile("https://github.com/pyenv-win/pyenv-win/archive/master.zip", $DownloadPath) + + Start-Process -FilePath "powershell.exe" -ArgumentList @( + "-NoProfile", + "-Command `"Microsoft.PowerShell.Archive\Expand-Archive -Path $DownloadPath -DestinationPath $PyEnvDir`"" + ) -NoNewWindow -Wait + + Move-Item -Path "$PyEnvDir\pyenv-win-master\*" -Destination "$PyEnvDir" + Remove-Item -Path "$PyEnvDir\pyenv-win-master" -Recurse + Remove-Item -Path $DownloadPath + + # Update env vars + [System.Environment]::SetEnvironmentVariable('PYENV', "${PyEnvWinDir}\", "User") + [System.Environment]::SetEnvironmentVariable('PYENV_ROOT', "${PyEnvWinDir}\", "User") + [System.Environment]::SetEnvironmentVariable('PYENV_HOME', "${PyEnvWinDir}\", "User") + + $PathParts = [System.Environment]::GetEnvironmentVariable('PATH', "User") -Split ";" + + # Remove existing paths, so we don't add duplicates + $NewPathParts = $PathParts.Where{ $_ -ne $BinPath }.Where{ $_ -ne $ShimsPath } + $NewPathParts = ($BinPath, $ShimsPath) + $NewPathParts + $NewPath = $NewPathParts -Join ";" + [System.Environment]::SetEnvironmentVariable('PATH', $NewPath, "User") + + If (Test-Path $BackupDir) { + Write-Host "Restoring Python installations..." + Move-Item -Path "$BackupDir/*" -Destination $PyEnvWinDir + } + + If ($? -eq $True) { + Write-Host "pyenv-win is successfully installed. You may need to close and reopen your terminal before using it." + } + Else { + Write-Host "pyenv-win was not installed successfully. If this issue persists, please open a ticket: https://github.com/pyenv-win/pyenv-win/issues." + } +} + +Main diff --git a/requirements.txt b/requirements.txt index 0e315d0..d4172c3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ colorama==0.4.6 python-dotenv==0.21.0 pytz==2022.6 requests==2.28.1 +streamlink==5.1.0 \ No newline at end of file diff --git a/start.bat b/start.bat new file mode 100644 index 0000000..11965de --- /dev/null +++ b/start.bat @@ -0,0 +1,23 @@ +rem @echo off +setlocal + +rem Set the path to your virtual environment +set VENV_PATH=.\venv3 +rem Activate the virtual environment + call "%VENV_PATH%\Scripts\activate.bat" + rem pyenv-venv activate twitcharchive + + pip install -r requirements.txt + +:loop + + rem Run the desired command in the virtual environment + python twitch-archive.py -u %1 + + @REM rem if the program exits with a non-zero error code, go back to the beginning of the loop + @REM if %errorlevel% neq 0 ( + goto loop + @REM ) + +rem Deactivate the virtual environment +call "%VENV_PATH%\Scripts\deactivate.bat" diff --git a/startmulti - Copy.bat b/startmulti - Copy.bat new file mode 100644 index 0000000..bf735d0 --- /dev/null +++ b/startmulti - Copy.bat @@ -0,0 +1,12 @@ +@echo off +setlocal + +rem Loop through the list of parameters +for %%P in (%*) do ( + + rem Start a new instance of start.bat for this parameter + start /b cmd /c "start start.bat %%P" + +) + +echo All instances have been started. Exiting... diff --git a/startmulti.bat b/startmulti.bat new file mode 100644 index 0000000..bf735d0 --- /dev/null +++ b/startmulti.bat @@ -0,0 +1,12 @@ +@echo off +setlocal + +rem Loop through the list of parameters +for %%P in (%*) do ( + + rem Start a new instance of start.bat for this parameter + start /b cmd /c "start start.bat %%P" + +) + +echo All instances have been started. Exiting... diff --git a/twitch-archive.py b/twitch-archive.py index edc51d3..4854a0d 100644 --- a/twitch-archive.py +++ b/twitch-archive.py @@ -8,21 +8,21 @@ from email.mime.text import MIMEText class TwitchArchive: def __init__(self): # user configuration - self.username = "dogzilar123" # Twitch streamer username + self.username = "vinesauce" # Twitch streamer username self.quality = "best" # Qualities options: best/source high/720p medium/540p low/360p audio_only # global configuration self.root_path = r"archive" # Path where this script saves everything (livestream,VODs,chat,metadata) - self.rclone_path = "remote:path" # Path to rclone remote storage - self.refresh = 5.0 # Time between checking (5.0 is recommended), avoid less than 1.0 + self.rclone_path = "MaddoNAS:Mediaroot/media/streams" # Path to rclone remote storage + self.refresh = 60.0 # Time between checking (5.0 is recommended), avoid less than 1.0 self.streamlink_ttvlol = 0 # 0 - disable blocking ads with ttvlol, 1 - enable blocking ads with ttvlol, Uses this repo: https://github.com/2bc4/streamlink-ttvlol to block ads with ttvlol. Follows the steps on the repo to enable it. self.notifications = 0 # 0 - disable email notification of current seccion, 1 - enable email notification of current seccion self.downloadMETADATA = 1 # 0 - disable metadata downloading, 1 - enable metadata downloading self.downloadVOD = 1 # 0 - disable VOD downloading after stream finished, 1 - enable VOD downloading after stream finished (this option downloads the latest public vod) self.downloadCHAT = 1 # 0 - disable chat downloading and rendering, 1 - enable chat downloading and rendering - self.uploadCloud = 0 # 0 - disable upload to remote cloud, 1 - enable upload to remote cloud + self.uploadCloud = 1 # 0 - disable upload to remote cloud, 1 - enable upload to remote cloud self.deleteFiles = 0 # 0 - disable the deleting of files from current seccion after being uploaded to the cloud, 1 - enable the deleting files of files from current seccion after being uploaded to the cloud (BE CAREFUL WITH THIS OPTION) self.onlyRaw = 0 # 0 - disable the converting of ts files to mp3/mp4, 1 - enable the converting of ts files to mp3/mp4 (only works for recording, the vod will still be downloaded to mp3/mp4) - self.cleanRaw = 0 # 0 - disable the deleting of raw (.ts) files, 1 - enable the deleteing of raw (.ts) files (if upload enable they will be deleted before) + self.cleanRaw = 1 # 0 - disable the deleting of raw (.ts) files, 1 - enable the deleteing of raw (.ts) files (if upload enable they will be deleted before) self.hls_segments = 3 # 1-10 for live stream, it's possible to use multiple threads to potentially increase the throughput. 2-3 is enough self.hls_segmentsVOD = 10 # 1-10 for downloading vod, it's possible to use multiple threads to potentially increase the throughput