Esempio n. 1
0
def create_screenshot_from_production_link(production_link_id):
    try:
        prod_link = ProductionLink.objects.get(id=production_link_id)
        if prod_link.production.screenshots.count():
            return  # don't create a screenshot if there's one already

        production_id = prod_link.production_id
        url = prod_link.download_url
        download, file_content = fetch_url(url)
        buf = cStringIO.StringIO(file_content)

        if prod_link.is_zip_file():
            z = zipfile.ZipFile(buf, 'r')
            # catalogue the zipfile contents if we don't have them already
            if not download.archive_members.all():
                download.log_zip_contents(z)
            # select the archive member to extract a screenshot from, if we don't have
            # a candidate already
            if not prod_link.file_for_screenshot:
                file_for_screenshot = download.select_screenshot_file()
                if file_for_screenshot:
                    prod_link.file_for_screenshot = file_for_screenshot
                    prod_link.is_unresolved_for_screenshotting = False
                else:
                    prod_link.is_unresolved_for_screenshotting = True
                prod_link.save()

            image_extension = prod_link.file_for_screenshot.split(
                '.')[-1].lower()
            if image_extension in USABLE_IMAGE_FILE_EXTENSIONS:
                # we encode the filename as iso-8859-1 before retrieving it, because we
                # decoded it that way on insertion into the database to ensure that it had
                # a valid unicode string representation - see mirror/models.py
                member_buf = cStringIO.StringIO(
                    z.read(prod_link.file_for_screenshot.encode('iso-8859-1')))
                z.close()
                img = PILConvertibleImage(
                    member_buf, name_hint=prod_link.file_for_screenshot)
            else:  # image is not a usable format
                z.close()
                return
        else:
            img = PILConvertibleImage(buf, name_hint=url.split('/')[-1])

        screenshot = Screenshot(production_id=production_id,
                                source_download_id=download.id)
        u = download.sha1
        basename = u[0:2] + '/' + u[2:4] + '/' + u[4:8] + '.pl' + str(
            production_link_id) + '.'
        upload_original(img, screenshot, basename, reduced_redundancy=True)
        upload_standard(img, screenshot, basename)
        upload_thumb(img, screenshot, basename)
        screenshot.save()

    except ProductionLink.DoesNotExist:
        # guess it was deleted in the meantime, then.
        pass
Esempio n. 2
0
def create_screenshot_from_production_link(production_link_id):
	try:
		prod_link = ProductionLink.objects.get(id=production_link_id)
		if prod_link.production.screenshots.count():
			return  # don't create a screenshot if there's one already

		production_id = prod_link.production_id
		url = prod_link.download_url
		download, file_content = fetch_url(url)
		buf = cStringIO.StringIO(file_content)

		if prod_link.is_zip_file():
			z = zipfile.ZipFile(buf, 'r')
			# catalogue the zipfile contents if we don't have them already
			if not download.archive_members.all():
				download.log_zip_contents(z)
			# select the archive member to extract a screenshot from, if we don't have
			# a candidate already
			if not prod_link.file_for_screenshot:
				file_for_screenshot = download.select_screenshot_file()
				if file_for_screenshot:
					prod_link.file_for_screenshot = file_for_screenshot
					prod_link.is_unresolved_for_screenshotting = False
				else:
					prod_link.is_unresolved_for_screenshotting = True
				prod_link.save()

			image_extension = prod_link.file_for_screenshot.split('.')[-1].lower()
			if image_extension in USABLE_IMAGE_FILE_EXTENSIONS:
				# we encode the filename as iso-8859-1 before retrieving it, because we
				# decoded it that way on insertion into the database to ensure that it had
				# a valid unicode string representation - see mirror/models.py
				member_buf = cStringIO.StringIO(
					z.read(prod_link.file_for_screenshot.encode('iso-8859-1'))
				)
				z.close()
				img = PILConvertibleImage(member_buf, name_hint=prod_link.file_for_screenshot)
			else:  # image is not a usable format
				z.close()
				return
		else:
			img = PILConvertibleImage(buf, name_hint=url.split('/')[-1])

		screenshot = Screenshot(production_id=production_id, source_download_id=download.id)
		u = download.sha1
		basename = u[0:2] + '/' + u[2:4] + '/' + u[4:8] + '.pl' + str(production_link_id) + '.'
		upload_original(img, screenshot, basename, reduced_redundancy=True)
		upload_standard(img, screenshot, basename)
		upload_thumb(img, screenshot, basename)
		screenshot.save()

	except ProductionLink.DoesNotExist:
		# guess it was deleted in the meantime, then.
		pass
Esempio n. 3
0
def create_screenshot_from_remote_file(url, production_id):
	try:
		download, file_content = fetch_url(url)
		screenshot = Screenshot(production_id=production_id, source_download_id=download.id)

		buf = cStringIO.StringIO(file_content)
		img = PILConvertibleImage(buf, name_hint=url.split('/')[-1])

		u = download.sha1
		basename = u[0:2] + '/' + u[2:4] + '/' + u[4:8] + '.p' + str(production_id) + '.'
		upload_original(img, screenshot, basename, reduced_redundancy=True)
		upload_standard(img, screenshot, basename)
		upload_thumb(img, screenshot, basename)
		screenshot.save()

	except (urllib2.URLError, FileTooBig):
		# oh well.
		pass
Esempio n. 4
0
def create_screenshot_from_remote_file(url, production_id):
    try:
        download, file_content = fetch_url(url)
        screenshot = Screenshot(production_id=production_id,
                                source_download_id=download.id)

        buf = cStringIO.StringIO(file_content)
        img = PILConvertibleImage(buf, name_hint=url.split('/')[-1])

        u = download.sha1
        basename = u[0:2] + '/' + u[2:4] + '/' + u[4:8] + '.p' + str(
            production_id) + '.'
        upload_original(img, screenshot, basename, reduced_redundancy=True)
        upload_standard(img, screenshot, basename)
        upload_thumb(img, screenshot, basename)
        screenshot.save()

    except (urllib2.URLError, FileTooBig):
        # oh well.
        pass