<commit_before>__author__ = '<NAME>'


import revar
import general
import json
import urllib2
import ceq
import config
import os
import socket
import time
import connection
import sys
import thread
import urllib
from datetime import datetime

b = ceq.cbold
r = ceq.creset
cyan = ceq.ccyan
violet = ceq.cviolet
orange = ceq.corange


def shorten_url(url):
	try:
		post_url = 'https://www.googleapis.com/urlshortener/v1/url?&key=' + general.google_api
		postdata = {'longUrl':url,
					'key':general.google_api}
		headers = {'Content-Type':'application/json'}
		req = urllib2.Request(
			post_url,
			json.dumps(postdata),
			headers
		)
		ret = urllib2.urlopen(req).read()
		return json.loads(ret)['id']
	except BaseException as exc:
		return general.get_exc(exc, 'commands.shorten_url()')


def get_hash(imdb_id):
	try:
		torrent_hash = ''
		if not revar.get_hash:
			return
		url3 = "https://yts.to/api/v2/list_movies.json?query_term=" + imdb_id
		data3 = json.load(urllib2.urlopen(url3, timeout=8))
		quality1080 = ''
		quality720 = ''
		if data3['data']['movie_count'] == 0:
			return ''
		for torrent in data3['data']['movies'][0]['torrents']:
			if torrent['quality'] == '1080p':
				quality1080 = torrent['hash']
			elif torrent['quality'] == '720p':
				quality720 = torrent['hash']
			else:
				noquality = [torrent['hash'], torrent['quality']]
		if quality1080 != '':
			quality = '1080p'
			xhash = quality1080
		elif quality720 != '':
			quality = '720p'
			xhash = quality720
		else:
			quality = noquality[1]
			xhash = noquality[0]
		return xhash
	except BaseException as exc:
		return general.get_exc(exc, 'commands.get_hash()')


def imdb_info(kind, simdb):
	if kind == 'id':
		url = "http://www.omdbapi.com/?i=" + simdb + "&plot=short&r=json"
	elif kind == 'search':
		params = {
			"q": ' '.join(simdb),
		}
		url2 = "http://www.imdb.com/xml/find?json=1&" + urllib.urlencode(params)
		print url2
		try:
			data2 = json.load(urllib2.urlopen(url2, timeout=8))
			try:
				if len(data2["title_popular"]) < 1:
					return "Title not found11."
				imdbID = data2["title_popular"][0]["id"]
			except:
				try:
					if len(data2["title_exact"]) < 1:
						return "Title not found."
					imdbID = data2["title_exact"][0]["id"]
				except:
					return "Title not found."
			url = "http://www.omdbapi.com/?i=" + imdbID
		except:
			url = "http://www.omdbapi.com/?t=" + '+'.join(simdb)<commit_msg>IMDB search input will now remove any qoutationmarks(i spellt dat rait, just shut da fuq up m8 ;) ) to prevent the api from returning wrong results.<commit_after>__author__ = '<NAME>'


import revar
import general
import json
import urllib2
import ceq
import config
import os
import socket
import time
import connection
import sys
import thread
import urllib
from datetime import datetime

b = ceq.cbold
r = ceq.creset
cyan = ceq.ccyan
violet = ceq.cviolet
orange = ceq.corange


def shorten_url(url):
	try:
		post_url = 'https://www.googleapis.com/urlshortener/v1/url?&key=' + general.google_api
		postdata = {'longUrl':url,
					'key':general.google_api}
		headers = {'Content-Type':'application/json'}
		req = urllib2.Request(
			post_url,
			json.dumps(postdata),
			headers
		)
		ret = urllib2.urlopen(req).read()
		return json.loads(ret)['id']
	except BaseException as exc:
		return general.get_exc(exc, 'commands.shorten_url()')


def get_hash(imdb_id):
	try:
		torrent_hash = ''
		if not revar.get_hash:
			return
		url3 = "https://yts.to/api/v2/list_movies.json?query_term=" + imdb_id
		data3 = json.load(urllib2.urlopen(url3, timeout=8))
		quality1080 = ''
		quality720 = ''
		if data3['data']['movie_count'] == 0:
			return ''
		for torrent in data3['data']['movies'][0]['torrents']:
			if torrent['quality'] == '1080p':
				quality1080 = torrent['hash']
			elif torrent['quality'] == '720p':
				quality720 = torrent['hash']
			else:
				noquality = [torrent['hash'], torrent['quality']]
		if quality1080 != '':
			quality = '1080p'
			xhash = quality1080
		elif quality720 != '':
			quality = '720p'
			xhash = quality720
		else:
			quality = noquality[1]
			xhash = noquality[0]
		return xhash
	except BaseException as exc:
		return general.get_exc(exc, 'commands.get_hash()')


def imdb_info(kind, simdb):
	if kind == 'id':
		url = "http://www.omdbapi.com/?i=" + simdb + "&plot=short&r=json"
	elif kind == 'search':
		params = {
			"q": ' '.join(simdb).replace('\'', '').replace('"', ''),
		}
		url2 = "http://www.imdb.com/xml/find?json=1&" + urllib.urlencode(params)
		print url2
		try:
			data2 = json.load(urllib2.urlopen(url2, timeout=8))
			try:
				if len(data2["title_popular"]) < 1:
					return "Title not found11."
				imdbID = data2["title_popular"][0]["id"]
			except:
				try:
					if len(data2["title_exact"]) < 1:
						return "Title not found."
					imdbID = data2["title_exact"][0]["id"]
				except:
					return "Title not found."
			url = "http://www.omdbapi.com/?i=" + imdbID
		except:
			url = "http://www.omdbapi.com/?t=" + '+'.join(simdb)
{'fraction_non_alphanumeric': 0.16090799517878665, 'fraction_numerical': 0.030333467255926075, 'mean_word_length': 3.7921077959576515, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 10, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7336110', 'n_tokens_mistral': 2185, 'n_tokens_neox': 1844, 'n_words': 406}