What makes us different from other similar websites? › Forums › Tech › How to Stop Ad Blocker Detection on Websites Like YouTube › Reply To: How to Stop Ad Blocker Detection on Websites Like YouTube
January 23, 2026 at 4:24 pm
#8401
Moderator
Updated Script
#!/bin/bash
# ASCII Art Functions
print_banner() {
echo "+---------------------------------+"
echo "|===========TAKS SHACK============|"
echo "|======https://taksshack.com======|"
echo "+---------------------------------+"
}
print_section_header() {
echo "---=[ $@ ]=---------------------------------------------------"
echo ""
}
# --- Configuration ---
YTDLP_URL="https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp"
YTDLP_BIN="./yt-dlp"
PYTHON_SCRIPT="yt_dlp_player.py"
OUTPUT_BASENAME="downloaded_video"
LAST_SAVE_FOLDER_FILE=".last_save_folder"
AUDIO_TOOLS_INSTALLED_FLAG=".audio_tools_installed_by_script_flag"
FFMPEG_INSTALLED_FLAG=".ffmpeg_installed_by_script_flag"
PLAYLIST_FILE="video_playlist.txt"
# --- Main Script Execution ---
print_banner
print_section_header "SYSTEM SETUP"
if [ ! -f "$YTDLP_BIN" ] || [ ! -x "$YTDLP_BIN" ]; then
echo " yt-dlp binary not found. Downloading..."
if command -v curl &> /dev/null; then
curl -L "$YTDLP_URL" -o "$YTDLP_BIN"
elif command -v wget &> /dev/null; then
wget -O "$YTDLP_BIN" "$YTDLP_URL"
fi
chmod +x "$YTDLP_BIN"
fi
# Tool Check
command -v ffmpeg &> /dev/null || (sudo apt update && sudo apt install -y ffmpeg espeak-ng alsa-utils && touch "$FFMPEG_INSTALLED_FLAG")
print_section_header "PYTHON SCRIPT CREATION"
cat <<'EOF' > "$PYTHON_SCRIPT"
import subprocess
import os
import sys
import glob
import re
import shutil
YTDLP_PATH = "./yt-dlp"
OUTPUT_BASENAME = "downloaded_video"
LAST_SAVE_FOLDER_FILE = ".last_save_folder"
PLAYLIST_FILE = "video_playlist.txt"
PROGRESS_RE = re.compile(r'\[download\]\s+(\d+\.?\d*)%')
# Global session cookie path
session_cookie_path = None
def print_ascii_header(text, char='='):
print("-" * 60)
print(f" {text}")
print("-" * 60)
def draw_ascii_progress_bar(percentage, bar_length=40):
filled_len = int(bar_length * percentage // 100)
bar = '#' * filled_len + '-' * (bar_length - filled_len)
sys.stdout.write(f'\rDownloading: [ {bar} ] {percentage:6.2f}%')
sys.stdout.flush()
def get_monitor_choice():
print("\n Select monitor for playback (0-9).")
choice = input(" Monitor index [default 0]: ").strip()
return choice if choice else "0"
def show_cookie_help():
print("\n--- COOKIE ASSISTANCE ---")
print("1. Chrome / Brave / Opera")
print("2. Firefox")
print("3. Microsoft Edge")
print("4. Safari")
print("5. Skip instructions and enter path")
b_choice = input("\nSelect your browser for instructions: ").strip()
if b_choice == '1':
print("\n[ Chrome / Chromium ]")
print("1. Install: https://chromewebstore.google.com/detail/get-cookiestxt-locally/cclelndahbckbenkjhflpdbgdldlbecc")
print("2. Open YouTube, click the extension icon, and click 'Export'.")
print("3. Save the file and provide the path here.")
elif b_choice == '2':
print("\n[ Firefox ]")
print("1. Search Firefox Add-ons for 'Export Cookies.txt'.")
print("2. Export while on the YouTube tab.")
print("3. Provide the saved file path here.")
elif b_choice == '3':
print("\n[ Microsoft Edge ]")
print("1. Use the Chrome Web Store link (Edge supports Chrome extensions):")
print(" https://chromewebstore.google.com/detail/get-cookiestxt-locally/cclelndahbckbenkjhflpdbgdldlbecc")
print("2. Export and provide the path here.")
elif b_choice == '4':
print("\n[ Safari ]")
print("1. It is recommended to use Chrome or Firefox for exporting cookies.txt.")
print("2. Otherwise, use a 'cookies.txt' extension from the Mac App Store.")
def run_yt_dlp(youtube_link, cookie_option=None):
info_cmd = [YTDLP_PATH, '--get-title', '--print', '%(title)s', '--print', '%(id)s.%(ext)s', youtube_link]
if cookie_option:
info_cmd.extend(['--cookies', os.path.expanduser(cookie_option)])
suggested_filename = None
try:
res = subprocess.run(info_cmd, capture_output=True, text=True, check=True)
lines = res.stdout.strip().split('\n')
if len(lines) >= 2:
suggested_filename = re.sub(r'[\\/:*?"<>|]', '_', lines[0].strip()) + ".mp4"
except: pass
dl_cmd = [YTDLP_PATH, '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best',
'--merge-output-format', 'mp4', '--output', f"{OUTPUT_BASENAME}.%(ext)s", youtube_link]
if cookie_option:
dl_cmd.extend(['--cookies', os.path.expanduser(cookie_option)])
try:
p = subprocess.Popen(dl_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
for line in iter(p.stdout.readline, ''):
m = PROGRESS_RE.search(line)
if m: draw_ascii_progress_bar(float(m.group(1)))
return p.wait() == 0, suggested_filename
except: return False, suggested_filename
def attempt_download_with_retry(link):
global session_cookie_path
success, name = run_yt_dlp(link, cookie_option=session_cookie_path)
if not success and not session_cookie_path:
print("\n[!] Download failed. Link may be restricted (Age-gate/Login).")
show_cookie_help()
path = input("\n Please enter path to cookies.txt (or ENTER to skip): ").strip()
if path and os.path.exists(os.path.expanduser(path)):
session_cookie_path = path
print(f" Retrying with cookies: {session_cookie_path}...")
success, name = run_yt_dlp(link, cookie_option=session_cookie_path)
elif not success and session_cookie_path:
success, name = run_yt_dlp(link, cookie_option=session_cookie_path)
return success, name
def _process_link_workflow(youtube_link, last_folder, monitor_id=None, mode='stream'):
print_ascii_header(f"PROCESSING: {youtube_link}")
if monitor_id is None:
monitor_id = get_monitor_choice()
success, suggested = attempt_download_with_retry(youtube_link)
if not success:
print("\n[!] Could not process link.")
return False, last_folder
files = glob.glob(f"{OUTPUT_BASENAME}.*")
if not files:
print("\n[!] Video file not found after download.")
return False, last_folder
final_file = files[0]
# Run playback
subprocess.run(["mpv", "--fs", f"--screen={monitor_id}", final_file])
if mode == 'download':
save_choice = input("Save video? (y/n): ").lower()
if save_choice == 'y':
folder_prompt = f"Use {last_folder}? (y/n): " if last_folder else "Enter Path: "
use_last = input(folder_prompt).lower() if last_folder else 'n'
target_folder = last_folder if use_last == 'y' else input("Path: ").strip()
if target_folder:
os.makedirs(target_folder, exist_ok=True)
dest_path = os.path.join(target_folder, suggested or final_file)
try:
shutil.move(final_file, dest_path)
print(f" Saved to: {dest_path}")
with open(LAST_SAVE_FOLDER_FILE, 'w') as f: f.write(target_folder)
return True, target_folder
except Exception as e:
print(f" Error saving file: {e}")
# Clean up if not saved or if in stream mode
if os.path.exists(final_file):
os.remove(final_file)
return True, last_folder
def silent_batch_download(last_save_folder):
print_ascii_header("SILENT BATCH DOWNLOAD", '-')
print(" Enter links (one per line). Press ENTER twice to begin.")
links = []
while True:
l = sys.stdin.readline().strip()
if not l: break
links.append(l)
if not links: return last_save_folder
if last_save_folder and os.path.isdir(last_save_folder):
target_folder = last_save_folder if input(f" Use folder '{last_save_folder}'? (y/n): ").lower() == 'y' else input(" Path: ").strip()
else: target_folder = input(" Path: ").strip()
if not target_folder: return last_save_folder
os.makedirs(target_folder, exist_ok=True)
dupe_action = None
for i, link in enumerate(links):
print(f"\n[{i+1}/{len(links)}] {link}")
success, name = attempt_download_with_retry(link)
if success:
if name:
dest = os.path.join(target_folder, name)
if os.path.exists(dest):
if not dupe_action:
choice = input(f" '{name}' exists. (s)kip or (o)verwrite all? ").lower()
dupe_action = 'overwrite' if choice == 'o' else 'skip'
if dupe_action == 'skip': continue
else: os.remove(dest)
files = glob.glob(f"{OUTPUT_BASENAME}.*")
if files: shutil.move(files[0], os.path.join(target_folder, name or files[0]))
else:
print(f" Skipping {link} due to failure.")
with open(LAST_SAVE_FOLDER_FILE, 'w') as f: f.write(target_folder)
return target_folder
def main():
last_folder = ""
if os.path.exists(LAST_SAVE_FOLDER_FILE):
with open(LAST_SAVE_FOLDER_FILE, 'r') as f: last_folder = f.read().strip()
while True:
print_ascii_header("MAIN MENU", '=')
if session_cookie_path: print(f" SESSION COOKIES: {session_cookie_path}")
print(" 1. Stream a SINGLE YouTube video link")
print(" 2. Download and play a SINGLE YouTube video link")
print(" 3. Download and play MULTIPLE YouTube video links")
p_links = []
if os.path.exists(PLAYLIST_FILE):
with open(PLAYLIST_FILE, 'r') as f: p_links = [l for l in f if l.strip()]
print(f" 4. Play from PLAYLIST ({len(p_links)} links)")
print(" 5. Silent Batch DOWNLOAD (No playback)")
print(" 6. Exit and clean up")
choice = input(" Choice: ").strip()
if choice == '1':
link = input("Link: ")
_process_link_workflow(link, last_folder, mode='stream')
elif choice == '2':
link = input("Link: ")
_, last_folder = _process_link_workflow(link, last_folder, mode='download')
elif choice == '3':
print("Enter links (double enter to start):")
links = []
while True:
l = sys.stdin.readline().strip()
if not l: break
links.append(l)
if links:
m_id = get_monitor_choice()
for l in links: _, last_folder = _process_link_workflow(l, last_folder, monitor_id=m_id, mode='download')
elif choice == '4':
if p_links:
m_id = get_monitor_choice()
for l in p_links: _process_link_workflow(l.strip(), last_folder, monitor_id=m_id, mode='stream')
elif choice == '5':
last_folder = silent_batch_download(last_folder)
elif choice == '6':
sys.exit(5)
if __name__ == "__main__":
main()
EOF
# --- FINAL CLEANUP BASH LOGIC ---
print_section_header "RUNNING PLAYER"
python3 "$PYTHON_SCRIPT"
PYTHON_EXIT_CODE=$?
[ -f "$PYTHON_SCRIPT" ] && rm "$PYTHON_SCRIPT"
[ -f "$YTDLP_BIN" ] && rm "$YTDLP_BIN"
if [ $PYTHON_EXIT_CODE -eq 5 ]; then
if [ -f "$AUDIO_TOOLS_INSTALLED_FLAG" ]; then
echo ""
read -p " This script installed audio tools. Uninstall them now? (y/n): " uninstall_confirm
if [[ "$uninstall_confirm" =~ ^[Yy]$ ]]; then
sudo apt remove -y espeak-ng alsa-utils && rm "$AUDIO_TOOLS_INSTALLED_FLAG"
echo " Tools uninstalled."
fi
fi
fi
echo " Done."
exit 0
