Skip to content

Instantly share code, notes, and snippets.

@alsolovyev
Last active October 16, 2024 03:09
Show Gist options
  • Select an option

  • Save alsolovyev/b0a03e9a8cb0ef253dbfba7e65a6074a to your computer and use it in GitHub Desktop.

Select an option

Save alsolovyev/b0a03e9a8cb0ef253dbfba7e65a6074a to your computer and use it in GitHub Desktop.
Batch scripts

Bash Scripts

ls - list directory contents
mk - create a directory and move into it
rm - remove files or directories
s - open files or directories in sublime text 3
st - open Twitch streams in a video player(mpv default)
touch - create files
yt - download videos from YouTube.com
zip - create a password-protected ZIP file(7zip)
SyncTime - synchronize time on local computer using w32tm

@ECHO OFF
:: Name: br
:: Author: Jane Rivas
:: Description: Open blu-ray device with mpv player
:: Usage: br "That Awkward Moment"
:: Version: 0.1
SET blu-ray_path=%1
SET player="mpv"
:: Check if player is installed
WHERE %player% > nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
ECHO %player% is not installed on your system.
EXIT /B 1
)
%player% bd:// --bluray-device=%blu-ray_path%
@echo off
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"^
--app="https://twitch.tv/%1/chat"^
--window-size="500,500"
@echo off
dir /b %1
@echo off
mkdir "%~1" && cd "%~1"
@echo off
if exist %1\* (rmdir %1 /S /Q) else del %1
@echo off
set editor="C:\Program Files\Sublime Text 3\sublime_text.exe"
start "" %editor% %1
::
:: Make streamlink easier to use (only for twitch.tv)
::
:: Requirements:
:: - streamlink
:: - media player (mpv, vlc, etc)
::
:: Usage:
:: - st pingeee
:: - st ladyd audio_only
::
:: Author: janeRivas <[email protected]>
:: GitHub: https://github.com/alsolovyev
::
@echo OFF
:: Clear screen
:: CLS
:: Get stream name
if "%~1"=="" (
set /p name="Enter streamer username: "
) else (
set name=%~1
)
:: Get stream quality
if "%~2"=="" (
set quality=best
) else (
if "%~2"=="a" (set is_audio=true) else (set quality=%~2)
)
:: Set player position:
:: tight top => 380-10+10
:: left top => 380+10+10
:: right bottom => 380-10-10
:: left bottom => 380+10-10
set geometry=380-9+9
:: Set media player
set player="mpv.com --ontop --geometry=%geometry%"
set player_audio="mpv.com"
:: Use this if you want streamlink to only pass a URL to your player and
:: let it handle the transport of the stream itself.
:: player-passthrough: https://streamlink.github.io/cli.html?highlight=player%20passthrough#cmdoption-player-passthrough
:: available value: hls, https, rtmp
:: default ???
set passthrough=hls
:: Number of threads to use when streaming HLS streams
:: hls-segment-threads: https://streamlink.github.io/cli.html?highlight=player%20passthrough#cmdoption-hls-segment-threads
:: minimum value is 1 and maximum is 10
:: default 1
set hsl_segment_threads=4
:: How many segments from the end to start live HLS streams on.
:: The lower the value the lower latency from the source
:: you will be, but also increases the chance of buffering. Default is: 3.
set hls_live_edge=2
:: Twitch options (https://streamlink.github.io/cli.html#twitch):
:: - twitch-disable-hosting
:: - twitch-disable-ads
:: - twitch-disable-reruns
:: - twitch-low-latency
set twitch_options=--twitch-disable-hosting --twitch-disable-ads --twitch-low-latency
set twitch_options_audio=--twitch-disable-hosting --twitch-disable-ads
:: Set window title
title=%name%
set player_title="{author} - {category} - {game} - {title}"
:: Change url
if x%name:miker=%==x%name% (
set url=twitch.tv/%name%
) else (
set url=goodgame.ru/channel/%name%
)
::
if "%is_audio%"=="true" (
set clo=%url% audio_only --player %player_audio%
) else (
set clo=%url%^
%quality%^
--player %player%^
--title %player_title%^
--verbose-player^
%twitch_options%^
--hls-segment-threads %hsl_segment_threads%^
--hls-live-edge %hls_live_edge%
)
:: Open stream
streamlink %clo%
:: Set window title
:end
title=%name%'s stream has ended
@echo off
SETLOCAL EnableExtensions DisableDelayedExpansion
:: Name: SyncTime
:: Author: Jane Rivas
:: Description: Synchronize time on local computer using w32tm
:: Version: 0.1
SET service=w32time
SC QUERYEX %service% | FIND "STATE" | FIND /v "RUNNING" > NUL && (
ECHO %service% is not running
ECHO Start %service%
NET START %service% > NUL || (
ECHO %service% won't start
PAUSE
EXIT /B 1
)
ECHO %service% is started
GOTO sync
EXIT /B 0
) || (
ECHO %service% is running
GOTO sync
EXIT /B 0
)
:sync
w32tm /resync /rediscover
IF ERRORLEVEL 1 (
PAUSE
) || (
EXIT /B 0
)
@echo off
:next
if "%1" equ "" goto:eof
if exist "%1" (
echo "File %1 exists"
) else (
type nul > %1
)
shift
goto:next
::
:: Download YouTube videos in "mp4" format
:: with the best available video and audio quality
:: using "youtube-dl"
::
:: Requirements:
:: - youtube-dl
:: - ffmpeg or avconv
::
:: Usage: yt https://youtu.be/aqz-KE-bpKQ
::
:: Author: janeRivas <[email protected]>
:: GitHub: https://github.com/alsolovyev
::
@ECHO OFF
REM Change the default download location.
REM Default: the path of running script.
SET download_location="./"
REM Specify the full path to "youtube-dl" in your system.
REM Use the program name if it is specified in the environment variable "path".
REM https://ytdl-org.github.io/youtube-dl/download.html
SET youtube-dl="youtube-dl"
REM "FFmpeg" is required to combine video and audio files.
REM Specify the full path to "ffmpeg" in your system.
REM Use the program name if it is specified in the environment variable "path".
SET ffmpeg="ffmpeg"
REM Location in the filesystem where youtube-dl can
REM store some downloaded information permanently.
SET cache_dir="./"
REM Set the best video and audio quality.
SET video_format="bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio"
REM Specify output container format.
SET container_format="mp4"
REM Clear screen.
CLS
REM Not necessary cuz youtube-dl handle this error.
REM Check if parameter passed.
REM IF "%~1"=="" (
REM ECHO You must provide at least one URL.
REM EXIT /B 1
REM )
REM Check if "youtub-dl" is installed
WHERE %youtube-dl% > nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
ECHO Youtube-dl is not installed on your system.
ECHO https://ytdl-org.github.io/youtube-dl/download.html
EXIT /B 1
)
REM Check if "ffmpeg" is installed
WHERE %ffmpeg% > nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
ECHO FFmpeg is not installed on your system.
ECHO https://ffmpeg.org/
EXIT /B 1
)
REM Is it necessary???
REM Remove the last slash of the downloading path if exists
REM IF %download_location:~-1%==\ (
REM SET download_location=%download_location:~0,-1%
REM )
REM Check if user want to download a playlist.
ECHO %~1%|find "playlist" >nul
IF ERRORLEVEL 1 (
SET output_filename_template="%download_location%\%%(title)s.%%(ext)s"
) ELSE (
SET output_filename_template="%download_location%\%%(playlist_index)s. %%(title)s.%%(ext)s"
)
%youtube-dl%^
--cache-dir %cache_dir%^
--format %video_format%^
--merge-output-format %container_format%^
--output %output_filename_template%^
--add-metadata^
--mark-watched^
%~1%
@title Creating archive...
@echo off
setlocal DisableDelayedExpansion
:: Variables
set app=%~dp07zip\7za.exe
set password=
set name=D:\Desktop\
set files=
set additOpt=-mm=Deflate -mfb=258 -mpass=15
:: Argument parser
:nextArg
if "%1" equ "" goto :exitParser
if "%1" neq "-p" if "%1" neq "-n" set files=%1 %files% && shift && goto :nextArg
if "%1" equ "-p" set password=%2 && shift && shift && goto :nextArg
if "%1" equ "-n" set name=%name%%2.zip && shift && shift && goto :nextArg
:exitParser
:: Run
%app% a %name% %additOpt% -r -sse -p%password% %files%
:: Complete
@title Archive "%name%" has been created
rundll32 user32.dll,MessageBeep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment