Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Nov 29, 2024
1 parent bd6fc44 commit 7cc6c09
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions objects/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import subprocess
import urllib.request
from datetime import datetime, timedelta
import http.client
http.client.HTTPConnection.debuglevel = 1


# Function to ensure pytube is installed
def ensure_pytube_installed():
Expand Down Expand Up @@ -65,11 +68,20 @@ def patched_get_throttling_function_name(js: str) -> str:

# Add a User-Agent header to urllib requests
def add_user_agent():
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)"
headers = [
("User-Agent", user_agent),
("Accept-Language", "en-US,en;q=0.9"),
("Accept-Encoding", "gzip, deflate, br"),
("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),
("Connection", "keep-alive"),
("Upgrade-Insecure-Requests", "1"),
]
opener = urllib.request.build_opener()
opener.addheaders = [("User-Agent", user_agent)]
opener.addheaders = headers
urllib.request.install_opener(opener)


# Ensure User-Agent is applied
add_user_agent()

Expand All @@ -79,9 +91,6 @@ def log_system_details():
print(f"Pytube version: {pytube.__version__}")
print(f"SSL version: {ssl.OPENSSL_VERSION}")
print(f"System platform: {sys.platform}")
print("Environment variables:")
for key, value in os.environ.items():
print(f"{key}: {value}")

def save_progress(stream, bytes_remaining, folder):
try:
Expand Down

0 comments on commit 7cc6c09

Please sign in to comment.