예제 #1
0
from InstagramAPI import InstagramAPI
import pprint
import os

user = os.environ.get('DB_USER')
password = os.environ.get('INST_KINGALIEN_PASS')
api = InstagramAPI(user, password)
api.USER_AGENT = 'Instagram 10.34.0 Android (18/4.3; 320dpi; 720x1280; Xiamo; HM ISW; armani; qcom; en_US)'


def get_my_profile_details():
    api.login()
    api.getSelfUsernameInfo()
    result = api.LastJson
    formated_print = pprint.pformat(result)
    print(formated_print)


get_my_profile_details()
예제 #2
0
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)