Update mirror.py
Browse files
mirror.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import sys
|
| 2 |
import os
|
| 3 |
-
import
|
| 4 |
import pickle
|
| 5 |
from googleapiclient.discovery import build
|
| 6 |
from googleapiclient.http import MediaFileUpload
|
|
@@ -9,6 +9,9 @@ from google.auth.transport.requests import Request
|
|
| 9 |
TOKEN_FILE = '/app/token.pickle'
|
| 10 |
VIDEO_PATH = '/app/mirror_video.mp4'
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
def get_credentials():
|
| 13 |
creds = None
|
| 14 |
if os.path.exists(TOKEN_FILE):
|
|
@@ -21,28 +24,30 @@ def get_credentials():
|
|
| 21 |
return creds
|
| 22 |
|
| 23 |
def download_from_youtube(video_id, output_path):
|
|
|
|
|
|
|
|
|
|
| 24 |
url = f"https://www.youtube.com/watch?v={video_id}"
|
| 25 |
print(f"Downloading: {url}")
|
| 26 |
|
| 27 |
if os.path.exists(output_path):
|
| 28 |
os.remove(output_path)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
if result.returncode != 0:
|
| 44 |
-
raise Exception(f"yt-dlp failed: {result.stderr}")
|
| 45 |
|
|
|
|
|
|
|
| 46 |
print("Download complete!")
|
| 47 |
|
| 48 |
def upload_to_channel_b(title, description):
|
|
|
|
| 1 |
import sys
|
| 2 |
import os
|
| 3 |
+
import ssl
|
| 4 |
import pickle
|
| 5 |
from googleapiclient.discovery import build
|
| 6 |
from googleapiclient.http import MediaFileUpload
|
|
|
|
| 9 |
TOKEN_FILE = '/app/token.pickle'
|
| 10 |
VIDEO_PATH = '/app/mirror_video.mp4'
|
| 11 |
|
| 12 |
+
# Fix SSL issues globally
|
| 13 |
+
ssl._create_default_https_context = ssl._create_unverified_context
|
| 14 |
+
|
| 15 |
def get_credentials():
|
| 16 |
creds = None
|
| 17 |
if os.path.exists(TOKEN_FILE):
|
|
|
|
| 24 |
return creds
|
| 25 |
|
| 26 |
def download_from_youtube(video_id, output_path):
|
| 27 |
+
from pytubefix import YouTube
|
| 28 |
+
from pytubefix.cli import on_progress
|
| 29 |
+
|
| 30 |
url = f"https://www.youtube.com/watch?v={video_id}"
|
| 31 |
print(f"Downloading: {url}")
|
| 32 |
|
| 33 |
if os.path.exists(output_path):
|
| 34 |
os.remove(output_path)
|
| 35 |
|
| 36 |
+
yt = YouTube(url, on_progress_callback=on_progress, use_oauth=False, allow_oauth_cache=False)
|
| 37 |
+
print(f"Title: {yt.title}")
|
| 38 |
+
|
| 39 |
+
# Get highest resolution progressive stream (audio+video together)
|
| 40 |
+
stream = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').last()
|
| 41 |
+
|
| 42 |
+
if not stream:
|
| 43 |
+
# Fallback to any mp4
|
| 44 |
+
stream = yt.streams.filter(file_extension='mp4').first()
|
| 45 |
+
|
| 46 |
+
if not stream:
|
| 47 |
+
raise Exception("No suitable stream found!")
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
print(f"Downloading stream: {stream.resolution} {stream.mime_type}")
|
| 50 |
+
stream.download(filename=output_path)
|
| 51 |
print("Download complete!")
|
| 52 |
|
| 53 |
def upload_to_channel_b(title, description):
|