sh20raj commited on
Commit
ebf8893
·
1 Parent(s): 10dff30

Insta Upload

Browse files
Files changed (1) hide show
  1. reeluploader.py +78 -0
reeluploader.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from instagrapi import Client
3
+ import requests
4
+ from pathlib import Path
5
+ import os
6
+ from moviepy.editor import VideoFileClip
7
+ from PIL import Image
8
+
9
+ # Your Instagram credentials
10
+ username = "droidcv1"
11
+ password = ";ya_#GkM,KND6?$"
12
+
13
+ # Initialize the client
14
+ cl = Client()
15
+
16
+ # Add a delay before login
17
+ import time
18
+ time.sleep(5)
19
+
20
+ # Login to Instagram
21
+ try:
22
+ cl.login(username, password)
23
+ except Exception as e:
24
+ st.error(f'Login failed: {e}')
25
+ st.stop()
26
+
27
+ # Function to download video from Instagram Reel URL
28
+ def download_instagram_reel(url, filename):
29
+ shortcode = url.split('/')[-2]
30
+ media_info = cl.media_info_from_shortcode(shortcode)
31
+ video_url = media_info.video_url
32
+ response = requests.get(video_url, stream=True)
33
+ if response.status_code == 200:
34
+ with open(filename, 'wb') as f:
35
+ for chunk in response.iter_content(1024):
36
+ f.write(chunk)
37
+ return filename
38
+
39
+ # Function to generate thumbnail
40
+ def generate_thumbnail(video_path):
41
+ clip = VideoFileClip(str(video_path))
42
+ frame = clip.get_frame(1) # Get a frame at 1 second
43
+ thumbnail_path = str(video_path) + ".jpg"
44
+ im = Image.fromarray(frame)
45
+ im.save(thumbnail_path)
46
+ return thumbnail_path
47
+
48
+ # Function to upload video and return the reel URL
49
+ def upload_video(video_path, caption):
50
+ thumbnail_path = generate_thumbnail(video_path)
51
+ media = cl.clip_upload(video_path, caption=caption, thumbnail=thumbnail_path)
52
+ return f"https://www.instagram.com/reel/{media.pk}/"
53
+
54
+ # Directory to save downloaded videos
55
+ download_dir = Path("downloads")
56
+ download_dir.mkdir(exist_ok=True)
57
+
58
+ st.title('Instagram Reels Re-uploader')
59
+
60
+ urls = st.text_area('Enter Instagram Reel URLs (one per line):')
61
+
62
+ if st.button('Re-upload Reels'):
63
+ if urls:
64
+ reel_urls = urls.splitlines()
65
+ for idx, reel_url in enumerate(reel_urls, start=1):
66
+ with st.spinner(f'Downloading Reel {idx}...'):
67
+ video_path = download_instagram_reel(reel_url, download_dir / f"reel_{idx}.mp4")
68
+ caption = f"Re-uploaded Reel {idx}"
69
+ with st.spinner(f'Uploading Reel {idx}...'):
70
+ try:
71
+ reel_url = upload_video(video_path, caption)
72
+ st.success(f'Uploaded Reel {idx} URL: {reel_url}')
73
+ except Exception as e:
74
+ st.error(f'Failed to upload Reel {idx}: {e}')
75
+ os.remove(video_path)
76
+ os.remove(video_path.with_suffix('.mp4.jpg'))
77
+ else:
78
+ st.warning('Please enter at least one Instagram Reel URL.')