예제 #1
0
def move_listener(request):
    form = request.GET
    request = form_to_request(form)
    arg_hack = json.dumps(request)
    rounddbus.emit_stream_signal(int(form['session_id']), "move_listener",
                                 arg_hack)
    return {"success": True}
예제 #2
0
def modify_stream(request):
    success = False
    msg = ""
    form = request.GET
    request = form_to_request(form)
    arg_hack = json.dumps(request)
    db.log_event("modify_stream", int(form['session_id']), form)

    if form.has_key('session_id'):
        session = models.Session.objects.select_related('project').get(id=form['session_id'])
        project = session.project
        if form.has_key('language'):
            try:
                logging.debug("modify_stream: language: " + form['language'])
                l = models.Language.objects.filter(language_code=form['language'])[0]
                session.language = l
                session.save()
            except:
                raise roundexception.RoundException("language not supported")

        audio_format = project.audio_format.upper()
        if stream_exists(int(form['session_id']), audio_format):
            rounddbus.emit_stream_signal(int(form['session_id']), "modify_stream", arg_hack)
            success = True
        else:
            msg = "no stream available for session: " + form['session_id']
    else:
        msg = "a session_id is required for this operation"

    if success:
        return {"success": success}
    else:
        return {"success": success, }
예제 #3
0
def skip_ahead(request):
    form = request.GET
    db.log_event("skip_ahead", int(form['session_id']), form)

    if not form.has_key('session_id'):
        raise roundexception.RoundException("a session_id is required for this operation")
    if check_for_single_audiotrack(form.get('session_id')) != True:
        raise roundexception.RoundException("this operation is only valid for projects with 1 audiotrack")
    rounddbus.emit_stream_signal(int(form['session_id']), "skip_ahead", "")
    return {"success": True}
예제 #4
0
def skip_ahead(request):
    form = request.GET
    db.log_event("skip_ahead", int(form['session_id']), form)

    if not form.has_key('session_id'):
        raise roundexception.RoundException(
            "a session_id is required for this operation")
    if check_for_single_audiotrack(form.get('session_id')) != True:
        raise roundexception.RoundException(
            "this operation is only valid for projects with 1 audiotrack")
    rounddbus.emit_stream_signal(int(form['session_id']), "skip_ahead", "")
    return {"success": True}
예제 #5
0
def add_asset_to_envelope(request):

	envelope_id = get_parameter_from_request(request, 'envelope_id', True)
	latitude = get_parameter_from_request(request, 'latitude', False)
	longitude = get_parameter_from_request(request, 'longitude', False)
	if latitude == None:
		latitude = 0.0
	if longitude == None:
		longitude = 0.0
	
	tagset = []
	tags = get_parameter_from_request(request, 'tags', False)
	if tags != None:
		ids = tags.split(',')
		tagset = models.Tag.objects.filter(id__in=ids)

	envelope = models.Envelope.objects.get(id=envelope_id)
	session = envelope.session
	submitted = get_parameter_from_request(request, 'submitted', False)
	if submitted == None:
		submitted=session.project.auto_submit 
	
	db.log_event("start_upload", session.id,request.GET)
	
	fileitem = request.FILES.get('file')
	if fileitem.name:
		logging.debug("Processing " + fileitem.name)
		(filename_prefix, filename_extension) = \
			os.path.splitext(fileitem.name)
		fn = time.strftime("%Y%m%d-%H%M%S") + filename_extension
		fileout = open(os.path.join(settings.config["upload_dir"], fn), 'wb')
		fileout.write(fileitem.file.read())
		fileout.close()
		newfilename = convertaudio.convert_uploaded_file(fn)
		if newfilename:
			asset = models.Asset(latitude=latitude,longitude=longitude,
			                      filename=newfilename, session=session, submitted=submitted, volume=1.0)
			asset.project = session.project
			asset.save()
			for t in tagset:
				asset.tags.add(t)
			
			discover_audiolength.discover_and_set_audiolength(asset, newfilename)
			asset.save()
			envelope.assets.add(asset)
			envelope.save()
		else:
			raise RoundException("File not converted successfully: " + newfilename)		
	else:
		raise RoundException("No file in request")
	rounddbus.emit_stream_signal(0, "refresh_recordings", "")
	return {"success":True}
예제 #6
0
def play_asset_in_stream(request):
    form = request.GET
    # add skipped asset_id to form in order to track which asset is played
    #assetid = form[asset_id]
    #form[data] = form["asset_id"]
    request = form_to_request(form)
    arg_hack = json.dumps(request)
    db.log_event("play_asset_in_stream", int(form['session_id']), form)

    if not form.has_key('session_id'):
        raise roundexception.RoundException("a session_id is required for this operation")
    if check_for_single_audiotrack(form.get('session_id')) != True:
        raise roundexception.RoundException("this operation is only valid for projects with 1 audiotrack")
    if not form.has_key('asset_id'):
        raise roundexception.RoundException("an asset_id is required for this operation")
    rounddbus.emit_stream_signal(int(form['session_id']), "play_asset", arg_hack)
    return {"success": True}
예제 #7
0
def play_asset_in_stream(request):
    form = request.GET
    # add skipped asset_id to form in order to track which asset is played
    #assetid = form[asset_id]
    #form[data] = form["asset_id"]
    request = form_to_request(form)
    arg_hack = json.dumps(request)
    db.log_event("play_asset_in_stream", int(form['session_id']), form)

    if not form.has_key('session_id'):
        raise roundexception.RoundException(
            "a session_id is required for this operation")
    if check_for_single_audiotrack(form.get('session_id')) != True:
        raise roundexception.RoundException(
            "this operation is only valid for projects with 1 audiotrack")
    if not form.has_key('asset_id'):
        raise roundexception.RoundException(
            "an asset_id is required for this operation")
    rounddbus.emit_stream_signal(int(form['session_id']), "play_asset",
                                 arg_hack)
    return {"success": True}
예제 #8
0
def modify_stream(request):
    success = False
    msg = ""
    form = request.GET
    request = form_to_request(form)
    arg_hack = json.dumps(request)
    db.log_event("modify_stream", int(form['session_id']), form)

    if form.has_key('session_id'):
        session = models.Session.objects.select_related('project').get(
            id=form['session_id'])
        project = session.project
        if form.has_key('language'):
            try:
                logging.debug("modify_stream: language: " + form['language'])
                l = models.Language.objects.filter(
                    language_code=form['language'])[0]
                session.language = l
                session.save()
            except:
                raise roundexception.RoundException("language not supported")

        audio_format = project.audio_format.upper()
        if stream_exists(int(form['session_id']), audio_format):
            rounddbus.emit_stream_signal(int(form['session_id']),
                                         "modify_stream", arg_hack)
            success = True
        else:
            msg = "no stream available for session: " + form['session_id']
    else:
        msg = "a session_id is required for this operation"

    if success:
        return {"success": success}
    else:
        return {
            "success": success,
        }
예제 #9
0
def modify_stream (request):
	success = False
	msg = ""
	form = request.GET
	request = form_to_request(form)
	arg_hack = json.dumps(request)
	db.log_event("modify_stream", int(form['session_id']),form)
	if form.has_key('session_id'):
		session = models.Session.objects.get(id=form['session_id'])
		project = session.project
		audio_format = project.audio_format.upper()
		if stream_exists(int(form['session_id']), audio_format):
			rounddbus.emit_stream_signal(int(form['session_id']), "modify_stream", arg_hack)
			success = True
		else:
			msg = "no stream available for session: " + form['session_id']
	else:
		msg = "a session_id is required for this operation"
		
		
	if success:
		return {"success":success}
	else:
		return {"success":success,"user_error_message":msg}
예제 #10
0
def skip_ahead (form):
	rounddbus.emit_stream_signal(int(form['sessionid']), "skip_ahead", "")
	return True #FIXME: return false if it failed. don't always return true
예제 #11
0
def move_listener (form):
	db.log_event(1, form)
	request = form_to_request(form)
	arg_hack = json.dumps(request)
	rounddbus.emit_stream_signal(int(form['sessionid']), "move_listener", arg_hack)
	return True
예제 #12
0
def heartbeat (request):
	form = request.GET
	rounddbus.emit_stream_signal(int(form['session_id']), "heartbeat", "")
	db.log_event("heartbeat", int(form['session_id']),form)
	return {"success":True}
예제 #13
0
def move_listener (request):
	form = request.GET
	request = form_to_request(form)
	arg_hack = json.dumps(request)
	rounddbus.emit_stream_signal(int(form['session_id']), "move_listener", arg_hack)
	return {"success":True}
예제 #14
0
def heartbeat(request):
    form = request.GET
    rounddbus.emit_stream_signal(int(form['session_id']), "heartbeat", "")
    db.log_event("heartbeat", int(form['session_id']), form)
    return {"success": True}
예제 #15
0
def add_asset_to_envelope(request):

    #get asset_id from the GET request
    asset_id = get_parameter_from_request(request, 'asset_id', False)
    asset = None
    #grab the Asset from the database, if an asset_id has been passed in
    if asset_id:
        try:
            asset = models.Asset.objects.get(pk=asset_id)
        except models.Asset.DoesNotExist:
            raise roundexception.RoundException(
                "Invalid Asset ID Provided. No Asset exists with ID %s" %
                asset_id)
    envelope_id = get_parameter_from_request(request, 'envelope_id', True)

    envelope = models.Envelope.objects.select_related('session').get(
        id=envelope_id)
    session = envelope.session

    db.log_event("start_upload", session.id, request.GET)

    fileitem = request.FILES.get('file') if not asset else asset.file
    #get mediatype from the GET request
    mediatype = get_parameter_from_request(
        request, 'mediatype', False) if not asset else asset.mediatype
    #if mediatype parameter not passed, set to 'audio'
    #this ensures backwards compatibility
    if mediatype is None:
        mediatype = "audio"

    if fileitem.name:
        #copy the file to a unique name (current time and date)
        logging.debug("Processing " + fileitem.name)
        (filename_prefix, filename_extension) = \
            os.path.splitext(fileitem.name)
        fn = time.strftime("%Y%m%d-%H%M%S") + filename_extension
        fileout = open(os.path.join(settings.config["upload_dir"], fn), 'wb')
        fileout.write(fileitem.file.read())
        fileout.close()
        #delete the uploaded original after the copy has been made
        if asset:
            asset.file.delete()
            # re-assign file to asset
            asset.file.name = fn
            asset.filename = fn
            asset.save()
        #make sure everything is in wav form only if mediatype is audio
        if mediatype == "audio":
            newfilename = convertaudio.convert_uploaded_file(fn)
        else:
            newfilename = fn
        if newfilename:
            #create the new asset if request comes in from a source other
            #than the django admin interface
            if not asset:
                #get location data from request
                latitude = get_parameter_from_request(request, 'latitude',
                                                      False)
                longitude = get_parameter_from_request(request, 'longitude',
                                                       False)
                #if no location data in request, default to project latitude and longitude
                if not latitude:
                    latitude = session.project.latitude
                if not longitude:
                    longitude = session.project.longitude
                tagset = []
                tags = get_parameter_from_request(request, 'tags', False)
                if tags is not None:
                    ids = tags.split(',')
                    tagset = models.Tag.objects.filter(id__in=ids)

                # get optional submitted parameter from request (Y, N or blank string are only acceptable values)
                submitted = get_parameter_from_request(request, 'submitted',
                                                       False)
                # set submitted variable to proper boolean value if it is passed as parameter
                if submitted == "N":
                    submitted = False
                elif submitted == "Y":
                    submitted = True
                # if blank string or not included as parameter, check if in range of project and if so
                # set asset.submitted based on project.auto_submit boolean value
                elif submitted is None or len(submitted) == 0:
                    submitted = False
                    if is_listener_in_range_of_stream(request.GET,
                                                      session.project):
                        submitted = session.project.auto_submit

                asset = models.Asset(latitude=latitude,
                                     longitude=longitude,
                                     filename=newfilename,
                                     session=session,
                                     submitted=submitted,
                                     mediatype=mediatype,
                                     volume=1.0,
                                     language=session.language,
                                     project=session.project)
                asset.file.name = fn
                asset.save()
                for t in tagset:
                    asset.tags.add(t)
            #if the request comes from the django admin interface
            #update the Asset with the right information
            else:
                #update asset with session
                asset.session = session
                asset.filename = newfilename

            #get the audiolength of the file only if mediatype is audio and update the Asset
            if mediatype == "audio":
                discover_audiolength.discover_and_set_audiolength(
                    asset, newfilename)
                asset.save()
            envelope.assets.add(asset)
            envelope.save()
        else:
            raise roundexception.RoundException(
                "File not converted successfully: " + newfilename)
    else:
        raise roundexception.RoundException("No file in request")
    rounddbus.emit_stream_signal(0, "refresh_recordings", "")
    return {"success": True, "asset_id": asset.id}
예제 #16
0
def heartbeat (form):
	db.log_event(2, form)
	rounddbus.emit_stream_signal(int(form['sessionid']), "heartbeat", "")
	return True #FIXME: return false if it failed. don't always return true
예제 #17
0
def refresh_recordings ():
	#NOTE: The zero is a hack. No ID is required.
	rounddbus.emit_stream_signal(0, "refresh_recordings", "")
예제 #18
0
def add_asset_to_envelope(request):

    #get asset_id from the GET request
    asset_id = get_parameter_from_request(request, 'asset_id', False)
    asset = None
    #grab the Asset from the database, if an asset_id has been passed in
    if asset_id:
        try:
            asset = models.Asset.objects.get(pk=asset_id)
        except models.Asset.DoesNotExist:
            raise roundexception.RoundException("Invalid Asset ID Provided. No Asset exists with ID %s" % asset_id)
    envelope_id = get_parameter_from_request(request, 'envelope_id', True)

    envelope = models.Envelope.objects.select_related('session').get(id=envelope_id)
    session = envelope.session

    db.log_event("start_upload", session.id, request.GET)

    fileitem = request.FILES.get('file') if not asset else asset.file
    #get mediatype from the GET request
    mediatype = get_parameter_from_request(request, 'mediatype', False) if not asset else asset.mediatype
    #if mediatype parameter not passed, set to 'audio'
    #this ensures backwards compatibility
    if mediatype is None:
        mediatype = "audio"

    if fileitem.name:
        #copy the file to a unique name (current time and date)
        logging.debug("Processing " + fileitem.name)
        (filename_prefix, filename_extension) = \
            os.path.splitext(fileitem.name)
        fn = time.strftime("%Y%m%d-%H%M%S") + filename_extension
        fileout = open(os.path.join(settings.config["upload_dir"], fn), 'wb')
        fileout.write(fileitem.file.read())
        fileout.close()
        #delete the uploaded original after the copy has been made
        if asset:
            asset.file.delete()
            # re-assign file to asset
            asset.file.name = fn
            asset.filename = fn
            asset.save()
        #make sure everything is in wav form only if mediatype is audio
        if mediatype == "audio":
            newfilename = convertaudio.convert_uploaded_file(fn)
        else:
            newfilename = fn
        if newfilename:
            #create the new asset if request comes in from a source other
            #than the django admin interface
            if not asset:
                #get location data from request
                latitude = get_parameter_from_request(request, 'latitude', False)
                longitude = get_parameter_from_request(request, 'longitude', False)
                #if no location data in request, default to project latitude and longitude
                if not latitude:
                    latitude = session.project.latitude
                if not longitude:
                    longitude = session.project.longitude
                tagset = []
                tags = get_parameter_from_request(request, 'tags', False)
                if tags is not None:
                    ids = tags.split(',')
                    tagset = models.Tag.objects.filter(id__in=ids)

                # get optional submitted parameter from request (Y, N or blank string are only acceptable values)
                submitted = get_parameter_from_request(request, 'submitted', False)
                # set submitted variable to proper boolean value if it is passed as parameter
                if submitted == "N":
                    submitted = False
                elif submitted == "Y":
                    submitted = True
                # if blank string or not included as parameter, check if in range of project and if so
                # set asset.submitted based on project.auto_submit boolean value
                elif submitted is None or len(submitted) == 0:
                    submitted = False
                    if is_listener_in_range_of_stream(request.GET, session.project):
                        submitted = session.project.auto_submit

                asset = models.Asset(latitude=latitude,
                                     longitude=longitude,
                                     filename=newfilename,
                                     session=session,
                                     submitted=submitted,
                                     mediatype=mediatype,
                                     volume=1.0,
                                     language=session.language,
                                     project = session.project)
                asset.file.name = fn
                asset.save()
                for t in tagset:
                    asset.tags.add(t)
            #if the request comes from the django admin interface
            #update the Asset with the right information
            else:
                #update asset with session
                asset.session = session
                asset.filename = newfilename

            #get the audiolength of the file only if mediatype is audio and update the Asset
            if mediatype == "audio":
                discover_audiolength.discover_and_set_audiolength(asset, newfilename)
                asset.save()
            envelope.assets.add(asset)
            envelope.save()
        else:
            raise roundexception.RoundException("File not converted successfully: " + newfilename)
    else:
        raise roundexception.RoundException("No file in request")
    rounddbus.emit_stream_signal(0, "refresh_recordings", "")
    return {"success": True,
            "asset_id": asset.id}