<reponame>diverglovsky/telespoon
import requests,time
from concurrent.futures import ThreadPoolExecutor, as_completed
from fake_useragent import UserAgent
import re,traceback,random,base64
from urllib.request import urlopen
from spoon import botlive,config,basic
import threading

def tele(bot_message):    
    bot_token = '<KEY>'
    #bot_chatID = '-405649200'
    bot_chatID = config.getIdTele()
    print(bot_chatID)
    #time.sleep(50)
    send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=html&text=' + bot_message

    response = requests.get(send_text)
    print('pesan terkirim')
    
def telerror(bot_message):    
    bot_token = '1495404340:<KEY>'
    #bot_chatID = '-471014112'
    bot_chatID = config.getIdTelerror()
    print(bot_chatID)
    #time.sleep(50)
    send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=html&text=' + bot_message

    response = requests.get(send_text)
    print('pesan terkirim')


#method WEBSOCKET ########
#up bot listener stay
def upBotStay(slink,token,password,jumlahbot):
	if True:
		random.shuffle(token)
		penghitung = 0
		if True:
			for nomer in token:
				if penghitung != jumlahbot:
				
					#ua = UserAgent()
					#uafix = ua.random
			
					token = basic.login(nomer,password)
					tokens = token[0]
					uafix = token[1]
					
					try:
						jwt = tokens.json()['data']['jwt']
						headers2 = {"Authorization":"Bearer "+jwt,"User-Agent":uafix,'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','accept':'application/json','host':'id-api.spooncast.net','save-data':'on','sec-fetch-site':'same-site','sec-fetch-mode':'cors','sec-fetch-dest':'empty','accept-encoding':'gzip, deflate, br','accept-language':'en-US,en;q=0.9,ru;q=0.8','access-control-request-method':'GET','access-control-request-headers':'authorization'}
						
						nomer = nomer.replace('628','8')
						print('nomer digunakan untuk api signin '+nomer)
						login = requests.post('https://id-api.spooncast.net/signin/',headers=headers2,json={"sns_type":"phone","sns_id":nomer,"password":password,"country":"id"})
						
						print(login.text[:100])
						
						idnyabot = str(login.json()['results'][0]['id'])
						usertoken = 'Bearer '+jwt
						botlive.konek(slink,headers2,usertoken,idnyabot,uafix)
						#(threading.Thread(target=botlive.konek, args=(slink,headers2,usertoken,idnyabot,uafix)).start()
						time.sleep(config.getJedaMasuk())
						penghitung+=1
						print(penghitung)				
						
					except Exception as e:
						print('err')
						print(e)
						print(traceback.format_exc())
		
		
#method pool agar cepat#################

#method cepat uplistenercast
def upCastListenerCepat(slink):
	processes=[]
	with ThreadPoolExecutor(max_workers=10) as executor:
		for i in range(0,random.randint(100,200)):
			processes.append(executor.submit(basic.upCastListener, slink))
			
#method cepat follow
def upFollowCepat(slink,token):
	processes=[]
	with ThreadPoolExecutor(max_workers=10) as executor:
		for toket in token:
			processes.append(executor.submit(basic.upFollow, slink, toket))

#method cepat upcast
def upCastCepat(slink,token):
	processes=[]
	with ThreadPoolExecutor(max_workers=10) as executor:
		for toket in token:
			processes.append(executor.submit(basic.upCast, slink, toket))
			


#getter#########

#mendapatkan slink
#0 id
#1 url
def getSlink(txtid):
	
	headers4={"User-Agent":uafix,'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','content-type':'application/json'}
	response = requests.get(txtid)
	print(txtid)
	#print(response.text)
	url = response.url
	print(url)
	slink = re.search('\d{7}',url)
	slink = slink.group(0)
	print('Berhasil mendapatkan id '+slink)
	return slink,url

def getLive(slink):
	ua = UserAgent()
	uafix=ua.random
	headers4={"User-Agent":uafix,'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','content-type':'application/json'}
	response4=requests.get('https://id-api.spooncast.net/lives/'+slink+'',	headers=headers4,).json()
	print(response4)

#mendapatkan iduser
# 0 id
# 1 nama
def getUserById(id):
	headers4={"User-Agent":"Mozilla/5.0",'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','content-type':'application/json'}
	response4=requests.get('https://id-api.spooncast.net/search/user/?keyword='+id+'',	headers=headers4,)
	tele(getUserById.__name__+'\n'+response4.text)
	idd = str(response4.json()['results'][0]['id'])
	nama = response4.json()['results'][0]['nickname']
	print('Didapatkan nama '+nama+' dengan id '+idd)
	return idd,nama
	
	
def getUserDetailById(id):
	headers4={"User-Agent":"Mozilla/5.0",'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','content-type':'application/json'}
	response4=requests.get('https://id-api.spooncast.net/users/'+str(id)+'/',	headers=headers4,)
	tele(getUserDetailById.__name__+'\n'+response4.text)
	idd = str(response4.json()['results'][0]['id'])
	nama = response4.json()['results'][0]['nickname']
	print('Didapatkan nama '+nama+' dengan id '+idd)
	return idd,nama

#mendapatkan link mp3 cast
# 0 link
def getCastMp3link(slink):
	ua = UserAgent()
	uafix=ua.random
	headers={"User-Agent":uafix,'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','content-type':'application/json'}
	response = requests.get('https://id-api.spooncast.net/casts/'+slink+'/',headers=headers,)
	linkmp3 = response.json()['results'][0]['voice_url']
	return linkmp3
	
#mendapatkan mp3
#0 mp3
def getCastMp3(slink):
	ua = UserAgent()
	uafix=ua.random
	headers={"User-Agent":uafix,'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','content-type':'application/json'}
	u = urlopen(slink)
	b64 = base64.b64encode(u.read())
	decode_b64 = base64.b64decode(b64)
	slink = slink.strip('/')
	name = slink.split('/')[-1]
	fname = 'cast/'+name
	out_file = open(fname, 'wb')
	out_file.write(decode_b64)
	return fname

def getCariUser(id):
	#User = getUserById(id)
	#uid = int(User[0])
	#getUserDetailById(uid)
	#print(uid)
	
	uid = '210984860'
	
	
	headers4={"User-Agent":"Mozilla/5.0",'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','content-type':'application/json'}
	
	listlive = requests.get('https://id-api.spooncast.net/lives/popular/?is_adult=0&with_sing=true').json()
	
	uidlive = str(listlive['results'][0]['id'])
	
	getLive(uidlive)
	listenerlive = requests.get('https://id-api.spooncast.net/lives/'+uidlive+'/listeners').json()
	i=1
	for a in listenerlive['results']:
			print(i)
			print(a)
			print('\n\n')
			i+=1
	next=listenerlive['next']
	print('ini next : '+next)
	while next !='':
		listenerlive=requests.get(next).json()
		next = listenerlive['next']
		print(next)
		print(len(listenerlive))
		
		for a in listenerlive['results']:
			print(i)
			print(a)
			print('\n\n')
			i+=1
	
	
	
import requests,time
from concurrent.futures import ThreadPoolExecutor, as_completed
from fake_useragent import UserAgent
import re,traceback,random,base64
from urllib.request import urlopen
from spoon import botlive,config,basic
import threading

def tele(bot_message):    
    bot_token = '<KEY>'
    #bot_chatID = '-405649200'
    bot_chatID = config.getIdTele()
    print(bot_chatID)
    #time.sleep(50)
    send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=html&text=' + bot_message

    response = requests.get(send_text)
    print('pesan terkirim')
    
def telerror(bot_message):    
    bot_token = '1495404340:<KEY>'
    #bot_chatID = '-471014112'
    bot_chatID = config.getIdTelerror()
    print(bot_chatID)
    #time.sleep(50)
    send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=html&text=' + bot_message

    response = requests.get(send_text)
    print('pesan terkirim')


#method WEBSOCKET ########
#up bot listener stay
def upBotStay(slink,token,password,jumlahbot):
	if True:
		random.shuffle(token)
		penghitung = 0
		if True:
			for nomer in token:
				if penghitung != jumlahbot:
				
					#ua = UserAgent()
					#uafix = ua.random
			
					token = basic.login(nomer,password)
					tokens = token[0]
					uafix = token[1]
					
					try:
						jwt = tokens.json()['data']['jwt']
						headers2 = {"Authorization":"Bearer "+jwt,"User-Agent":uafix,'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','accept':'application/json','host':'id-api.spooncast.net','save-data':'on','sec-fetch-site':'same-site','sec-fetch-mode':'cors','sec-fetch-dest':'empty','accept-encoding':'gzip, deflate, br','accept-language':'en-US,en;q=0.9,ru;q=0.8','access-control-request-method':'GET','access-control-request-headers':'authorization'}
						
						nomer = nomer.replace('628','8')
						print('nomer digunakan untuk api signin '+nomer)
						login = requests.post('https://id-api.spooncast.net/signin/',headers=headers2,json={"sns_type":"phone","sns_id":nomer,"password":password,"country":"id"})
						
						print(login.text[:100])
						
						idnyabot = str(login.json()['results'][0]['id'])
						usertoken = 'Bearer '+jwt
						botlive.konek(slink,headers2,usertoken,idnyabot,uafix)
						#(threading.Thread(target=botlive.konek, args=(slink,headers2,usertoken,idnyabot,uafix)).start()
						time.sleep(config.getJedaMasuk())
						penghitung+=1
						print(penghitung)				
						
					except Exception as e:
						print('err')
						print(e)
						print(traceback.format_exc())
		
		
#method pool agar cepat#################

#method cepat uplistenercast
def upCastListenerCepat(slink):
	processes=[]
	with ThreadPoolExecutor(max_workers=10) as executor:
		for i in range(0,random.randint(100,200)):
			processes.append(executor.submit(basic.upCastListener, slink))
			
#method cepat follow
def upFollowCepat(slink,token):
	processes=[]
	with ThreadPoolExecutor(max_workers=10) as executor:
		for toket in token:
			processes.append(executor.submit(basic.upFollow, slink, toket))

#method cepat upcast
def upCastCepat(slink,token):
	processes=[]
	with ThreadPoolExecutor(max_workers=10) as executor:
		for toket in token:
			processes.append(executor.submit(basic.upCast, slink, toket))
			


#getter#########

#mendapatkan slink
#0 id
#1 url
def getSlink(txtid):
	
	headers4={"User-Agent":uafix,'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','content-type':'application/json'}
	response = requests.get(txtid)
	print(txtid)
	#print(response.text)
	url = response.url
	print(url)
	slink = re.search('\d{7}',url)
	slink = slink.group(0)
	print('Berhasil mendapatkan id '+slink)
	return slink,url

def getLive(slink):
	ua = UserAgent()
	uafix=ua.random
	headers4={"User-Agent":uafix,'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','content-type':'application/json'}
	response4=requests.get('https://id-api.spooncast.net/lives/'+slink+'',	headers=headers4,).json()
	print(response4)

#mendapatkan iduser
# 0 id
# 1 nama
def getUserById(id):
	headers4={"User-Agent":"Mozilla/5.0",'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','content-type':'application/json'}
	response4=requests.get('https://id-api.spooncast.net/search/user/?keyword='+id+'',	headers=headers4,)
	tele(getUserById.__name__+'\n'+response4.text)
	idd = str(response4.json()['results'][0]['id'])
	nama = response4.json()['results'][0]['nickname']
	print('Didapatkan nama '+nama+' dengan id '+idd)
	return idd,nama
	
	
def getUserDetailById(id):
	headers4={"User-Agent":"Mozilla/5.0",'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','content-type':'application/json'}
	response4=requests.get('https://id-api.spooncast.net/users/'+str(id)+'/',	headers=headers4,)
	tele(getUserDetailById.__name__+'\n'+response4.text)
	idd = str(response4.json()['results'][0]['id'])
	nama = response4.json()['results'][0]['nickname']
	print('Didapatkan nama '+nama+' dengan id '+idd)
	return idd,nama

#mendapatkan link mp3 cast
# 0 link
def getCastMp3link(slink):
	ua = UserAgent()
	uafix=ua.random
	headers={"User-Agent":uafix,'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','content-type':'application/json'}
	response = requests.get('https://id-api.spooncast.net/casts/'+slink+'/',headers=headers,)
	linkmp3 = response.json()['results'][0]['voice_url']
	return linkmp3
	
#mendapatkan mp3
#0 mp3
def getCastMp3(slink):
	ua = UserAgent()
	uafix=ua.random
	headers={"User-Agent":uafix,'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','content-type':'application/json'}
	u = urlopen(slink)
	b64 = base64.b64encode(u.read())
	decode_b64 = base64.b64decode(b64)
	slink = slink.strip('/')
	name = slink.split('/')[-1]
	fname = 'cast/'+name
	out_file = open(fname, 'wb')
	out_file.write(decode_b64)
	return fname

def getCariUser(id):
	#User = getUserById(id)
	#uid = int(User[0])
	#getUserDetailById(uid)
	#print(uid)
	
	uid = '210984860'
	
	
	headers4={"User-Agent":"Mozilla/5.0",'origin':'https://www.spooncast.net','referer':'https://www.spooncast.net/','content-type':'application/json'}
	
	listlive = requests.get('https://id-api.spooncast.net/lives/popular/?is_adult=0&with_sing=true').json()
	
	uidlive = str(listlive['results'][0]['id'])
	
	getLive(uidlive)
	listenerlive = requests.get('https://id-api.spooncast.net/lives/'+uidlive+'/listeners').json()
	i=1
	for a in listenerlive['results']:
			print(i)
			print(a)
			print('\n\n')
			i+=1
	next=listenerlive['next']
	print('ini next : '+next)
	while next !='':
		listenerlive=requests.get(next).json()
		next = listenerlive['next']
		print(next)
		print(len(listenerlive))
		
		for a in listenerlive['results']:
			print(i)
			print(a)
			print('\n\n')
			i+=1
#bot_chatID = '-405649200' #time.sleep(50) #bot_chatID = '-471014112' #time.sleep(50) #method WEBSOCKET ######## #up bot listener stay #ua = UserAgent() #uafix = ua.random #(threading.Thread(target=botlive.konek, args=(slink,headers2,usertoken,idnyabot,uafix)).start() #method pool agar cepat################# #method cepat uplistenercast #method cepat follow #method cepat upcast #getter######### #mendapatkan slink #0 id #1 url #print(response.text) #mendapatkan iduser # 0 id # 1 nama #mendapatkan link mp3 cast # 0 link #mendapatkan mp3 #0 mp3 #User = getUserById(id) #uid = int(User[0]) #getUserDetailById(uid) #print(uid)