示例#1
0
    def Upload(logger, imagePath=None, imageUrl=None):
        if imageUrl is None:
            return PtpImg.__UploadInternal(logger, imagePath, imageUrl)

        # Get image extension from the URL and fall back to ptpimg.me's rehosting if it's not JPG or PNG.
        fileName, extension = os.path.splitext(imageUrl)
        extension = extension.lower()
        if (extension != ".jpg" and extension != ".jpeg"
                and extension != ".png"):
            return PtpImg.__UploadInternal(logger, imagePath, imageUrl)

        # Get a random name for the temporary file.
        imagePath = os.path.join(Settings.GetTemporaryPath(),
                                 str(uuid.uuid1()) + extension)

        # Download image.
        response = urllib2.urlopen(imageUrl)
        response = response.read()
        f = open(imagePath, "wb")
        f.write(response)
        f.close()

        try:
            return PtpImg.__UploadInternal(logger, imagePath, None)
        finally:
            os.remove(imagePath)
示例#2
0
def ajaxGetIncludedFileList():
    includedFileList = IncludedFileList()
    jobId = request.values.get("JobId")
    sourceTorrentFilename = request.values.get("SourceTorrentFilename")
    releaseDownloadPath = request.values.get("ReleaseDownloadPath")
    includedFilesCustomizedList = request.values.get(
        "IncludedFilesCustomizedList")

    if jobId:
        jobId = int(jobId)
        releaseInfo = Database.DbSession.query(ReleaseInfo).filter(
            ReleaseInfo.Id == jobId).first()
        announcementSource = MyGlobals.SourceFactory.GetSource(
            releaseInfo.AnnouncementSourceName)
        if announcementSource:
            includedFileList = announcementSource.GetIncludedFileList(
                releaseInfo)
    elif sourceTorrentFilename:
        sourceTorrentFilename = secure_filename(sourceTorrentFilename)
        sourceTorrentFilename = os.path.join(Settings.GetTemporaryPath(),
                                             sourceTorrentFilename)
        includedFileList.FromTorrent(sourceTorrentFilename)
    elif releaseDownloadPath:
        includedFileList.FromDirectory(releaseDownloadPath)
    else:
        return jsonify(result="ERROR")

    includedFileList.ApplyCustomizationFromJson(includedFilesCustomizedList)

    return jsonify(result="OK",
                   files=MakeIncludedFilesTreeJson(includedFileList))
示例#3
0
def ajaxExternalCreateJob():
    if ("Password" not in request.values) or request.values[
            "Password"] != Settings.GreasemonkeyTorrentSenderPassword:
        return MakeExternalCreateJobErrorResponse(
            "Invalid Greasemonkey Send to Script password!")

    file = request.files.get("Torrent")
    # file is not None even there is no file specified, but checking file as a boolean is OK. (As shown in the Flask example.)
    if not file:
        return MakeExternalCreateJobErrorResponse("Got no torrent file!")

    filename = "external job." + str(uuid.uuid1()) + ".torrent"
    sourceTorrentFilePath = os.path.join(Settings.GetTemporaryPath(), filename)
    file.save(sourceTorrentFilePath)

    releaseName, torrentContentSize = GetSuggestedReleaseNameAndSizeFromTorrentFile(
        sourceTorrentFilePath)

    releaseInfo = ReleaseInfo()
    releaseInfo.LastModificationTime = Database.MakeTimeStamp()
    releaseInfo.JobRunningState = JobRunningState.Paused
    releaseInfo.JobStartMode = JobStartMode.Manual
    releaseInfo.SourceTorrentFilePath = sourceTorrentFilePath
    releaseInfo.AnnouncementSourceName = "torrent"
    releaseInfo.ReleaseName = releaseName
    releaseInfo.Size = torrentContentSize
    releaseInfo.SetOverrideScreenshots(Settings.OverrideScreenshots)
    releaseInfo.ReleaseNotes = Settings.ReleaseNotes

    if Settings.ForceDirectorylessSingleFileTorrent:
        releaseInfo.SetForceDirectorylessSingleFileTorrent()

    if Settings.PersonalRip:
        releaseInfo.SetPersonalRip()

    if Settings.SkipDuplicateChecking:
        releaseInfo.DuplicateCheckCanIgnore = sys.maxint

    imdbId = ""
    if "ImdbUrl" in request.values:
        imdbId = NfoParser.GetImdbId(request.values["ImdbUrl"])
        if len(imdbId) > 0:
            releaseInfo.ImdbId = imdbId

    if "PageContent" in request.values:
        DoParsePageForExternalCreateJob(releaseInfo,
                                        request.values["SourceUrl"],
                                        request.values["PageContent"])

    Database.DbSession.add(releaseInfo)
    Database.DbSession.commit()

    # Just add the job, don't start it.

    response = make_response(jsonify(result="OK", jobId=releaseInfo.Id))
    response.headers[
        'Access-Control-Allow-Origin'] = '*'  # Enable cross-origin resource sharing.
    return response
示例#4
0
文件: Upload.py 项目: Aniverse/p1
def UploadTorrentFile(releaseInfo, request):
	torrentFilename = request.values[ "uploaded_torrentfilename" ]
	if not IsFileAllowed( torrentFilename ):
		return False

	torrentContentSize = request.values[ "uploaded_torrentcontentsize" ]
	if len( torrentContentSize ) <= 0: # Length of the string.
		return False
		
	torrentFilename = secure_filename( torrentFilename )
	torrentFilename = os.path.join( Settings.GetTemporaryPath(), torrentFilename )
	if not os.path.isfile( torrentFilename ):
		return False
	
	releaseInfo.SourceTorrentFilePath = torrentFilename
	releaseInfo.AnnouncementSourceName = "torrent"
	releaseInfo.Size = int( torrentContentSize )
	return True 
示例#5
0
文件: Upload.py 项目: Aniverse/p1
def ajaxUploadTorrentFile():
	file = request.files.get( "files[]" )
	# file is not None even there is no file specified, but checking file as a boolean is OK. (As shown in the Flask example.) 
	if ( not file ) or ( not IsFileAllowed( file.filename ) ):
		return jsonify( myResult = "ERROR" )
		
	filename = secure_filename( file.filename )
	
	# We add an UUID to the filename to make sure it is unique in the temporary folder.
	filename, extension = os.path.splitext( filename )
	filename += "." + str( uuid.uuid1() ) + extension

	sourceTorrentFilePath = os.path.join( Settings.GetTemporaryPath(), filename )
	file.save( sourceTorrentFilePath )
	
	releaseName, size = GetSuggestedReleaseNameAndSizeFromTorrentFile( sourceTorrentFilePath )
	sizeText = SizeToText( size )

	return jsonify( myResult = "OK", torrentFilename = filename, releaseName = releaseName, torrentContentSize = size, torrentContentSizeText = sizeText )
示例#6
0
	def __DownloadImage( logger, imageUrl ):
		# Get image extension from the URL.
		fileName, extension = os.path.splitext( imageUrl )
		extension = extension.lower()
		if ( extension != ".jpg" and extension != ".jpeg" and extension != ".png" ):
			raise PtpUploaderException( "Invalid image file extension." )

		# Download the image.
		result = MyGlobals.session.get( imageUrl )
		result.raise_for_status()
		response = result.content

		# Save the image with a random name.
		imagePath = os.path.join( Settings.GetTemporaryPath(), str( uuid.uuid1() ) + extension )
		f = open( imagePath, "wb" )
		f.write( response )
		f.close()

		return imagePath