My agentic slop goes here. Not intended for anyone else!
at jsont 4.6 kB view raw
1open Cmdliner 2 3(** List channel videos command *) 4let list_videos env _xdg profile base_url channel limit = 5 Eio.Switch.run @@ fun sw -> 6 7 let base_url = 8 match base_url with 9 | Some url -> url 10 | None -> 11 Keyeio.Profile.get profile ~key:"base_url" 12 |> Option.value ~default:"https://peertube.example.com" 13 in 14 15 try 16 let requests_session = Requests.create ~sw env in 17 let client = Peertubee.create ~requests_session ~base_url in 18 let videos = 19 match limit with 20 | Some n -> Peertubee.fetch_all_channel_videos client ~page_size:n channel 21 | None -> Peertubee.fetch_all_channel_videos client channel 22 in 23 24 Printf.printf "Found %d videos from channel '%s'\n\n" (List.length videos) channel; 25 26 List.iteri (fun i (v : Peertubee.video) -> 27 Printf.printf "%d. %s\n" (i + 1) v.name; 28 Printf.printf " UUID: %s\n" v.uuid; 29 Printf.printf " URL: %s\n" v.url; 30 (match v.description with 31 | Some desc -> 32 let desc_short = 33 if String.length desc > 100 then String.sub desc 0 100 ^ "..." 34 else desc 35 in 36 Printf.printf " Description: %s\n" desc_short 37 | None -> ()); 38 Printf.printf " Published: %s\n" (Ptime.to_rfc3339 v.published_at); 39 (match v.tags with 40 | Some tags when tags <> [] -> 41 Printf.printf " Tags: %s\n" (String.concat ", " tags) 42 | _ -> ()); 43 Printf.printf "\n" 44 ) videos; 45 0 46 with exn -> 47 Printf.eprintf "Error: %s\n" (Printexc.to_string exn); 48 1 49 50(** Get a single video by UUID *) 51let get_video env _xdg profile base_url uuid = 52 Eio.Switch.run @@ fun sw -> 53 54 let base_url = 55 match base_url with 56 | Some url -> url 57 | None -> 58 Keyeio.Profile.get profile ~key:"base_url" 59 |> Option.value ~default:"https://peertube.example.com" 60 in 61 62 try 63 let requests_session = Requests.create ~sw env in 64 let client = Peertubee.create ~requests_session ~base_url in 65 let video = Peertubee.fetch_video_details client uuid in 66 67 Printf.printf "Video: %s\n" video.name; 68 Printf.printf "UUID: %s\n" video.uuid; 69 Printf.printf "URL: %s\n" video.url; 70 Printf.printf "Embed path: %s\n" video.embed_path; 71 (match video.description with 72 | Some desc -> Printf.printf "Description: %s\n" desc 73 | None -> ()); 74 Printf.printf "Published: %s\n" (Ptime.to_rfc3339 video.published_at); 75 (match video.originally_published_at with 76 | Some t -> Printf.printf "Originally published: %s\n" (Ptime.to_rfc3339 t) 77 | None -> ()); 78 (match video.tags with 79 | Some tags when tags <> [] -> 80 Printf.printf "Tags: %s\n" (String.concat ", " tags) 81 | _ -> ()); 82 (match Peertubee.thumbnail_url client video with 83 | Some url -> Printf.printf "Thumbnail: %s\n" url 84 | None -> ()); 85 0 86 with exn -> 87 Printf.eprintf "Error: %s\n" (Printexc.to_string exn); 88 1 89 90(** Command-line arguments *) 91 92let base_url_arg = 93 let doc = "Base URL of the PeerTube instance (overrides profile setting)" in 94 Arg.(value & opt (some string) None & info ["u"; "url"] ~docv:"URL" ~doc) 95 96let channel_arg = 97 let doc = "Channel name to fetch videos from" in 98 Arg.(required & pos 0 (some string) None & info [] ~docv:"CHANNEL" ~doc) 99 100let limit_arg = 101 let doc = "Maximum number of videos to return" in 102 Arg.(value & opt (some int) None & info ["l"; "limit"] ~docv:"N" ~doc) 103 104let uuid_arg = 105 let doc = "UUID of the video" in 106 Arg.(required & pos 0 (some string) None & info [] ~docv:"UUID" ~doc) 107 108(** Commands *) 109 110let list_cmd = 111 let doc = "List videos from a PeerTube channel" in 112 Eiocmd.run 113 ~info:(Cmd.info "list" ~doc) 114 ~app_name:"peertubee" 115 ~service:"peertube" 116 Term.(const (fun base_url channel limit env xdg profile -> 117 list_videos env xdg profile base_url channel limit) 118 $ base_url_arg $ channel_arg $ limit_arg) 119 120let get_cmd = 121 let doc = "Get a video by UUID" in 122 Eiocmd.run 123 ~info:(Cmd.info "get" ~doc) 124 ~app_name:"peertubee" 125 ~service:"peertube" 126 Term.(const (fun base_url uuid env xdg profile -> 127 get_video env xdg profile base_url uuid) 128 $ base_url_arg $ uuid_arg) 129 130(** Main command *) 131 132let main_cmd = 133 let doc = "PeerTube API client" in 134 let man = [ 135 `S Manpage.s_description; 136 `P "$(tname) is a command-line client for the PeerTube API."; 137 `P "It allows you to list and view videos from PeerTube instances."; 138 ] in 139 let info = Cmd.info "peertubee" ~version:"0.1.0" ~doc ~man in 140 Cmd.group info [list_cmd; get_cmd] 141 142let () = exit (Cmd.eval' main_cmd)