Пример #1
0
def move_listener(request):
    form = request.GET
    request = form_to_request(form)
    arg_hack = json.dumps(request)
    log_event("move_listener", int(form["session_id"]), form)
    dbus_send.emit_stream_signal(int(form["session_id"]), "move_listener", arg_hack)
    return {"success": True}
Пример #2
0
def modify_stream(request):
    success = False
    msg = ""
    # TODO: Why is this request data changed so much? Why isn't msg used?
    form = request.GET
    request = form_to_request(form)
    arg_hack = json.dumps(request)
    log_event("modify_stream", int(form["session_id"]), form)
    logger.debug(request)

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

        audio_format = project.audio_format.upper()
        if stream_exists(int(form["session_id"]), audio_format):
            dbus_send.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 move_listener(request):
    form = request.GET
    request = form_to_request(form)
    arg_hack = json.dumps(request)
    log_event("move_listener", int(form['session_id']), form)
    dbus_send.emit_stream_signal(int(form['session_id']), "move_listener",
                                 arg_hack)
    return {"success": True}
Пример #4
0
def skip_ahead(request):
    form = request.GET
    log_event("skip_ahead", int(form["session_id"]), form)

    if "session_id" not in form:
        raise RoundException("a session_id is required for this operation")
    if not check_for_single_audiotrack(form.get("session_id")):
        raise RoundException("this operation is only valid for projects with 1 audiotrack")
    dbus_send.emit_stream_signal(int(form["session_id"]), "skip_ahead", "")
    return {"success": True}
Пример #5
0
def skip_ahead(request):
    form = request.GET
    log_event("skip_ahead", int(form['session_id']), form)

    if 'session_id' not in form:
        raise RoundException("a session_id is required for this operation")
    if not check_for_single_audiotrack(form.get('session_id')):
        raise RoundException(
            "this operation is only valid for projects with 1 audiotrack")
    dbus_send.emit_stream_signal(int(form['session_id']), "skip_ahead", "")
    return {"success": True}
Пример #6
0
def play_asset_in_stream(request):
    form = request.GET

    request = form_to_request(form)
    arg_hack = json.dumps(request)
    log_event("play_asset_in_stream", int(form["session_id"]), form)

    if "session_id" not in form:
        raise RoundException("a session_id is required for this operation")
    if not check_for_single_audiotrack(form.get("session_id")):
        raise RoundException("this operation is only valid for projects with 1 audiotrack")
    if "asset_id" not in form:
        raise RoundException("an asset_id is required for this operation")
    dbus_send.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

    request = form_to_request(form)
    arg_hack = json.dumps(request)
    log_event("play_asset_in_stream", int(form['session_id']), form)

    if 'session_id' not in form:
        raise RoundException("a session_id is required for this operation")
    if not check_for_single_audiotrack(form.get('session_id')):
        raise RoundException(
            "this operation is only valid for projects with 1 audiotrack")
    if 'asset_id' not in form:
        raise RoundException("an asset_id is required for this operation")
    dbus_send.emit_stream_signal(int(form['session_id']), "play_asset",
                                 arg_hack)
    return {"success": True}
Пример #8
0
def modify_stream(request):
    success = False
    msg = ""
    # TODO: Why is this request data changed so much? Why isn't msg used?
    form = request.GET
    request = form_to_request(form)
    arg_hack = json.dumps(request)
    log_event("modify_stream", int(form['session_id']), form)
    logger.debug(request)

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

        audio_format = project.audio_format.upper()
        if stream_exists(int(form['session_id']), audio_format):
            dbus_send.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 heartbeat(request):
    form = request.GET
    dbus_send.emit_stream_signal(int(form['session_id']), "heartbeat", "")
    log_event("heartbeat", int(form['session_id']), form)
    return {"success": True}
Пример #10
0
def add_asset_to_envelope(request):

    # get asset_id from the GET request
    asset_id = get_parameter_from_request(request, 'asset_id')
    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(
                "Invalid Asset ID Provided. No Asset exists with ID %s" %
                asset_id)

    envelope_id = get_parameter_from_request(request, 'envelope_id', True)
    logger.debug("Found asset_id: %d, envelope_id: %d", asset_id, envelope_id)

    try:
        envelope = models.Envelope.objects.select_related('session').get(
            id=envelope_id)
    except models.Envelope.DoesNotExist:
        raise RoundException(
            "Invalid Envelope ID Provided. No Envelope exists with ID %s" %
            envelope_id)

    session = envelope.session

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

    fileitem = asset.file if asset else request.FILES.get('file')
    if not fileitem.name:
        raise RoundException("No file in request")

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

    # copy the file to a unique name (current time and date)
    logger.debug("Processing " + fileitem.name)
    (filename_prefix, filename_extension) = os.path.splitext(fileitem.name)

    dest_filename = time.strftime("%Y%m%d-%H%M%S-") + str(session.id) + \
        filename_extension
    dest_filepath = os.path.join(settings.MEDIA_ROOT, dest_filename)
    if os.path.isfile(dest_filepath):
        raise RoundException("File already exists: %s" % dest_filepath)

    fileout = open(dest_filepath, 'wb')
    fileout.write(fileitem.file.read())
    fileout.close()

    # Delete the uploaded original after the copy has been made.
    if asset:
        asset.file.delete()
        asset.file.name = dest_filename
        asset.filename = dest_filename
        asset.save()
    # Make sure everything is in wav form only if media type is audio.
    if mediatype == "audio":
        newfilename = convertaudio.convert_uploaded_file(dest_filename)
    else:
        newfilename = dest_filename
    if not newfilename:
        raise RoundException("File not converted successfully: " + newfilename)

    # if the request comes from the django admin interface
    # update the Asset with the right information
    if asset:
        asset.session = session
        asset.filename = newfilename
    # create the new asset if request comes in from a source other
    # than the django admin interface
    else:
        # get location data from request
        latitude = get_parameter_from_request(request, 'latitude')
        longitude = get_parameter_from_request(request, 'longitude')
        # 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')
        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')
        # 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 = dest_filename
        asset.save()
        for t in tagset:
            asset.tags.add(t)

    # 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()

    dbus_send.emit_stream_signal(0, "refresh_recordings", "")
    return {"success": True, "asset_id": asset.id}
Пример #11
0
def heartbeat(request):
    form = request.GET
    dbus_send.emit_stream_signal(int(form["session_id"]), "heartbeat", "")
    log_event("heartbeat", int(form["session_id"]), form)
    return {"success": True}
Пример #12
0
def add_asset_to_envelope(request):

    # get asset_id from the GET request
    asset_id = get_parameter_from_request(request, "asset_id")
    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("Invalid Asset ID Provided. No Asset exists with ID %s" % asset_id)

    envelope_id = get_parameter_from_request(request, "envelope_id", True)
    logger.debug("Found asset_id: %d, envelope_id: %d", asset_id, envelope_id)

    try:
        envelope = models.Envelope.objects.select_related("session").get(id=envelope_id)
    except models.Envelope.DoesNotExist:
        raise RoundException("Invalid Envelope ID Provided. No Envelope exists with ID %s" % envelope_id)

    session = envelope.session

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

    fileitem = asset.file if asset else request.FILES.get("file")
    if not fileitem.name:
        raise RoundException("No file in request")

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

    # copy the file to a unique name (current time and date)
    logger.debug("Processing " + fileitem.name)
    (filename_prefix, filename_extension) = os.path.splitext(fileitem.name)

    dest_filename = time.strftime("%Y%m%d-%H%M%S-") + str(session.id) + filename_extension
    dest_filepath = os.path.join(settings.MEDIA_ROOT, dest_filename)
    if os.path.isfile(dest_filepath):
        raise RoundException("File already exists: %s" % dest_filepath)

    fileout = open(dest_filepath, "wb")
    fileout.write(fileitem.file.read())
    fileout.close()

    # Delete the uploaded original after the copy has been made.
    if asset:
        asset.file.delete()
        asset.file.name = dest_filename
        asset.filename = dest_filename
        asset.save()
    # Make sure everything is in wav form only if media type is audio.
    if mediatype == "audio":
        newfilename = convertaudio.convert_uploaded_file(dest_filename)
    else:
        newfilename = dest_filename
    if not newfilename:
        raise RoundException("File not converted successfully: " + newfilename)

    # if the request comes from the django admin interface
    # update the Asset with the right information
    if asset:
        asset.session = session
        asset.filename = newfilename
    # create the new asset if request comes in from a source other
    # than the django admin interface
    else:
        # get location data from request
        latitude = get_parameter_from_request(request, "latitude")
        longitude = get_parameter_from_request(request, "longitude")
        # 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")
        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")
        # 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 = dest_filename
        asset.save()
        for t in tagset:
            asset.tags.add(t)

    # 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()

    dbus_send.emit_stream_signal(0, "refresh_recordings", "")
    return {"success": True, "asset_id": asset.id}