Example #1
0
	def __init__(self,username=None,password=None):
		self.username = username
		self.password = password
		self.ryts = RawYTS()
		if self.username != None:
			self.login(username,password)
Example #2
0
class YTS:
	def __init__(self,username=None,password=None):
		self.username = username
		self.password = password
		self.ryts = RawYTS()
		if self.username != None:
			self.login(username,password)


	def login(self,username,password):
		url = 'https://yts.re/api/login.json'
		res = requests.get(url,params={'username':username,'password':password})
		dic = res.json()
		self.hash = dic['hash']
		self.uid = dic['userID']


	#Prints torrents on to the screen.Only should be used by other functions of class
	def print_torrents(self,dic):
		for i in dic:
			print '==============================================================\n'
			print '\t',i[u'title'],'{movie ID: ',i[u'id'],'}'
			print '\t','Rating: ',i[u'rating']
			print '\t','Language: ',i[u'language']
			print '\t','Year: ',i[u'year']
			print '\t','Size: ',i['torrents'][0][u'size']
			print '\t','Size: ',i['torrents'][0][u'quality']
			print '\t','Size: ',i['torrents'][0][u'seeds']
			print '\t','Uploaded Date: ',i[u'date_uploaded']
			print '==============================================================\n'

	#Fetches torrents as per keyword arguments specified
	def torrents(self,limit=20,page=1,quality='ALL',rating=0,genre='ALL',sort='date', with_rt_ratings=False):
		url = 'https://yts.to/api/v2/list_movies.json'
		payload = {'limit':limit,'set':page,'quality':quality,'rating':rating,'genre':genre,'sort':sort, 'with_rt_ratings':with_rt_ratings}
		res = requests.get(url,params=payload)
		dic = res.json()['data']['movies'] 
		#import ipdb;ipdb.set_trace()
		self.print_torrents(dic)
		
	
	def comment(self,id,text):
		if self.username:
			url = 'https://yts.re/api/commentpost.json'
			params = {'hash':self.hash,'movieid':id,'text':text}
			res = requests.post(url,data=params)
			print 'Posted comment successfully'
		else:
			print 'Please login to post comment!'

	def request(self,movie):
		if self.username:
			url = 'https://yts.re/api/makerequest.json'
			params = {'hash':self.hash,'request':movie}
			res = requests.post(url,data=params)
			print 'Requested movie successfully'
		else:
			print 'Please login to request a movie!'


	#Fetches top 20 latest movie torrents from web
	def latest(self):
		url = 'https://yts.re/api/list.json'
		res = requests.get(url)
		dic = res.json()
		self.print_torrents(dic)

	def upcoming(self):
		url = 'https://yts.re/api/upcoming.json'
		res = requests.get(url)
		dic = res.json()
		for i in dic:
			print '%s  by \t%s\n'%(i['MovieTitle'],i['Uploader'])

	def download(self,id):
		url = 'https://yts.re/api/movie.json'
		res = requests.get(url,params={'id':id})
		dic = res.json()
		webbrowser.open(dic['TorrentMagnetUrl'])

	def search(self,movie):
		url = 'https://yts.re/api/list.json'
		res = requests.get(url,params={'keywords':movie})
		dic = res.json()
		self.print_torrents(dic)

	def requests_confirmed(self):
		url = 'https://yts.re/api/requests.json'
		res = requests.get(url,params={'page':'confirmed'})
		dic = res.json()
		for i in dic['RequestList']:
			print i['Username'],':\t',i['MovieTitle'].encode('utf-8')

	def raw_upcoming(self):
		return self.ryts.raw_upcoming()

	def raw_torrents(self,limit=20,page=1,quality='ALL',rating=0,genre='ALL',sort='date'):
		return self.ryts.raw_torrents(limit=limit,page=page,quality=quality,rating=rating,genre=genre,sort=sort)

	def raw_latest(self):
		return self.ryts.raw_latest()

	def raw_search(self,movie):
		return self.ryts.raw_search(movie)

	def raw_requests_confirmed(self):
		return self.ryts.raw_requests_confirmed()