Beispiel #1
0
    def get(self, request, *args, **kwargs):
        form = self.form_class()
        torrent_form = TorrentForm()
        if 'search_string' in request.GET:
            form = self.form_class(request.GET)
            torrent_form = TorrentForm()
            results = None

            # get cleaned form data
            search_string = request.GET.get('search_string', "")
            category_string = request.GET.get('category', "")

            # construct search arguments
            # hardcoded to get first page, sort by number of seeders in descending order
            t = TPB(settings.TPB_URL)
            category = match_category(category_string)
            search = t.search(search_string,
                              category=category).order(ORDERS.SEEDERS.ASC)
            results = search.page(1)

            # set results to None if search didn't return anything
            results = None if get_results_length(results) == 0 else results

            return render(request, self.template_name, {
                'form': form,
                'results': results,
                'torrent_form': torrent_form
            })
        else:
            return render(request, self.template_name, {
                'form': form,
                'results': None,
                'torrent_form': torrent_form
            })
Beispiel #2
0
    def post(self, request, *args, **kwargs):
        form = TorrentForm(request.POST)
        data = {}

        if form.is_valid():
            cd = form.cleaned_data
            print cd
            data = {
                "seeders": cd.get("seeders"),
                "title": cd.get("title"),
                "url": cd.get("url"),
                "torrent_link": cd.get("torrent_link"),
                "magnet_link": cd.get("magnet_link"),
                "size": cd.get("size"),
                "leechers": cd.get("leechers"),
                "created": cd.get("created"),
                "user": cd.get("user"),
            }
            result = parse_torrent_page(cd.get("url"))
            data.update(result)

        return render(request, self.template_name, {"data": data}, context_instance=RequestContext(request))
Beispiel #3
0
    def post(self, request, *args, **kwargs):
        form = TorrentForm(request.POST)
        data = {}

        if form.is_valid():
            cd = form.cleaned_data
            print cd
            data = {
                'seeders': cd.get('seeders'),
                'title': cd.get('title'),
                'url': cd.get('url'),
                'torrent_link': cd.get('torrent_link'),
                'magnet_link': cd.get('magnet_link'),
                'size': cd.get('size'),
                'leechers': cd.get('leechers'),
                'created': cd.get('created'),
                'user': cd.get('user')
            }
            result = parse_torrent_page(cd.get('url'))
            data.update(result)

        return render(request,
                      self.template_name, {'data': data},
                      context_instance=RequestContext(request))
Beispiel #4
0
def torrent(tor_id):
	user = g.user

	# fetch informations about the torrent from transmission
	torrent = client.get_torrent(tor_id)
	# fetch information about the torrent from DB
	tordb = Torrent.query.filter_by(hashstring = torrent.hashString).first()
	if tordb.user==unicode(user):

		###
		if torrent.error == 1:
			torrent.error = 'tracker warning'
		if torrent.error == 2:
			torrent.error = 'tracker error'
		if torrent.error == 3:
			torrent.error = 'local error'
		
		control = TorrentForm(ratiomode=torrent.seedRatioMode,bandwidthpriority=torrent.bandwidthPriority)
		###
		for file_x in client.get_files(tor_id)[torrent.id]:
			# no csrf because this form is just a part of a bigger one which has already its own csrf !
			f_form = TorrentFileDetails()
			f_form.key = file_x
			f_form.filename	= unicode(client.get_files(tor_id)[torrent.id][file_x]['name'])
			f_form.priority  = client.get_files(tor_id)[torrent.id][file_x]['priority']
			f_form.size 	 = client.get_files(tor_id)[torrent.id][file_x]['size']
			f_form.completed = client.get_files(tor_id)[torrent.id][file_x]['completed']
			f_form.selected  = client.get_files(tor_id)[torrent.id][file_x]['selected']
			
			control.files.append_entry(f_form)
		
		if control.validate_on_submit():
			update = False
			# by default, ratio limit can be updated !
			update_ratio_limit = True
			if control.ratiomode.data != torrent.seedRatioMode:
				
				if control.ratiomode.data == '0':
					torrent.seed_ratio_mode = 'global'
					# we don't allow anymore the ratio limit to be updated : the ratiolimit will be the gloabal one !
					update_ratio_limit = False
				if control.ratiomode.data == '1':
					torrent.seed_ratio_mode = 'single'
				if control.ratiomode.data == '2':
					torrent.seed_ratio_mode = 'unlimited'
					# we don't allow anymore the ratio limit to be updated : the ratiolimit will be the gloabal one !
					update_ratio_limit = False
				update = True
			
			# if we are still allowed to update ratio limit
			# eg : we haven't touched ratiomode in form - update_ratio_limit is still at its default : true
			# or it has been changed to single mode
			if update_ratio_limit:
				if control.ratiolimit.data != torrent.seedRatioLimit:
					torrent.seed_ratio_limit = float(control.ratiolimit.data)
					torrent.seed_ratio_mode = 'single'
					update = True
			if control.downloadlimit.data != torrent.downloadLimit:
				torrent.download_limit = int(control.downloadlimit.data)
				update = True
			if control.uploadlimit.data != torrent.uploadLimit:
				torrent.upload_limit = int(control.uploadlimit.data)
				update = True
			if int(control.bandwidthpriority.data) != int(torrent.bandwidthPriority):
				updatebandwidthpriority(tor_id,control.bandwidthpriority.data)
			
			# we use the ID returned by transmission itself ! Not the hashString.
			# the first torrent.id is to say which torrent we are talking about. Transmission gives us a dict containing the info for the torrents asked.
			# so the dict contains ONE torrent info
			# but still, begin with the torrent.id, this is why the second torrent.id
			#files_dict = client.get_files(torrent.id)[torrent.id]
			files_answers = {}
			
			for file_un in control.files:
				files_update = False
				# create a dict that contains the new priority for each file according to the form
				file_answer = client.get_files(tor_id)[torrent.id][int(file_un.key.data)]
				if file_un.priority.data != file_answer['priority']:
					update = True
					files_update = True
					file_answer['priority'] = file_un.priority.data
					
				if file_un.selected.data != file_answer['selected']:
					update = True
					files_update = True
					file_answer['selected'] = file_un.selected.data
				
				# append the dict to the general dict previously created (files_answers).
				# the key is the ID of the file itself ! >> no value name !
				if files_update:
					files_answers[int(file_un.key.data)] = file_answer
			
			#finally, we create the last dict which will contain only one value : the files_answers dict !
			answer = {}
			answer[int(torrent.id)] = files_answers
			client.set_files(answer)
			
			if update:
				torrent.update()
			return redirect(redirect_url())
		else:
			app.logger.info(control.errors)
		return render_template("torrent.html", title = torrent.name, user = user, torrent = torrent, control = control)
	
	else:
		return render_template("404.html")