def Instagramm(username, password): ig = InstagramAPI(username, password) ig.login() islemler = int( input(""" 1-Kullanıcı yayın akışı görüntüle 2-Canlı Yayın Başlat """)) if (islemler == 1): ig.getTimeline() elif (islemler == 2): import subprocess FILE_PATH = '/path/to/video/file' PUBLISH_TO_LIVE_FEED = False SEND_NOTIFICATIONS = False api = InstagramAPI(username, password, debug=False) assert api.login() # first you have to create a broadcast - you will receive a broadcast id and an upload url here assert api.createBroadcast() broadcast_id = api.LastJson['broadcast_id'] upload_url = api.LastJson['upload_url'] # we now start a boradcast - it will now appear in the live-feed of users assert api.startBroadcast(broadcast_id, sendNotification=SEND_NOTIFICATIONS) ffmpeg_cmd = "ffmpeg -rtbufsize 256M -re -i '{file}' -acodec libmp3lame -ar 44100 -b:a 128k -pix_fmt yuv420p -profile:v baseline -s 720x1280 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -vcodec libx264 -preset veryfast -g 30 -r 30 -f flv '{stream_url}'".format( file=FILE_PATH, stream_url=upload_url.replace( ':4343', ':80', ).replace('rtmps://', 'rtmp://'), ) print(" Ctrl+C yaparak yayını sonlandırabilirsiniz") try: subprocess.call(ffmpeg_cmd, shell=True) except KeyboardInterrupt: print('Stop Broadcasting') assert api.stopBroadcast(broadcast_id) print('Yayın sona erdi') if PUBLISH_TO_LIVE_FEED: api.addBroadcastToLive(broadcast_id) print('Added Broadcast to LiveFeed')
# Use text editor to edit the script and type in valid Instagram username/password import subprocess from InstagramAPI import InstagramAPI USERNAME = '******' PASSWORD = '******' FILE_PATH = './video.mp4' PUBLISH_TO_LIVE_FEED = False SEND_NOTIFICATIONS = False api = InstagramAPI(USERNAME, PASSWORD, debug=False) assert api.login() # first you have to create a broadcast - you will receive a broadcast id and an upload url here assert api.createBroadcast() broadcast_id = api.LastJson['broadcast_id'] upload_url = api.LastJson['upload_url'] # we now start a boradcast - it will now appear in the live-feed of users assert api.startBroadcast(broadcast_id, sendNotification=SEND_NOTIFICATIONS) ffmpeg_cmd = "ffmpeg -rtbufsize 256M -re -i '{file}' -acodec libmp3lame -ar 44100 -b:a 128k -pix_fmt yuv420p -profile:v baseline -s 720x1280 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -vcodec libx264 -preset veryfast -g 30 -r 30 -f flv '{stream_url}'".format( file=FILE_PATH, stream_url=upload_url.replace( ':443', ':80', ).replace('rtmps://', 'rtmp://'), ) print("Hit Ctrl+C to stop broadcast") try:
import subprocess from InstagramAPI import InstagramAPI USERNAME = '' PASSWORD = '' FILE_PATH = '/path/to/video/file' PUBLISH_TO_LIVE_FEED = False SEND_NOTIFICATIONS = False api = InstagramAPI(USERNAME, PASSWORD, debug=False) assert api.login() # first you have to create a broadcast - you will receive a broadcast id and an upload url here assert api.createBroadcast() broadcast_id = api.LastJson['broadcast_id'] upload_url = api.LastJson['upload_url'] # we now start a boradcast - it will now appear in the live-feed of users assert api.startBroadcast(broadcast_id, sendNotification=SEND_NOTIFICATIONS) ffmpeg_cmd = "ffmpeg -rtbufsize 256M -re -i '{file}' -acodec libmp3lame -ar 44100 -b:a 128k -pix_fmt yuv420p -profile:v baseline -s 720x1280 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -vcodec libx264 -preset veryfast -g 30 -r 30 -f flv '{stream_url}'".format( file=FILE_PATH, stream_url=upload_url.replace(':443', ':80', ).replace('rtmps://', 'rtmp://'), ) print("Hit Ctrl+C to stop broadcast") try: subprocess.call(ffmpeg_cmd, shell=True) except KeyboardInterrupt:
def main(): # To start with we will load the admin user name and passwords [ADMIN_USERNAME,ADMIN_ID] = getAdminCredentials('./admin.txt') [BROADCAST_USERNAME,BROADCAST_PASSWORD] = getBroadcasterCredentials('./login.txt') # Now we will define the API for InstagramAPI api = InstagramAPI(BROADCAST_USERNAME, BROADCAST_PASSWORD, debug=False) api.login() api.USER_AGENT = 'Instagram 39.0.0.19.93 Android' api.direct_message('Darkland Broadcasting System Online...',ADMIN_ID) api2 = InstagramAPI(BROADCAST_USERNAME, BROADCAST_PASSWORD, debug=False) api2.login() # # With this there are now two process loops. The first is to run the broadcaster # # and the second is to look for any DM commands coming in from the admin account # # We will run these two methods on diffrent threads # Thread(target = pollAdminCommands,args=[BROADCAST_USERNAME,BROADCAST_PASSWORD,ADMIN_ID]).start() # # Initial command will always play the simpsons by default # Thread(target = runBroadcast,args=[]).start() last_admin_command_thread_ID = [] # The first DM from the admin is not usable broadcast_id = [] MEDIA_FOLDER = './Media/RickAndMorty/S01E01.mkv' # api2.createBroadcast() # print (api2.LastJson) # broadcast_id = api2.LastJson['broadcast_id'] # upload_url = api2.LastJson['upload_url'] # api2.startBroadcast(broadcast_id, sendNotification=False) # ffmpeg_cmd = "ffmpeg -rtbufsize 256M -re -i '{file}' -vf 'transpose=1' -acodec libmp3lame -ar 44100 -b:a 256k -pix_fmt yuv420p -profile:v baseline -s 720x1280 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -vcodec libx264 -preset veryfast -g 30 -r 30 -f flv '{stream_url}'".format( # file=MEDIA_FOLDER, # stream_url=upload_url.replace(':443', ':80', ).replace('rtmps://', 'rtmp://'), # ) # pro = subprocess.Popen(ffmpeg_cmd, stdout=subprocess.PIPE,shell=True, preexec_fn=os.setsid) while True: # Wait 5 seconds between checking for admin messages time.sleep(5) api.getv2Inbox() item_ID = api.LastJson['inbox']['threads'][0]['items'][0]['item_id'] latest_message = api.LastJson['inbox']['threads'][0]['items'][0]['text'] latest_DM_username_pk = api.LastJson['inbox']['threads'][0]['users'] latest_DM_username_pk = api.LastJson['inbox']['threads'][0]['users'][0]['pk'] latest_DM_username_un = api.LastJson['inbox']['threads'][0]['users'][0]['username'] if latest_DM_username_un in ['kapastor']: if not last_admin_command_thread_ID: # If the last message ID is empty last_admin_command_thread_ID = item_ID elif item_ID not in last_admin_command_thread_ID: last_admin_command_thread_ID = item_ID # If there is a new message from kapastor print ('NEW COMMAND FOUND...' + latest_message) latest_message = latest_message.split(' ') if latest_message[0] in ['!start']: MEDIA_FOLDER = latest_message[1] api2.createBroadcast() print (api2.LastJson) broadcast_id = api2.LastJson['broadcast_id'] upload_url = api2.LastJson['upload_url'] api2.startBroadcast(broadcast_id, sendNotification=False) ffmpeg_cmd = "ffmpeg -rtbufsize 256M -re -i '{file}' -vf 'transpose=1' -acodec libmp3lame -ar 44100 -b:a 256k -pix_fmt yuv420p -profile:v baseline -s 720x1280 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -vcodec libx264 -preset veryfast -g 30 -r 30 -f flv '{stream_url}'".format( file=MEDIA_FOLDER, stream_url=upload_url.replace(':443', ':80', ).replace('rtmps://', 'rtmp://'), ) pro = subprocess.Popen(ffmpeg_cmd, stdout=subprocess.PIPE,shell=True, preexec_fn=os.setsid) elif latest_message in ['!stop']: if broadcast_id: os.killpg(os.getpgid(pro.pid), signal.SIGTERM) api2.stopBroadcast(broadcast_id)