Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- import requests
- import json
- import shutil
- import os
- import glob
- import sys
- import multiprocessing as mp
- """
- TRANSLATOR USED: https://translate.yandex.com/?
- DATABASE MOVIES USED: http://omdbapi.com/
- """
- cabecalho = {'User-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'}
- key = "trnsl.1.1.20170125T181407Z.a7a266350d888956.929a9a628283b699b48ec678da47707fc4d18d6a"
- def requisicao(titulo, tipo='movies', ano=None):
- data = {'t' : titulo, 'y' : ano, 'type' : tipo}
- try:
- req = requests.get("http://omdbapi.com/",
- headers=cabecalho,
- params=data)
- dicionario = json.loads(req.text)
- return dicionario
- except Exception as e:
- print(e)
- exit(0)
- def traduzir(texto, dest='pt'):
- data = {'key' : key, 'text': texto, 'lang': dest, 'format' : 'plain'}
- try:
- req = requests.get("https://translate.yandex.net/api/v1.5/tr.json/translate",
- headers=cabecalho,
- params=data)
- traduzido = req.text
- resumo = traduzido[traduzido.find('[')+2:traduzido.find(']')-1:]
- return resumo
- except Exception as e:
- print(e)
- exit(0)
- def detalhes(tv):
- resumo = traduzir(tv['Plot']).replace('\\', '')
- print(' FETCHING DATA '.center(80, '-'))
- print("Título: %s (inglês)/%s (português, tradutoção via yandex translator)\n" % (tv['Title'], traduzir(tv['Title'])))
- if tv['Type'] == 'movies':
- print("Ano: %s\n" % tv['Year'])
- else:
- print("Lançamento em %s\n" % tv['Released'])
- print("Diretor: %s\n" % tv['Director'])
- print("Atores: %s\n" % tv['Actors'])
- print("Nota: %s (Metascore, max 100)\n" % tv['Metascore'])
- print("Nota: %s (imdb, max 10)\n" % tv['imdbRating'])
- print("Plot: %s (inglês)\n\nResumo: %s (português, tradução via yandex translator)\n" % (tv['Plot'], resumo))
- if tv['Type'] == 'movies':
- print("Duração: %s\n" % tv['Runtime'])
- else:
- print("Duração (média) por episódio: %s\n" % tv['Runtime'])
- print("Gênero: %s/%s (português, tradução via yandex translator)\n" % (tv['Genre'], traduzir(tv['Genre'])))
- if tv['Type'] == 'series':
- print("Temporadas: %s\n" % tv['totalSeasons'])
- print(' DATA FETCHED '.center(80, '-'))
- def create_folder():
- if os.path.exists('posters/'):
- pass
- else:
- os.mkdir('posters')
- return 'posters/'
- def baixar_poster(url, title):
- if url != "N/A":
- fname = '%s.png' % title.replace(' ', '').replace(':', '')
- directory = create_folder()
- os.chdir(directory)
- if os.path.exists(fname):
- print(" Image is already downloaded ".center(80, '*'))
- if sys.platform.startswith("win32"):
- os.startfile(os.getcwd()+'\\'+fname)
- else:
- os.system('shotwell %s&' % os.getcwd()+"//"+fname)
- elif not os.path.exists(fname):
- image = requests.get(url, stream=True)
- print(" Downloading image... ".center(80, '*'))
- with open(fname, 'wb') as outfile:
- shutil.copyfileobj(image.raw, outfile)
- if sys.platform.startswith("win32"):
- os.startfile(os.getcwd()+'\\'+fname)
- else:
- os.system('shotwell %s&' % os.getcwd()+'//'+fname)
- print(" Opening image ".center(80, '*'))
- else:
- print(" IMAGE NOT FOUND ".center(80, '*'))
- def kill_visualizar():
- print(' Closing application '.center(80, 'X'))
- os.system('taskkill /IM dllhost.exe>nul 2>&1')
- def delete_posters(ask='N'):
- if ask == 'S':
- kill_visualizar()
- if sys.platform.startswith("win32"):
- os.chdir(os.getcwd()+'\\posters')
- else:
- os.chdir(os.getcwd()+"//posters")
- files = glob.glob('*.png')
- for file in files:
- os.remove(file)
- print(" Posters removed! ".center(80, 'X'))
- else:
- kill_visualizar()
- def main():
- print(" USER INPUT ".center(80, '~'))
- titulo = str(input('Título: '))
- tipo = str(input("Tipo (série/filme): ")).lower()
- if (tipo == 'série') or (tipo == 'serie'):
- tipo = 'series'
- else:
- tipo = 'movies'
- ano = str(input("Ano do filme: "))
- print(" USER INPUT ".center(80, '~'))
- tv = requisicao(titulo, ano)
- print("REQUESTING", end='')
- for i in range(0, 15, 1):
- for i in range(0, 150000, 1):
- i += 5
- sys.stdout.flush()
- sys.stdout.write('.')
- print('')
- if tv['Response'] == 'True':
- th = mp.Process(target=detalhes, args=(tv,))
- th.start()
- th.join()
- th2 = mp.Process(target=baixar_poster, args=(tv['Poster'], tv['Title']))
- th2.start()
- th2.join()
- else:
- print(" [ * ] %s não encontrado" % tv['Title'])
- if __name__ == "__main__":
- print('')
- print(" DATABASE MULTIMEDIA (Created by Reni A. Dantas) ".center(80, ' '))
- while 1:
- main()
- print(" USER INPUT ".center(80, '~'))
- deseja = input("Deseja sair? (S/n) ").title()
- if deseja == 'S':
- deseja_del = input("Deseja deletar todos os posters? (S/n) ").title()
- delete_posters(deseja_del)
- quit(0)
- print(" USER INPUT ".center(80, '~'))
- kill_visualizar()
Advertisement
Add Comment
Please, Sign In to add comment