first commit

This commit is contained in:
Pulguer Gonzalo 2022-02-16 09:49:12 -03:00
commit 8b85584d7c
4 changed files with 177 additions and 0 deletions

26
display.py Normal file
View File

@ -0,0 +1,26 @@
from bs4 import BeautifulSoup
import requests
import webbrowser
#get ep url
def get_vid(url):
webp = requests.get(url)
soup = BeautifulSoup(webp.text, 'html.parser')
res = soup.find_all('html')
raw = str(res)
vid = raw.split('var video')
r = vid[1]
src = r.split('src=')
src = str(src).replace('"', '')
sour = str(src).split(' width')
end = str(sour).split(',')
links = []
for x in end:
if '.net' in x:
links.append(x[2:-1])
return links
#opens link in a firefox tab (couldnt make mpv work yet :c)
def display(url):
webbrowser.open_new(url)

95
main.py Normal file
View File

@ -0,0 +1,95 @@
import search
import makeLink
import display
#user input
anime = input('Search anime: ')
#search function
results = search.search(anime)
#display results
num = 0
print('Results:')
for result in results:
num += 1
print(str(num) + ' - ' + result)
#selecting anime
while True:
pick = input('Select anime entering its number: ')
if pick.isnumeric():
if int(pick) <= num and int(pick) > 0:
url = makeLink.ani_link(results[int(pick)-1])
break
else:
print('Invalid number `-´')
else:
print("That's not a number `-´")
#episodes
while True:
eps = search.episodes(url)
ep_sel = input(results[int(pick)-1] + ' has ' + eps + ' episodes. Select the episode u want to watch: ')
if ep_sel.isnumeric():
if int(ep_sel) <= int(eps) and int(ep_sel) > 0:
epi = int(ep_sel)
link = makeLink.ep_link(url, ep_sel)
break
else:
print('Invalid number `-´')
else:
print("That's not a number `-´")
#display
def showtime(link):
vido = display.get_vid(link)
display.display(vido[-1])
return vido
#stores the different hosts in case the default one doesn't work
servers = showtime(link)
#options
while True:
res = input("""\np to watch previous episode
d to pick a different host
n to watch next episode
q to quit: """)
#quits
if res.lower() == 'q':
print('cya')
break
#previous episode
elif res.lower() == 'p':
if epi == 1:
print('Error! This is the first episode')
elif res.lower() == 'n':
epi += 1
if epi > int(eps):
print('Error! This is the last episode')
else:
link = makeLink.ep_link(url, epi)
showtime(link)
#diff host
elif res.lower() == 'd':
j = 0
for x in servers:
j += 1
print('Server ' + str(j))
host = input('Pick the host: ')
if host.isnumeric():
if int(host) > 0 and int(host) < j:
ref = servers[int(host)]
display.display(ref)
continue
else:
print('Invalid number')
else:
print('not a number sadly')
else:
print("That wasn't an option dude")

15
makeLink.py Normal file
View File

@ -0,0 +1,15 @@
filler = ['!', '¡', '?', '¿', '.', "'", ':', '=']
def ani_link(anime):
base_link = 'https://jkanime.net/'
anime = anime.replace('½', '-')
for x in filler:
anime = anime.replace(x, '')
anime = anime.replace(' ', '-')
anime = anime.lower()
final_link = base_link + anime + '/'
return final_link
def ep_link(link, ep):
link = link + str(ep) + '/'
return link

41
search.py Normal file
View File

@ -0,0 +1,41 @@
from bs4 import BeautifulSoup
import requests
def search(anime):
#etc
search_base = 'https://jkanime.net/buscar/'
filler = ['<div class="title">', '</div>', '[', ']']
final_list = []
#search
search_link = search_base + anime + '/'
#scrap
webp = requests.get(search_link)
soup = BeautifulSoup(webp.text, 'html.parser')
results = soup.find_all('div', class_ = 'title')
results = str(results)
for words in filler:
results = results.replace(words, '')
results_list = results.split(',')
#fixing names
for x in results_list:
if x[0] == ' ':
x = x.replace(' ', '', 1)
final_list.append(x)
return final_list
def episodes(link):
#scrap
webs = requests.get(link)
sopa = BeautifulSoup(webs.text, 'html.parser')
nums = sopa.find_all('div', class_ = 'anime__details__content')
#find eps
text = str(nums)
eps = text.find('Episodios:</span>')
eps2 = str(text[eps:])
split = eps2.split('</li>', 1)
half = split[0]
half = half.replace('Episodios:</span> ', '')
return half