aboutsummaryrefslogtreecommitdiff
path: root/doc/api.md
blob: 67809cb8ffde47aa208b1c049229bcdb598b1f8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Jellything Rust API

For making your own applications that implement client functionality, use the
`jellyclient` crate. The `jellycommon` crate exposes commonly used structs like
those used in the library and for jhls.

## Generated Documentation

- [jellything](/doc/jellything/)
- [jellycommon](/doc/jellycommon/)
- [jellyremuxer](/doc/jellyremuxer/)
- [jellytranscode](/doc/jellytranscode/)
- [jellyimport](/doc/jellyimport/)
- [jellymatroska](/doc/jellymatroska/)
  - [ebml_derive](/doc/ebml_derive/)
- [jellybase](/doc/jellybase/)
- [jellystream](/doc/jellystream/)
- [jellytool](/doc/jellytool/)

# Jellything HTTP API

Most endpoints require the `Accept` header to be present and set to
`application/json` and `image/avif` respectively. Any endpoint returning JSON,
will report errors with an object containing error string in the `error` key.
Routes marked with `*` require authentification.

The `jellyclient` crate already implements most API functionality. The
`jellycommon` crate provides useful structs for deserializing data (also
reexported in jellyclient).

```toml
# Cargo.toml
[depedencies]
jellyclient = { git = "https://codeberg.org/metamuffin/jellything.git" }
```

## General

### GET `/api/version`

Returns API version number.

### POST `/api/create_session`

Request body contains JSON with keys `username`, `password`, `expire` (in
seconds) and `drop_permissions` (a list of permissions, that this session cannot
use). The Response contains the session cookie as a string in JSON.

### GET* `/n/<id>?<parents>&<children>&<filter..>`

Request a library node with userdata attached. If `parents` or `children` flag
is set, all parents/children will be returned too, otherwise those lists are
empty. Returns `ApiNodeResponse`.

### GET* `/n/<id>/userdata`

Returns only `NodeUserData` for that node.

### GET* `/search?<query>&<page>`

Returns `ApiSearchResponse`.

### GET* `/items?<filter..>&<page>`

Returns `ApiItemsResponse`.

### GET* `/home`

Returns `ApiHomeResponse`.

## Assets

Endpoints like `.../poster` redirect to the asset that you need and
automatically choose fallbacks. Alternatively you can directly request assets
with `/asset/<token>`, but there you need to implement the fallback behaviour
yourself. Returned images are coded with AVIF. The `width` parameter is the
width of the resolution you want to image to be.

> [!WARNING] The actual returned resolution must not be exactly what you
> requested. Currently it is rounded up to the next power of two.

### GET* `/asset/<token>?<width>`

This is the final asset endpoint where images are returned from. Other endpoints
redirect here. The `token` part is an opaque string that you obtain from
somewhere else like a redirect or from within the `Node` struct.

### GET* `/n/<id>/poster?<width>`

### GET* `/n/<id>/backdrop?<width>`

### GET* `/n/<id>/thumbnail?<t>&<width>`

Returns a single frame from some track video of the media at a given time `t`.

### GET* `/n/<id>/person/<index>/asset?<group>&<width>`

Returns headshot of a person from that node.

## Stream

### GET* `/n/<id>/stream?<params..>`

Responds with the stream directly or a redirect to the actual source in case of
federation.

- `?whep&<track...>&<seek>`
  - WHEP Endpoint for streaming that set of tracks. The format used is decided
    by the server.
- `?whepcontrol&<token>`
  - WebSocket endpoint for controlling WHEP playback. TODO schema
- `?remux&<track...>&<container>`
- `?hlssupermultivariant&<container>`
  - Returns m3u8/HLS playlist of all known multi-variant playlists, one for each
    segment. The plylist is updated for live media.
- `?hlsmultivariant&<segment>&<container>`
  - Returns m3u8/HLS playlist of all track formats' variant playlists.
- `?hlsvariant&<segment>&<track>&<container>&<format>`
  - Returns m3u8/HLS playlist of all known fragments of this track format. The
    playlist is updated for live media.
- `?info`
  - Returns JSON `StreamInfo`.
- `?fragmentindex&<segment>&<track>`
  - Returns time ranges for every fragment of this track.
- `?fragment&<segment>&<track>&<index>&<container>&<format>`

```ts
export type FragmentIndex = TimeRange[];
export interface TimeRange {
  start: number;
  end: number;
}
export interface SubtitleCue extends TimeRange {
  content: string;
}
export interface StreamInfo {
  name?: string;
  segments: SegmentInfo[];
}
export interface SegmentInfo {
  name?: string;
  duration: number;
  tracks: TrackInfo[];
}
export type TrackKind = "video" | "audio" | "subtitles";
export interface TrackInfo {
  name?: string;
  language?: string;
  kind: TrackKind;
  formats: FormatInfo[];
}
export type StreamContainer = "webm" | "matroska" | "mpeg4" | "jvtt" | "webvtt";
export interface FormatInfo {
  codec: string;
  bitrate: number;
  remux: boolean;
  containers: StreamContainer[];

  width?: number;
  height?: number;
  channels?: number;
  samplerate?: number;
  bit_depth?: number;
}
```