# Create a studio task

`POST /api/v1/videos/{id}/studio/edit`

Create a task to edit a video (cut, add intro/outro etc). By default the video is edited in place. Set `saveAsNewVideo` to keep it untouched and save the result in a new video.

Authentication (security requirement alternatives):

```json
[
  {
    "OAuth2": []
  }
]
```

- OAuth2: oauth2. Authenticating via OAuth requires the following steps:
- Have an activated account
- [Generate] an access token for that account at `/api/v1/users/token`.
- Make requests with the *Authorization: Bearer <token\>* header
- Profit, depending on the role assigned to the account

Note that the __access token is valid for 1 day__ and is given
along with a __refresh token valid for 2 weeks__.

[Generate]: https://docs.joinpeertube.org/api/rest-getting-started


Parameters:

- `id` (path, id | UUIDv4 | shortUUID, required) - The object id, uuid or short uuid
  Type: id | UUIDv4 | shortUUID
  
  oneOf:
    Reference: [id](https://sourcey-peertube.pages.dev/api-rest-reference/models/id.md); Type: id
    
    minimum: 1
    
    Example:
    
    ```json
    42
    ```
  
    Reference: [UUIDv4](https://sourcey-peertube.pages.dev/api-rest-reference/models/uuidv4.md); Type: UUIDv4, uuid
    
    minLength: 36
    
    maxLength: 36
    
    pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    
    Example:
    
    ```json
    "9c9de5e8-0a1e-484a-b099-e80766180a6d"
    ```
  
    Reference: [shortUUID](https://sourcey-peertube.pages.dev/api-rest-reference/models/shortuuid.md); Type: shortUUID
    
    translation of a uuid v4 with a bigger alphabet to have a shorter uuid
    
    Example:
    
    ```json
    "2y84q2MQUMWPbiEcxNXMgC"
    ```

Request body: multipart/form-data (required)

Type: object

- `tasks` (required)
  Reference: [VideoStudioCreateTask](https://sourcey-peertube.pages.dev/api-rest-reference/models/videostudiocreatetask.md); Type: Array<object>

- `saveAsNewVideo` (optional)
  Type: boolean
  
  Keep the source video untouched: duplicate it, and edit the duplicate. The duplicate is created private, in the same channel as the source video, with the source video metadata. The size of the source video counts towards the user quota.
  
  
  default: false

Responses:

- 200: successful operation, when `saveAsNewVideo` is `true`. Returns the identifiers of the new video

Content type: application/json

Type: VideoUploadResponse

Schema: [VideoUploadResponse](https://sourcey-peertube.pages.dev/api-rest-reference/models/videouploadresponse.md)

- `video` (optional)
  Type: object
  
  - `id` (optional)
    Reference: [id](https://sourcey-peertube.pages.dev/api-rest-reference/models/id.md); Type: id
    
    object id for the video
  
  - `uuid` (optional)
    Type: UUIDv4
    
    universal identifier for the video, that can be used across instances
    
    allOf:
      Reference: [UUIDv4](https://sourcey-peertube.pages.dev/api-rest-reference/models/uuidv4.md); Type: UUIDv4, uuid
      
      minLength: 36
      
      maxLength: 36
      
      pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
      
      Example:
      
      ```json
      "9c9de5e8-0a1e-484a-b099-e80766180a6d"
      ```
  
  - `shortUUID` (optional)
    Reference: [shortUUID](https://sourcey-peertube.pages.dev/api-rest-reference/models/shortuuid.md); Type: shortUUID

- 204: successful operation, when the source video is edited in place

- 400: incorrect parameters

- 403: the user cannot manage this video, or `saveAsNewVideo` is `true` on a blocked video and the user cannot manage blocks

- 404: video not found

- 409: video is already being processed

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/videos/42/studio/edit' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  --form-string 'tasks={"name":"cut","options":{"start":0,"end":0}}' \
  --form-string 'saveAsNewVideo=false'
```

### JavaScript

```javascript
const form = new FormData();
form.append('tasks', '{"name":"cut","options":{"start":0,"end":0}}');
form.append('saveAsNewVideo', 'false');
const response = await fetch('https://peertube2.cpy.re/api/v1/videos/42/studio/edit', {
  method: 'POST',
  headers: {"Authorization":"Bearer YOUR_TOKEN"},
  body: form,
});
console.log(await response.text());
```

### Python

```python
import requests
from contextlib import ExitStack

with ExitStack() as stack:
    files = [
        ('tasks', (None, '{"name":"cut","options":{"start":0,"end":0}}')),
        ('saveAsNewVideo', (None, 'false')),
    ]
    response = requests.request('POST', 'https://peertube2.cpy.re/api/v1/videos/42/studio/edit', headers={"Authorization":"Bearer YOUR_TOKEN"}, files=files)
    print(response.text)
```
