Module Bushel_sync.Peertube

Video metadata and thumbnails from PeerTube

PeerTube API client for video metadata and thumbnails

val src : Logs.src
module Log : Logs.LOG

Types

type video = {
  1. id : int;
  2. uuid : string;
  3. name : string;
  4. description : string option;
  5. url : string;
  6. embed_path : string;
  7. published_at : Ptime.t;
  8. originally_published_at : Ptime.t option;
  9. thumbnail_path : string option;
  10. tags : string list;
}

Simplified video type used in bushel - projects relevant fields from PeerTube API

type fetch_result =
  1. | Ok of string
  2. | Skipped of string
  3. | Error of string

Conversion from Generated Types

module PT = Peer_tube
val int_of_json : Jsont.json -> int

Extract int from Jsont.json

val string_of_json : Jsont.json -> string

Extract string from Jsont.json

val video_of_peertube : PT.Video.T.t -> video

Convert from generated Peertube.Video.T.t to our simplified video type

type channel_response = {
  1. total : int;
  2. data : video list;
}

JSON decoding using generated library

val decode_video : string -> (video, string) Result.t
val decode_channel_response : string -> (channel_response, string) Result.t

URL Parsing

val uuid_of_url : string -> string option

Extract UUID from a PeerTube video URL. Handles formats like:

  • https://example.com/w/UUID
  • https://example.com/videos/watch/UUID
val origin_of_url : string -> string option

Extract the origin (scheme + host) from a URL

val find_server_for_url : Bushel_config.peertube_server list -> string -> Bushel_config.peertube_server option

Find a configured server that matches the URL's origin

PeerTube API

val fetch_video_details : http:Requests.t -> endpoint:string -> string -> (video, string) Result.t
val fetch_channel_videos : http:Requests.t -> endpoint:string -> channel:string -> ?count:int -> ?start:int -> unit -> int * video list
val fetch_all_channel_videos : http:Requests.t -> endpoint:string -> channel:string -> ?page_size:int -> unit -> video list

Thumbnail Download

val thumbnail_url : string -> video -> string option
val download_thumbnail : http:Requests.t -> endpoint:string -> video -> string -> fetch_result

Videos Index (YAML)

module VideoIndex : sig ... end

Fetch Thumbnails

val try_fetch_from_server : http:Requests.t -> endpoint:string -> output_path:string -> string -> fetch_result option

Try to fetch a video from a specific server

val try_all_servers : http:Requests.t -> servers:Bushel_config.peertube_server list -> output_path:string -> string -> (Bushel_config.peertube_server * fetch_result) option

Try each server until one succeeds, return the server that worked

val fetch_thumbnails : http:Requests.t -> servers:Bushel_config.peertube_server list -> output_dir:string -> videos:Bushel.Video.t list -> index:(string, string) Hashtbl.t -> (string * fetch_result) list

Fetch thumbnails for videos, using URL field, index, or server discovery. Updates the index when servers are discovered.

val fetch_thumbnails_from_index : http:Requests.t -> servers:Bushel_config.peertube_server list -> output_dir:string -> (string, string) Hashtbl.t -> (string * fetch_result) list

Legacy function for compatibility - calls fetch_thumbnails with empty video list