@r_masseater/masseater-utils 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/README.md +1 -1
  2. package/dist/app-name.d.mts +1 -2
  3. package/dist/browser-test/vite.d.mts +1 -2
  4. package/dist/browser-test/vite.mjs +1 -1
  5. package/dist/{browser-test-vite-DS3fTcyM.mjs → browser-test-vite-DtB8cExi.mjs} +1 -1
  6. package/dist/{browser-test-vite-DS3fTcyM.mjs.map → browser-test-vite-DtB8cExi.mjs.map} +1 -1
  7. package/dist/{button-980Op0uF.mjs → button-Cu09f5VU.mjs} +4 -4
  8. package/dist/{button-980Op0uF.mjs.map → button-Cu09f5VU.mjs.map} +1 -1
  9. package/dist/{button-variants-BLMlMm-s.mjs → button-variants-BlDbQ4DD.mjs} +1 -1
  10. package/dist/{button-variants-BLMlMm-s.mjs.map → button-variants-BlDbQ4DD.mjs.map} +1 -1
  11. package/dist/{button-variants-Bupz7GI3.d.mts → button-variants-YGBhQ_mb.d.mts} +1 -2
  12. package/dist/{client-BS-MCJ0I.mjs → client-DX2jXirb.mjs} +39 -42
  13. package/dist/client-DX2jXirb.mjs.map +1 -0
  14. package/dist/{cn-DtxpfSUK.mjs → cn-COS9Py_F.mjs} +1 -1
  15. package/dist/{cn-DtxpfSUK.mjs.map → cn-COS9Py_F.mjs.map} +1 -1
  16. package/dist/{context-B_4aJtEC.mjs → context-COCO-Ecg.mjs} +1 -1
  17. package/dist/{context-B_4aJtEC.mjs.map → context-COCO-Ecg.mjs.map} +1 -1
  18. package/dist/desktop-shell/media-notes/protocol.d.mts +1 -1
  19. package/dist/desktop-shell/media-notes/protocol.mjs +1 -1
  20. package/dist/desktop-shell/media-notes.d.mts +5 -5
  21. package/dist/desktop-shell/media-notes.mjs +7 -7
  22. package/dist/desktop-shell/media-notes.mjs.map +1 -1
  23. package/dist/desktop-shell/release-cli.mjs +2 -2
  24. package/dist/desktop-shell/telemetry.d.mts +1 -2
  25. package/dist/desktop-shell/telemetry.mjs +2 -2
  26. package/dist/desktop-shell/vite.d.mts +1 -2
  27. package/dist/desktop-shell/vite.mjs +2 -2
  28. package/dist/effect2cs.d.mts +1 -2
  29. package/dist/effect2rs.d.mts +2 -3
  30. package/dist/effect2rs.mjs +4 -4
  31. package/dist/{failure-CjeINRVu.mjs → failure-BhLz69b6.mjs} +1 -1
  32. package/dist/{failure-CjeINRVu.mjs.map → failure-BhLz69b6.mjs.map} +1 -1
  33. package/dist/github-workflow.d.mts +2 -3
  34. package/dist/github-workflow.mjs +1 -1
  35. package/dist/{headers-Cr6gAurg.mjs → headers-Bpv9DhNS.mjs} +2 -2
  36. package/dist/{headers-Cr6gAurg.mjs.map → headers-Bpv9DhNS.mjs.map} +1 -1
  37. package/dist/{headers-BK-aW9Kw.d.mts → headers-NUwRihYD.d.mts} +1 -2
  38. package/dist/{heading-class-H4Z13Bpn.mjs → heading-class-Cj0jHgsZ.mjs} +1 -1
  39. package/dist/{heading-class-H4Z13Bpn.mjs.map → heading-class-Cj0jHgsZ.mjs.map} +1 -1
  40. package/dist/{heading-class-CDq0WZpR.d.mts → heading-class-DPbs-YiQ.d.mts} +1 -2
  41. package/dist/hook-flags.d.mts +1 -2
  42. package/dist/{index-CeVmiNfF.d.mts → index-1-4t9rX2.d.mts} +2 -3
  43. package/dist/{index-KNezbJnC.d.mts → index-2z0Rr69i.d.mts} +1 -2
  44. package/dist/{index-ChbPLmqu.d.mts → index-8ZrDzBaY.d.mts} +1 -2
  45. package/dist/{index-CjUS4pmA.d.mts → index-B9MYxbAp.d.mts} +2 -3
  46. package/dist/{index-BkZOsFv4.d.mts → index-BhIR7Vrb.d.mts} +1 -2
  47. package/dist/index-Cz3K0tg_.d.mts +3 -0
  48. package/dist/index-DJGZKGut.d.mts +5 -0
  49. package/dist/{index-CLb1-l_c.d.mts → index-DeL_mxdJ.d.mts} +2 -3
  50. package/dist/index-DgofHxew.d.mts +1 -0
  51. package/dist/{index-Cb8YSEwo.d.mts → index-DmIMnqv8.d.mts} +1 -2
  52. package/dist/kestrion/node.d.mts +1 -2
  53. package/dist/kestrion/npm.d.mts +2 -3
  54. package/dist/kestrion/npm.mjs +1 -1
  55. package/dist/kestrion/pnpm.d.mts +2 -3
  56. package/dist/kestrion/pnpm.mjs +4 -4
  57. package/dist/kestrion.d.mts +1 -1
  58. package/dist/kestrion.mjs +1 -1
  59. package/dist/lapse/sdk.d.mts +1 -2
  60. package/dist/lapse.d.mts +2 -3
  61. package/dist/lapse.mjs +1 -1
  62. package/dist/local-server/node.d.mts +2 -3
  63. package/dist/local-server/node.mjs +3 -3
  64. package/dist/local-server/node.mjs.map +1 -1
  65. package/dist/local-server/serve.d.mts +1 -2
  66. package/dist/local-server.d.mts +2 -3
  67. package/dist/local-server.mjs +1 -1
  68. package/dist/mapped-import/mapper.d.mts +2 -3
  69. package/dist/mapped-import/vite.d.mts +1 -2
  70. package/dist/mapped-import/vite.mjs +1 -1
  71. package/dist/mapped-import.d.mts +1 -1
  72. package/dist/{media-protocol-CMyatw7A.mjs → media-protocol-Buk1x3Gb.mjs} +1 -1
  73. package/dist/{media-protocol-CMyatw7A.mjs.map → media-protocol-Buk1x3Gb.mjs.map} +1 -1
  74. package/dist/model-server/process.mjs +7 -7
  75. package/dist/model-server/process.mjs.map +1 -1
  76. package/dist/model-server.d.mts +423 -102
  77. package/dist/model-server.mjs +1 -1
  78. package/dist/model-server.mjs.map +1 -1
  79. package/dist/{node-main-Bwril94o.mjs → node-main-BrhzkUvP.mjs} +1 -1
  80. package/dist/{node-main-Bwril94o.mjs.map → node-main-BrhzkUvP.mjs.map} +1 -1
  81. package/dist/node-main.d.mts +2 -3
  82. package/dist/node-main.mjs +2 -2
  83. package/dist/{normalize-CogX79EO.mjs → normalize-CboffJzv.mjs} +1 -1
  84. package/dist/{normalize-CogX79EO.mjs.map → normalize-CboffJzv.mjs.map} +1 -1
  85. package/dist/{otlp-ohapzeFh.mjs → otlp-DwZqQqjc.mjs} +1 -1
  86. package/dist/{otlp-ohapzeFh.mjs.map → otlp-DwZqQqjc.mjs.map} +1 -1
  87. package/dist/{otlp-schema-CDBPGJ5s.mjs → otlp-schema-DcYNaxGn.mjs} +1 -1
  88. package/dist/{otlp-schema-CDBPGJ5s.mjs.map → otlp-schema-DcYNaxGn.mjs.map} +1 -1
  89. package/dist/{otlp-spans-D88555DO.mjs → otlp-spans-BF7m_C1W.mjs} +2 -2
  90. package/dist/{otlp-spans-D88555DO.mjs.map → otlp-spans-BF7m_C1W.mjs.map} +1 -1
  91. package/dist/{package-json-CYRyaF9U.mjs → package-json-CdnNcBLT.mjs} +1 -1
  92. package/dist/{package-json-CYRyaF9U.mjs.map → package-json-CdnNcBLT.mjs.map} +1 -1
  93. package/dist/plugin-kit.d.mts +3 -4
  94. package/dist/plugin-kit.mjs +1 -1
  95. package/dist/plugin-kit.mjs.map +1 -1
  96. package/dist/{portfolio-BQJtJtfK.mjs → portfolio-VMbxOrAS.mjs} +1 -1
  97. package/dist/{portfolio-BQJtJtfK.mjs.map → portfolio-VMbxOrAS.mjs.map} +1 -1
  98. package/dist/{process-_W_7DeKe.d.mts → process-BHJEIAWo.d.mts} +1 -2
  99. package/dist/{process-lKS6nYWh.mjs → process-l69KvwcT.mjs} +1 -1
  100. package/dist/{process-lKS6nYWh.mjs.map → process-l69KvwcT.mjs.map} +1 -1
  101. package/dist/process.d.mts +1 -1
  102. package/dist/process.mjs +1 -1
  103. package/dist/{receive-S2txZwcV.mjs → receive-o3h4RxCi.mjs} +1 -1
  104. package/dist/{receive-S2txZwcV.mjs.map → receive-o3h4RxCi.mjs.map} +1 -1
  105. package/dist/{route-handlers-Cn3O2hmf.mjs → route-handlers-CKVY2bqC.mjs} +1 -1
  106. package/dist/{route-handlers-Cn3O2hmf.mjs.map → route-handlers-CKVY2bqC.mjs.map} +1 -1
  107. package/dist/{route-handlers-E2lwhaAf.d.mts → route-handlers-DAmv3iMD.d.mts} +1 -2
  108. package/dist/{run-D59Owiv1.d.mts → run-C1nPjDih.d.mts} +1 -2
  109. package/dist/{run-Cc5W9mi8.mjs → run-DKB2KSjp.mjs} +2 -2
  110. package/dist/{run-Cc5W9mi8.mjs.map → run-DKB2KSjp.mjs.map} +1 -1
  111. package/dist/{run-main-BD4uT8sr.mjs → run-main-Chtieg-p.mjs} +7 -7
  112. package/dist/run-main-Chtieg-p.mjs.map +1 -0
  113. package/dist/security-headers/http.d.mts +2 -3
  114. package/dist/security-headers/http.mjs +1 -1
  115. package/dist/security-headers/request.d.mts +1 -2
  116. package/dist/security-headers/response.d.mts +1 -2
  117. package/dist/security-headers/response.mjs +1 -1
  118. package/dist/security-headers/static.d.mts +1 -1
  119. package/dist/security-headers/static.mjs +1 -1
  120. package/dist/security-headers/vite.d.mts +1 -1
  121. package/dist/security-headers/vite.mjs +1 -1
  122. package/dist/security-headers.d.mts +3 -3
  123. package/dist/security-headers.mjs +2 -2
  124. package/dist/skerm.d.mts +1 -2
  125. package/dist/{socket-port-CTg-qfiP.mjs → socket-port-Cq7YKLFS.mjs} +1 -1
  126. package/dist/{socket-port-CTg-qfiP.mjs.map → socket-port-Cq7YKLFS.mjs.map} +1 -1
  127. package/dist/{span-BKjRu617.mjs → span-BK0kTs11.mjs} +2 -2
  128. package/dist/{span-BKjRu617.mjs.map → span-BK0kTs11.mjs.map} +1 -1
  129. package/dist/{static-page-headers-_B0WGkew.mjs → static-page-headers-muClDOhu.mjs} +2 -2
  130. package/dist/{static-page-headers-_B0WGkew.mjs.map → static-page-headers-muClDOhu.mjs.map} +1 -1
  131. package/dist/{sync-BkyZGGDA.mjs → sync-Ctl9b02O.mjs} +1 -1
  132. package/dist/{sync-BkyZGGDA.mjs.map → sync-Ctl9b02O.mjs.map} +1 -1
  133. package/dist/{table-class-BeiCXlFj.d.mts → table-class-B6OCkS3k.d.mts} +1 -2
  134. package/dist/{table-class-RQvT6MYy.mjs → table-class-Ck9lRrm4.mjs} +1 -1
  135. package/dist/{table-class-RQvT6MYy.mjs.map → table-class-Ck9lRrm4.mjs.map} +1 -1
  136. package/dist/{telemetry-BEWIE8tU.d.mts → telemetry-D6lI0_F9.d.mts} +1 -2
  137. package/dist/ui/backdrop-palette.d.mts +1 -2
  138. package/dist/ui/badge.d.mts +1 -2
  139. package/dist/ui/badge.mjs +1 -1
  140. package/dist/ui/browser-runtime.d.mts +1 -2
  141. package/dist/ui/browser-runtime.mjs +1 -1
  142. package/dist/ui/button-variants.d.mts +1 -1
  143. package/dist/ui/button-variants.mjs +1 -1
  144. package/dist/ui/button.d.mts +3 -4
  145. package/dist/ui/button.mjs +1 -1
  146. package/dist/ui/cn.d.mts +1 -2
  147. package/dist/ui/cn.mjs +1 -1
  148. package/dist/ui/color-scheme.d.mts +1 -2
  149. package/dist/ui/heading-class.d.mts +1 -1
  150. package/dist/ui/heading-class.mjs +1 -1
  151. package/dist/ui/heading.d.mts +2 -3
  152. package/dist/ui/heading.mjs +1 -1
  153. package/dist/ui/input-class.d.mts +1 -2
  154. package/dist/ui/native-select-class.d.mts +1 -2
  155. package/dist/ui/next-page-trigger.d.mts +1 -2
  156. package/dist/ui/next-page-trigger.mjs +2 -2
  157. package/dist/ui/page-footer.d.mts +2 -3
  158. package/dist/ui/page-footer.mjs +1 -1
  159. package/dist/ui/page-header.d.mts +2 -3
  160. package/dist/ui/page-header.mjs +1 -1
  161. package/dist/ui/pointer.d.mts +1 -2
  162. package/dist/ui/portfolio.d.mts +1 -2
  163. package/dist/ui/portfolio.mjs +1 -1
  164. package/dist/ui/table-class.d.mts +1 -1
  165. package/dist/ui/table-class.mjs +1 -1
  166. package/dist/ui/table.d.mts +2 -3
  167. package/dist/ui/table.mjs +2 -2
  168. package/dist/ui/to-wavy-letters.d.mts +1 -2
  169. package/dist/ui/web-analytics.d.mts +3 -4
  170. package/dist/ui/web-analytics.mjs +1 -1
  171. package/dist/usage-meter/report.d.mts +2 -3
  172. package/dist/usage-meter/report.mjs +1 -1
  173. package/dist/{usage-meter-CmCceKx1.mjs → usage-meter-B196tKiM.mjs} +2 -2
  174. package/dist/{usage-meter-CmCceKx1.mjs.map → usage-meter-B196tKiM.mjs.map} +1 -1
  175. package/dist/usage-meter.d.mts +3 -4
  176. package/dist/usage-meter.mjs +2 -2
  177. package/dist/{usage-tally-C7zVBg75.d.mts → usage-tally-BBhBouif.d.mts} +1 -2
  178. package/dist/{usage-tally-FiAxcD-H.mjs → usage-tally-BD3f41V8.mjs} +1 -1
  179. package/dist/{usage-tally-FiAxcD-H.mjs.map → usage-tally-BD3f41V8.mjs.map} +1 -1
  180. package/dist/vitest-otlp/collector-files.d.mts +3 -4
  181. package/dist/vitest-otlp/collector-files.mjs +2 -2
  182. package/dist/vitest-otlp/semconv.d.mts +1 -2
  183. package/dist/vitest-otlp/semconv.mjs +2 -2
  184. package/dist/vitest-otlp/setup.mjs +4 -4
  185. package/dist/vitest-otlp/workers.d.mts +2 -3
  186. package/dist/vitest-otlp/workers.mjs +1 -1
  187. package/dist/{vitest-otlp-current-receiver-8c7rIP1N.mjs → vitest-otlp-current-receiver-Bh_4YbhT.mjs} +1 -1
  188. package/dist/{vitest-otlp-current-receiver-8c7rIP1N.mjs.map → vitest-otlp-current-receiver-Bh_4YbhT.mjs.map} +1 -1
  189. package/dist/{vitest-otlp-current-receiver-DphmM9Ha.d.mts → vitest-otlp-current-receiver-DSgQ3zo9.d.mts} +3 -4
  190. package/dist/vitest-otlp.d.mts +4 -5
  191. package/dist/vitest-otlp.mjs +3 -3
  192. package/dist/{web-analytics-Bz6nyJmQ.mjs → web-analytics-CondjbtC.mjs} +1 -1
  193. package/dist/{web-analytics-Bz6nyJmQ.mjs.map → web-analytics-CondjbtC.mjs.map} +1 -1
  194. package/dist/{web-analytics-BM9LdncT.d.mts → web-analytics-Cvs9PDoh.d.mts} +1 -2
  195. package/dist/workers-tracing/alchemy.d.mts +3 -4
  196. package/dist/workers-tracing/alchemy.mjs +3 -3
  197. package/dist/workers-tracing/browser-logs.d.mts +2 -3
  198. package/dist/workers-tracing/browser-logs.mjs +2 -2
  199. package/dist/workers-tracing/browser-spans.d.mts +2 -3
  200. package/dist/workers-tracing/browser-spans.mjs +2 -2
  201. package/dist/workers-tracing/effect.browser.d.mts +2 -3
  202. package/dist/workers-tracing/effect.browser.mjs +1 -1
  203. package/dist/workers-tracing/effect.d.mts +2 -3
  204. package/dist/workers-tracing/effect.mjs +3 -3
  205. package/dist/workers-tracing/elysia.d.mts +2 -3
  206. package/dist/workers-tracing/elysia.mjs +4 -4
  207. package/dist/workers-tracing/elysia.node.d.mts +1 -1
  208. package/dist/workers-tracing/elysia.node.mjs +1 -1
  209. package/dist/workers-tracing/tanstack-start.browser.d.mts +1 -2
  210. package/dist/workers-tracing/tanstack-start.d.mts +1 -2
  211. package/dist/workers-tracing/tanstack-start.mjs +3 -3
  212. package/dist/workers-tracing/trace-sink-worker.d.mts +1 -2
  213. package/dist/workers-tracing/trace-sink-worker.mjs +1 -1
  214. package/dist/workers-tracing/workers-ai.d.mts +1 -2
  215. package/dist/yohaku-protocol/sync.d.mts +1 -1
  216. package/dist/yohaku-protocol/sync.mjs +1 -1
  217. package/dist/yohaku-protocol.d.mts +1 -1
  218. package/dist/yohaku-protocol.mjs +1 -1
  219. package/native/desktop-shell/Cargo.toml +38 -0
  220. package/native/desktop-shell/src/app/builder.rs +39 -0
  221. package/native/desktop-shell/src/app/mod.rs +3 -0
  222. package/native/desktop-shell/src/entities/access_token.rs +77 -0
  223. package/native/desktop-shell/src/entities/mod.rs +1 -0
  224. package/native/desktop-shell/src/features/mod.rs +4 -0
  225. package/native/desktop-shell/src/features/record_telemetry/appender.rs +127 -0
  226. package/native/desktop-shell/src/features/record_telemetry/forwarder.rs +183 -0
  227. package/native/desktop-shell/src/features/record_telemetry/invoke.rs +80 -0
  228. package/native/desktop-shell/src/features/record_telemetry/mod.rs +231 -0
  229. package/native/desktop-shell/src/features/serve_screen/mod.rs +135 -0
  230. package/native/desktop-shell/src/features/serve_tools/mod.rs +37 -0
  231. package/native/desktop-shell/src/features/update_app/mod.rs +53 -0
  232. package/native/desktop-shell/src/lib.rs +17 -0
  233. package/native/desktop-shell/src/shared/lib/bearer.rs +49 -0
  234. package/native/desktop-shell/src/shared/lib/host.rs +1 -0
  235. package/native/desktop-shell/src/shared/lib/mod.rs +5 -0
  236. package/native/desktop-shell/src/shared/mod.rs +2 -0
  237. package/native/desktop-shell/src/shared/ui/log.rs +15 -0
  238. package/native/desktop-shell/src/shared/ui/menu.rs +37 -0
  239. package/native/desktop-shell/src/shared/ui/mod.rs +7 -0
  240. package/native/desktop-shell/src/shared/ui/window.rs +49 -0
  241. package/native/media-notes/Cargo.toml +36 -0
  242. package/native/media-notes/src/entities/media_file.rs +89 -0
  243. package/native/media-notes/src/entities/media_notes.rs +31 -0
  244. package/native/media-notes/src/entities/mod.rs +3 -0
  245. package/native/media-notes/src/entities/source/credit.rs +129 -0
  246. package/native/media-notes/src/entities/source/link.rs +194 -0
  247. package/native/media-notes/src/entities/source/mod.rs +5 -0
  248. package/native/media-notes/src/features/mod.rs +2 -0
  249. package/native/media-notes/src/features/open_media/mod.rs +88 -0
  250. package/native/media-notes/src/features/share_mcp_access.rs +15 -0
  251. package/native/media-notes/src/lib.rs +12 -0
  252. package/native/media-notes/src/shared/db/mod.rs +3 -0
  253. package/native/media-notes/src/shared/db/store.rs +276 -0
  254. package/native/media-notes/src/shared/lib/failure.rs +55 -0
  255. package/native/media-notes/src/shared/lib/mcp.rs +34 -0
  256. package/native/media-notes/src/shared/lib/mod.rs +5 -0
  257. package/native/media-notes/src/shared/mod.rs +3 -0
  258. package/native/media-notes/src/shared/protocol.rs +69 -0
  259. package/package.json +7 -3
  260. package/skills/build-tauri-app/SKILL.md +4 -2
  261. package/dist/client-BS-MCJ0I.mjs.map +0 -1
  262. package/dist/index-BtcxUsGh.d.mts +0 -4
  263. package/dist/index-CUo4CRam.d.mts +0 -1
  264. package/dist/index-DudHILTn.d.mts +0 -6
  265. package/dist/run-main-BD4uT8sr.mjs.map +0 -1
@@ -0,0 +1,129 @@
1
+ use std::sync::LazyLock;
2
+
3
+ use regex::Regex;
4
+ use serde::Deserialize;
5
+
6
+ use super::link::page_of;
7
+ use crate::shared::lib::{Failure, Outcome};
8
+ use crate::shared::protocol::{Media, Site, Source};
9
+
10
+ const YOUTUBE_OEMBED: &str = "https://www.youtube.com/oembed";
11
+ const SOUNDCLOUD_OEMBED: &str = "https://soundcloud.com/oembed";
12
+ const NICONICO_INFO: &str = "https://ext.nicovideo.jp/api/getthumbinfo/";
13
+ const NICONICO_FOUND: &str = r#"<nicovideo_thumb_response status="ok">"#;
14
+
15
+ static NICONICO_TITLE: LazyLock<Regex> =
16
+ LazyLock::new(|| Regex::new(r"<title>([^<]*)</title>").expect("valid title pattern"));
17
+ static NICONICO_ARTIST: LazyLock<Regex> = LazyLock::new(|| {
18
+ Regex::new(r"<(?:user_nickname|ch_name)>([^<]*)</").expect("valid artist pattern")
19
+ });
20
+
21
+ #[derive(Deserialize)]
22
+ struct OEmbed {
23
+ title: String,
24
+ author_name: String,
25
+ }
26
+
27
+ struct Credit {
28
+ title: String,
29
+ artist: String,
30
+ }
31
+
32
+ fn unescaped(text: &str) -> String {
33
+ text.replace("&lt;", "<")
34
+ .replace("&gt;", ">")
35
+ .replace("&quot;", "\"")
36
+ .replace("&#39;", "'")
37
+ .replace("&amp;", "&")
38
+ }
39
+
40
+ fn captured(pattern: &Regex, text: &str) -> String {
41
+ pattern
42
+ .captures(text)
43
+ .and_then(|found| found.get(1))
44
+ .map_or_else(String::new, |found| unescaped(found.as_str()))
45
+ }
46
+
47
+ fn niconico_credit(text: &str) -> Outcome<Credit> {
48
+ if !text.contains(NICONICO_FOUND) {
49
+ return Err(Failure::new("niconico has no such video"));
50
+ }
51
+ Ok(Credit {
52
+ title: captured(&NICONICO_TITLE, text),
53
+ artist: captured(&NICONICO_ARTIST, text),
54
+ })
55
+ }
56
+
57
+ async fn oembed(client: &reqwest::Client, endpoint: &str, source: &Source) -> Outcome<Credit> {
58
+ let page = page_of(source).ok_or_else(|| Failure::new("a file has no page"))?;
59
+ let found: OEmbed = client
60
+ .get(endpoint)
61
+ .query(&[("format", "json"), ("url", &page)])
62
+ .send()
63
+ .await?
64
+ .error_for_status()?
65
+ .json()
66
+ .await?;
67
+ Ok(Credit {
68
+ title: found.title,
69
+ artist: found.author_name,
70
+ })
71
+ }
72
+
73
+ async fn niconico(client: &reqwest::Client, source: &Source) -> Outcome<Credit> {
74
+ let text = client
75
+ .get(format!("{NICONICO_INFO}{}", source.id))
76
+ .send()
77
+ .await?
78
+ .error_for_status()?
79
+ .text()
80
+ .await?;
81
+ niconico_credit(&text)
82
+ }
83
+
84
+ async fn credit(client: &reqwest::Client, source: &Source) -> Outcome<Credit> {
85
+ match source.site {
86
+ Site::Youtube => oembed(client, YOUTUBE_OEMBED, source).await,
87
+ Site::Soundcloud => oembed(client, SOUNDCLOUD_OEMBED, source).await,
88
+ Site::Niconico => niconico(client, source).await,
89
+ Site::File => Err(Failure::new("a file has no credit online")),
90
+ }
91
+ }
92
+
93
+ pub async fn media_of(client: &reqwest::Client, source: Source) -> Media {
94
+ match credit(client, &source).await {
95
+ Ok(Credit { title, artist }) => Media {
96
+ source,
97
+ title,
98
+ artist,
99
+ },
100
+ Err(failure) => {
101
+ eprintln!("credit lookup failed: {failure}");
102
+ Media {
103
+ title: source.id.clone(),
104
+ source,
105
+ artist: String::new(),
106
+ }
107
+ }
108
+ }
109
+ }
110
+
111
+ #[cfg(test)]
112
+ mod tests {
113
+ use super::niconico_credit;
114
+
115
+ #[test]
116
+ fn reads_niconico_credits() {
117
+ let credit = niconico_credit(
118
+ r#"<nicovideo_thumb_response status="ok"><thumb><title>Tom &amp; Jerry&#39;s</title><user_nickname>作者</user_nickname></thumb>"#,
119
+ )
120
+ .expect("credit");
121
+ assert_eq!(credit.title, "Tom & Jerry's");
122
+ assert_eq!(credit.artist, "作者");
123
+ }
124
+
125
+ #[test]
126
+ fn refuses_pages_that_are_not_thumb_info() {
127
+ assert!(niconico_credit("<html><title>ニコニコ動画</title></html>").is_err());
128
+ }
129
+ }
@@ -0,0 +1,194 @@
1
+ use std::sync::LazyLock;
2
+
3
+ use regex::Regex;
4
+ use url::Url;
5
+
6
+ use crate::shared::protocol::{Site, Source};
7
+
8
+ const SECONDS_PER_MINUTE: u64 = 60;
9
+ const NESTED_YOUTUBE: [&str; 3] = ["shorts", "live", "embed"];
10
+ const HOST_PREFIXES: [&str; 4] = ["www.", "m.", "music.", "sp."];
11
+
12
+ static YOUTUBE_ID: LazyLock<Regex> =
13
+ LazyLock::new(|| Regex::new(r"^[\w-]{11}$").expect("valid YouTube id pattern"));
14
+ static NICONICO_ID: LazyLock<Regex> =
15
+ LazyLock::new(|| Regex::new(r"^(?:sm|so|nm)\d+$").expect("valid niconico id pattern"));
16
+
17
+ fn accepted(site: Site, id: Option<&str>, pattern: &Regex) -> Option<Source> {
18
+ id.filter(|value| pattern.is_match(value))
19
+ .map(|value| Source {
20
+ site,
21
+ id: value.to_owned(),
22
+ })
23
+ }
24
+
25
+ fn youtube_id<'a>(parts: &[&'a str], video: Option<&'a str>) -> Option<&'a str> {
26
+ match parts.first() {
27
+ Some(&"watch") => video,
28
+ Some(first) if NESTED_YOUTUBE.contains(first) => parts.get(1).copied(),
29
+ _ => None,
30
+ }
31
+ }
32
+
33
+ fn bare_host(host: &str) -> &str {
34
+ HOST_PREFIXES
35
+ .iter()
36
+ .find_map(|prefix| host.strip_prefix(prefix))
37
+ .unwrap_or(host)
38
+ }
39
+
40
+ #[must_use]
41
+ pub fn source_of(text: &str) -> Option<Source> {
42
+ let url = Url::parse(text.trim()).ok()?;
43
+ let host = bare_host(url.host_str()?);
44
+ let parts: Vec<&str> = url.path_segments().map_or_else(Vec::new, |segments| {
45
+ segments.filter(|part| !part.is_empty()).collect()
46
+ });
47
+ let video = url
48
+ .query_pairs()
49
+ .find(|(key, _)| key == "v")
50
+ .map(|(_, value)| value.into_owned());
51
+ match host {
52
+ "youtube.com" => accepted(
53
+ Site::Youtube,
54
+ youtube_id(&parts, video.as_deref()),
55
+ &YOUTUBE_ID,
56
+ ),
57
+ "youtu.be" => accepted(Site::Youtube, parts.first().copied(), &YOUTUBE_ID),
58
+ "nicovideo.jp" => accepted(Site::Niconico, parts.get(1).copied(), &NICONICO_ID),
59
+ "nico.ms" => accepted(Site::Niconico, parts.first().copied(), &NICONICO_ID),
60
+ "soundcloud.com" if parts.len() == 2 => Some(Source {
61
+ site: Site::Soundcloud,
62
+ id: parts.join("/"),
63
+ }),
64
+ _ => None,
65
+ }
66
+ }
67
+
68
+ #[must_use]
69
+ pub fn page_of(source: &Source) -> Option<String> {
70
+ match source.site {
71
+ Site::Youtube => Some(format!("https://www.youtube.com/watch?v={}", source.id)),
72
+ Site::Niconico => Some(format!("https://www.nicovideo.jp/watch/{}", source.id)),
73
+ Site::Soundcloud => Some(format!("https://soundcloud.com/{}", source.id)),
74
+ Site::File => None,
75
+ }
76
+ }
77
+
78
+ #[expect(
79
+ clippy::cast_possible_truncation,
80
+ clippy::cast_sign_loss,
81
+ reason = "only finite positive seconds reach the cast"
82
+ )]
83
+ fn whole(seconds: f64) -> u64 {
84
+ if seconds.is_finite() && seconds > 0.0 {
85
+ seconds.floor() as u64
86
+ } else {
87
+ 0
88
+ }
89
+ }
90
+
91
+ #[must_use]
92
+ pub fn clock(seconds: f64) -> String {
93
+ let total = whole(seconds);
94
+ format!(
95
+ "{}:{:02}",
96
+ total / SECONDS_PER_MINUTE,
97
+ total % SECONDS_PER_MINUTE
98
+ )
99
+ }
100
+
101
+ #[must_use]
102
+ pub fn range(from: f64, to: f64) -> String {
103
+ format!("{}–{}", clock(from), clock(to))
104
+ }
105
+
106
+ #[must_use]
107
+ pub fn link_at(source: &Source, seconds: f64) -> Option<String> {
108
+ match source.site {
109
+ Site::Youtube => Some(format!(
110
+ "https://youtu.be/{}?t={}",
111
+ source.id,
112
+ whole(seconds)
113
+ )),
114
+ Site::Niconico => Some(format!(
115
+ "https://www.nicovideo.jp/watch/{}?from={}",
116
+ source.id,
117
+ whole(seconds)
118
+ )),
119
+ Site::Soundcloud => Some(format!(
120
+ "https://soundcloud.com/{}#t={}",
121
+ source.id,
122
+ clock(seconds)
123
+ )),
124
+ Site::File => None,
125
+ }
126
+ }
127
+
128
+ #[cfg(test)]
129
+ mod tests {
130
+ use super::{clock, link_at, page_of, range, source_of};
131
+ use crate::shared::protocol::{Site, Source};
132
+
133
+ fn source(site: Site, id: &str) -> Source {
134
+ Source {
135
+ site,
136
+ id: id.to_owned(),
137
+ }
138
+ }
139
+
140
+ #[test]
141
+ fn reads_every_site_link() {
142
+ let youtube = Some(source(Site::Youtube, "dQw4w9WgXcQ"));
143
+ assert_eq!(
144
+ source_of("https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=3"),
145
+ youtube
146
+ );
147
+ assert_eq!(source_of("https://youtu.be/dQw4w9WgXcQ"), youtube);
148
+ assert_eq!(
149
+ source_of("https://m.youtube.com/shorts/dQw4w9WgXcQ"),
150
+ youtube
151
+ );
152
+ assert_eq!(
153
+ source_of("https://music.youtube.com/watch?v=dQw4w9WgXcQ"),
154
+ youtube
155
+ );
156
+ let niconico = Some(source(Site::Niconico, "sm9"));
157
+ assert_eq!(source_of("https://www.nicovideo.jp/watch/sm9"), niconico);
158
+ assert_eq!(source_of("https://sp.nicovideo.jp/watch/sm9"), niconico);
159
+ assert_eq!(source_of("https://nico.ms/sm9"), niconico);
160
+ assert_eq!(
161
+ source_of(" https://soundcloud.com/artist/track "),
162
+ Some(source(Site::Soundcloud, "artist/track"))
163
+ );
164
+ }
165
+
166
+ #[test]
167
+ fn refuses_links_that_are_not_media() {
168
+ assert_eq!(source_of("https://www.youtube.com/@channel"), None);
169
+ assert_eq!(source_of("https://soundcloud.com/artist"), None);
170
+ assert_eq!(source_of("https://example.com/watch?v=dQw4w9WgXcQ"), None);
171
+ assert_eq!(source_of("https://www.youtube.com/watch?v=short"), None);
172
+ assert_eq!(source_of("https://www.nicovideo.jp/watch/lv123"), None);
173
+ assert_eq!(source_of("not a link"), None);
174
+ }
175
+
176
+ #[test]
177
+ fn links_to_the_moment() {
178
+ let song = source(Site::Soundcloud, "artist/track");
179
+ assert_eq!(clock(83.9), "1:23");
180
+ assert_eq!(clock(-4.0), "0:00");
181
+ assert_eq!(range(61.5, 75.0), "1:01–1:15");
182
+ assert_eq!(
183
+ link_at(&song, 83.9).as_deref(),
184
+ Some("https://soundcloud.com/artist/track#t=1:23")
185
+ );
186
+ }
187
+
188
+ #[test]
189
+ fn files_have_no_page() {
190
+ let file = source(Site::File, "abc");
191
+ assert_eq!(page_of(&file), None);
192
+ assert_eq!(link_at(&file, 3.0), None);
193
+ }
194
+ }
@@ -0,0 +1,5 @@
1
+ mod credit;
2
+ mod link;
3
+
4
+ pub use credit::media_of;
5
+ pub use link::{clock, link_at, page_of, range, source_of};
@@ -0,0 +1,2 @@
1
+ pub mod open_media;
2
+ pub mod share_mcp_access;
@@ -0,0 +1,88 @@
1
+ use std::path::{Path, PathBuf};
2
+
3
+ use tauri::{AppHandle, Manager, State, async_runtime};
4
+ use tauri_plugin_dialog::DialogExt;
5
+
6
+ use crate::entities::media_file::opened_file;
7
+ use crate::entities::media_notes::MediaNotes;
8
+ use crate::entities::source::{media_of, source_of};
9
+ use crate::shared::lib::{Failure, Outcome};
10
+ use crate::shared::protocol::{Opened, Site};
11
+
12
+ const NOT_MEDIA: &str = "開けるリンクではありません";
13
+ const NO_FILES: &str = "このアプリはファイルを開けません";
14
+ const MISSING_FILE: &str = "ファイルが見つかりません";
15
+ const MEDIA_FILES: &str = "動画と音声";
16
+ const MEDIA_EXTENSIONS: [&str; 11] = [
17
+ "mp4", "m4v", "mov", "webm", "mkv", "mp3", "m4a", "aac", "wav", "flac", "ogg",
18
+ ];
19
+
20
+ type Answer<T> = Result<T, Failure>;
21
+
22
+ #[tauri::command]
23
+ #[specta::specta]
24
+ pub async fn open_link(notes: State<'_, MediaNotes>, link: String) -> Answer<Opened> {
25
+ let source = source_of(&link)
26
+ .filter(|source| notes.sites.contains(&source.site))
27
+ .ok_or_else(|| Failure::new(NOT_MEDIA))?;
28
+ Ok(Opened {
29
+ media: media_of(&notes.client, source).await,
30
+ location: link.trim().to_owned(),
31
+ })
32
+ }
33
+
34
+ fn readable(path: &Path) -> Outcome<()> {
35
+ if path.is_file() {
36
+ Ok(())
37
+ } else {
38
+ Err(Failure::new(MISSING_FILE))
39
+ }
40
+ }
41
+
42
+ fn failed(failure: impl std::fmt::Display) -> Failure {
43
+ Failure::new(failure.to_string())
44
+ }
45
+
46
+ async fn opened_at(app: &AppHandle, sites: &[Site], path: PathBuf) -> Outcome<Opened> {
47
+ if !sites.contains(&Site::File) {
48
+ return Err(Failure::new(NO_FILES));
49
+ }
50
+ readable(&path)?;
51
+ let opened = async_runtime::spawn_blocking(move || opened_file(&path))
52
+ .await
53
+ .map_err(failed)??;
54
+ app.asset_protocol_scope()
55
+ .allow_file(&opened.location)
56
+ .map_err(failed)?;
57
+ Ok(opened)
58
+ }
59
+
60
+ #[tauri::command]
61
+ #[specta::specta]
62
+ pub async fn open_file(
63
+ app: AppHandle,
64
+ notes: State<'_, MediaNotes>,
65
+ path: String,
66
+ ) -> Answer<Opened> {
67
+ opened_at(&app, notes.sites, PathBuf::from(path)).await
68
+ }
69
+
70
+ #[tauri::command]
71
+ #[specta::specta]
72
+ pub async fn choose_file(app: AppHandle, notes: State<'_, MediaNotes>) -> Answer<Option<Opened>> {
73
+ let asking = app.clone();
74
+ let chosen = async_runtime::spawn_blocking(move || {
75
+ asking
76
+ .dialog()
77
+ .file()
78
+ .add_filter(MEDIA_FILES, &MEDIA_EXTENSIONS)
79
+ .blocking_pick_file()
80
+ })
81
+ .await
82
+ .map_err(failed)?;
83
+ let Some(chosen) = chosen else {
84
+ return Ok(None);
85
+ };
86
+ let path = chosen.into_path().map_err(failed)?;
87
+ Ok(Some(opened_at(&app, notes.sites, path).await?))
88
+ }
@@ -0,0 +1,15 @@
1
+ use tauri::State;
2
+
3
+ use crate::entities::media_notes::MediaNotes;
4
+ use crate::shared::lib::Failure;
5
+ use crate::shared::protocol::McpAccess;
6
+
7
+ #[tauri::command]
8
+ #[specta::specta]
9
+ #[expect(
10
+ clippy::needless_pass_by_value,
11
+ reason = "Tauri hands managed state to commands by value"
12
+ )]
13
+ pub fn mcp_access(notes: State<'_, MediaNotes>) -> Result<McpAccess, Failure> {
14
+ Ok(notes.mcp.clone())
15
+ }
@@ -0,0 +1,12 @@
1
+ mod entities;
2
+ mod features;
3
+ mod shared;
4
+
5
+ pub use entities::media_file::{digest, opened_file};
6
+ pub use entities::media_notes::{MediaNotes, Setting, media_notes};
7
+ pub use entities::source::{clock, link_at, media_of, page_of, range, source_of};
8
+ pub use features::open_media::{choose_file, open_file, open_link};
9
+ pub use features::share_mcp_access::mcp_access;
10
+ pub use shared::db::{Row, Store, fresh_id, is_id, now};
11
+ pub use shared::lib::{Failure, Outcome, answer};
12
+ pub use shared::protocol::{McpAccess, Media, Opened, Saved, Site, Source};
@@ -0,0 +1,3 @@
1
+ mod store;
2
+
3
+ pub use store::{Row, Store, fresh_id, is_id, now};