cover added
Browse files
app.py
CHANGED
|
@@ -15,6 +15,7 @@ import instaloader
|
|
| 15 |
import time
|
| 16 |
import concurrent.futures
|
| 17 |
import re
|
|
|
|
| 18 |
api_key = "268976:66f4f58a2a905"
|
| 19 |
|
| 20 |
|
|
@@ -150,6 +151,12 @@ def yt_download(url):
|
|
| 150 |
ys.download()
|
| 151 |
return video_path, yt.title
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
def insta_oneapi(url, api_key):
|
| 154 |
shortcode = url.split("/")[-2]
|
| 155 |
print(shortcode)
|
|
@@ -170,13 +177,16 @@ def insta_oneapi(url, api_key):
|
|
| 170 |
if chunk:
|
| 171 |
file.write(chunk)
|
| 172 |
print(f"Downloaded successfully")
|
| 173 |
-
|
|
|
|
|
|
|
| 174 |
except requests.exceptions.RequestException as e:
|
| 175 |
print(f"An error occurred: {e}")
|
| 176 |
else:
|
| 177 |
print(f"Error: {response.status_code}, {response.text}")
|
| 178 |
return None
|
| 179 |
-
|
|
|
|
| 180 |
def insta_download(permalink):
|
| 181 |
# Create an instance of Instaloader
|
| 182 |
L = instaloader.Instaloader()
|
|
@@ -362,7 +372,7 @@ def create_subtitle_clips(subtitles, videosize, fontsize, font, color, debug):
|
|
| 362 |
def process_video(url, type):
|
| 363 |
|
| 364 |
if type=="insta":
|
| 365 |
-
input_video=insta_oneapi(url, api_key)
|
| 366 |
input_video_name = input_video.replace(".mp4", "")
|
| 367 |
input_audio = extract_audio(input_video)
|
| 368 |
elif type=="youtube":
|
|
@@ -370,7 +380,6 @@ def process_video(url, type):
|
|
| 370 |
input_video_name = input_video.replace(".mp4", "")
|
| 371 |
# Get the current local time
|
| 372 |
t = time.localtime()
|
| 373 |
-
|
| 374 |
# Format the time as a string
|
| 375 |
current_time = time.strftime("%H:%M:%S", t)
|
| 376 |
print("Current Time =", current_time)
|
|
@@ -385,11 +394,12 @@ def process_video(url, type):
|
|
| 385 |
video = VideoFileClip(input_video)
|
| 386 |
audio = AudioFileClip(input_audio)
|
| 387 |
video = video.with_audio(audio)
|
|
|
|
| 388 |
print(video)
|
| 389 |
subtitles = pysrt.open("google_translate.srt", encoding="utf-8")
|
| 390 |
output_video_file = input_video_name + '_subtitled' + ".mp4"
|
| 391 |
subtitle_clips = create_subtitle_clips(subtitles, video.size, 32, 'arial.ttf', 'white', False)
|
| 392 |
-
final_video = CompositeVideoClip([video] + subtitle_clips)
|
| 393 |
final_video.write_videofile(output_video_file, codec="libx264", audio_codec="aac", logger=None)
|
| 394 |
print('final')
|
| 395 |
# Get the current local time
|
|
|
|
| 15 |
import time
|
| 16 |
import concurrent.futures
|
| 17 |
import re
|
| 18 |
+
from PIL import Image
|
| 19 |
api_key = "268976:66f4f58a2a905"
|
| 20 |
|
| 21 |
|
|
|
|
| 151 |
ys.download()
|
| 152 |
return video_path, yt.title
|
| 153 |
|
| 154 |
+
def download_image(url, save_path='downloaded_image.jpg'):
|
| 155 |
+
response = requests.get(url)
|
| 156 |
+
image = Image.open(BytesIO(response.content))
|
| 157 |
+
image.save(save_path)
|
| 158 |
+
return save_path
|
| 159 |
+
|
| 160 |
def insta_oneapi(url, api_key):
|
| 161 |
shortcode = url.split("/")[-2]
|
| 162 |
print(shortcode)
|
|
|
|
| 177 |
if chunk:
|
| 178 |
file.write(chunk)
|
| 179 |
print(f"Downloaded successfully")
|
| 180 |
+
image_url = result["result"]['media'][0]["cover"]
|
| 181 |
+
image_file_path = download_image(image_url)
|
| 182 |
+
return "video.mp4", image_file_path
|
| 183 |
except requests.exceptions.RequestException as e:
|
| 184 |
print(f"An error occurred: {e}")
|
| 185 |
else:
|
| 186 |
print(f"Error: {response.status_code}, {response.text}")
|
| 187 |
return None
|
| 188 |
+
|
| 189 |
+
|
| 190 |
def insta_download(permalink):
|
| 191 |
# Create an instance of Instaloader
|
| 192 |
L = instaloader.Instaloader()
|
|
|
|
| 372 |
def process_video(url, type):
|
| 373 |
|
| 374 |
if type=="insta":
|
| 375 |
+
input_video, image_path=insta_oneapi(url, api_key)
|
| 376 |
input_video_name = input_video.replace(".mp4", "")
|
| 377 |
input_audio = extract_audio(input_video)
|
| 378 |
elif type=="youtube":
|
|
|
|
| 380 |
input_video_name = input_video.replace(".mp4", "")
|
| 381 |
# Get the current local time
|
| 382 |
t = time.localtime()
|
|
|
|
| 383 |
# Format the time as a string
|
| 384 |
current_time = time.strftime("%H:%M:%S", t)
|
| 385 |
print("Current Time =", current_time)
|
|
|
|
| 394 |
video = VideoFileClip(input_video)
|
| 395 |
audio = AudioFileClip(input_audio)
|
| 396 |
video = video.with_audio(audio)
|
| 397 |
+
image_clip = ImageClip(image_path).set_duration(1)
|
| 398 |
print(video)
|
| 399 |
subtitles = pysrt.open("google_translate.srt", encoding="utf-8")
|
| 400 |
output_video_file = input_video_name + '_subtitled' + ".mp4"
|
| 401 |
subtitle_clips = create_subtitle_clips(subtitles, video.size, 32, 'arial.ttf', 'white', False)
|
| 402 |
+
final_video = CompositeVideoClip([video.set_start(1), image_clip] + subtitle_clips)
|
| 403 |
final_video.write_videofile(output_video_file, codec="libx264", audio_codec="aac", logger=None)
|
| 404 |
print('final')
|
| 405 |
# Get the current local time
|