{"id":2949,"date":"2024-12-20T10:44:45","date_gmt":"2024-12-20T01:44:45","guid":{"rendered":"https:\/\/www.agile-software.site\/?p=2949"},"modified":"2024-12-22T17:06:08","modified_gmt":"2024-12-22T08:06:08","slug":"youtube-%e5%8b%95%e7%94%bb%e8%a6%81%e7%b4%84%e4%bd%9c%e6%88%90","status":"publish","type":"post","link":"https:\/\/agile-software.net\/?p=2949","title":{"rendered":"YouTube \u52d5\u753b\u8981\u7d04\u4f5c\u6210"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><strong>\u30b9\u30c6\u30c3\u30d7 1: \u5168\u4f53\u69cb\u60f3<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u76ee\u7684<\/strong>:\n<ul class=\"wp-block-list\">\n<li>YouTube \u52d5\u753b\u306e URL \u3092\u5165\u529b\u3002<\/li>\n\n\n\n<li>GAS \u3092\u4f7f\u7528\u3057\u3066\u52d5\u753b\u304b\u3089\u5b57\u5e55\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3002<\/li>\n\n\n\n<li>AI\uff08Dify\uff09\u3092\u5229\u7528\u3057\u3066\u5b57\u5e55\u30c7\u30fc\u30bf\u3092\u8981\u7d04\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u524d\u63d0\u6761\u4ef6<\/strong>:\n<ul class=\"wp-block-list\">\n<li>GAS \u3067 YouTube Data API \u3092\u6d3b\u7528\u3002<\/li>\n\n\n\n<li>YouTube \u52d5\u753b\u304c\u5b57\u5e55\u3092\u63d0\u4f9b\u3057\u3066\u3044\u308b\u3053\u3068\uff08\u81ea\u52d5\u751f\u6210\u3067\u3082\u53ef\uff09\u3002<\/li>\n\n\n\n<li>Dify \u304c AI \u30e2\u30c7\u30eb\uff08ChatGPT \u306a\u3069\uff09\u3092\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306b\u6301\u3064\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u30b9\u30c6\u30c3\u30d7 2: Google Apps Script (GAS) \u306e\u5b9f\u88c5<\/strong><\/h3>\n\n\n\n<p>GAS \u3092\u4f7f\u7528\u3057\u3066\u3001YouTube \u52d5\u753b\u304b\u3089\u5b57\u5e55\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. Google Cloud Console \u8a2d\u5b9a<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Google Cloud Console \u3067\u65b0\u3057\u3044\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3002<\/li>\n\n\n\n<li>YouTube Data API v3 \u3092\u6709\u52b9\u5316\u3002<\/li>\n\n\n\n<li>API \u30ad\u30fc\u3092\u751f\u6210\u3002<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. GAS \u30b9\u30af\u30ea\u30d7\u30c8\u306e\u4f5c\u6210<\/strong><\/h4>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3092 GAS \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u8cbc\u308a\u4ed8\u3051\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">javascript\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3059\u308b<code>function getYoutubeCaptions(videoUrl) {\n  const apiKey = \"YOUR_YOUTUBE_API_KEY\"; \/\/ \u3053\u3053\u306b\u751f\u6210\u3057\u305f API \u30ad\u30fc\u3092\u5165\u529b\n  const videoId = extractVideoId(videoUrl);\n  const captionsUrl = `https:\/\/www.googleapis.com\/youtube\/v3\/captions?videoId=${videoId}&amp;key=${apiKey}`;\n  \n  const options = {\n    method: \"get\",\n  };\n  \n  const response = UrlFetchApp.fetch(captionsUrl, options);\n  const data = JSON.parse(response.getContentText());\n  \n  if (!data.items || data.items.length === 0) {\n    return \"\u5b57\u5e55\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3002\";\n  }\n\n  const captionId = data.items[0].id; \/\/ \u6700\u521d\u306e\u5b57\u5e55 ID \u3092\u53d6\u5f97\n  const downloadUrl = `https:\/\/www.googleapis.com\/youtube\/v3\/captions\/${captionId}?tfmt=ttml&amp;key=${apiKey}`;\n\n  const captionResponse = UrlFetchApp.fetch(downloadUrl, options);\n  return captionResponse.getContentText(); \/\/ \u5b57\u5e55\u30c7\u30fc\u30bf\u3092\u8fd4\u3059\n}\n\nfunction extractVideoId(url) {\n  const regex = \/(?:https?:\\\/\\\/)?(?:www\\.)?youtube\\.com\\\/watch\\?v=([^&amp;]+)\/;\n  const match = url.match(regex);\n  return match &amp;&amp; match<img decoding=\"async\" class=\"ranking-number\" src=\"https:\/\/agile-software.net\/wp-content\/themes\/jin\/img\/rank01.png\" \/> ? match<img decoding=\"async\" class=\"ranking-number\" src=\"https:\/\/agile-software.net\/wp-content\/themes\/jin\/img\/rank01.png\" \/> : null;\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6a5f\u80fd<\/strong>:\n<ul class=\"wp-block-list\">\n<li><code>getYoutubeCaptions<\/code>: YouTube API \u3092\u547c\u3073\u51fa\u3057\u3066\u5b57\u5e55\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>extractVideoId<\/code>: YouTube \u52d5\u753b\u306e URL \u304b\u3089 Video ID \u3092\u62bd\u51fa\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. GAS \u306e\u516c\u958b<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>GAS \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u30a6\u30a7\u30d6\u30a2\u30d7\u30ea\u3068\u3057\u3066\u516c\u958b\u3002<\/li>\n\n\n\n<li>\u5b9f\u884c\u6a29\u9650\u3092\u8a2d\u5b9a\uff08\u300c\u5168\u54e1\u304c\u5b9f\u884c\u53ef\u80fd\u300d\u306b\u8a2d\u5b9a\uff09\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u30b9\u30c6\u30c3\u30d7 3: Dify \u3067\u5b57\u5e55\u30c7\u30fc\u30bf\u3092\u8981\u7d04<\/strong><\/h3>\n\n\n\n<p>\u5b57\u5e55\u30c7\u30fc\u30bf\u3092 Dify \u306b\u9001\u4fe1\u3057\u3001\u8981\u7d04\u3092\u751f\u6210\u3057\u307e\u3059\u3002<br>\u3069\u306e\u30a2\u30d7\u30ea\u3092\u9078\u629e\u3059\u308b\u306e\u304c\u30d9\u30b9\u30c8\u306a\u306e\u304b\u3001\u8ff7\u3046\u3068\u3053\u308d\u3067\u306f\u3042\u308b\u304c\u30a8\u30fc\u30b8\u30a7\u30f3\u30c8\u306f\u30b9\u30c8\u30ea\u30fc\u30df\u30f3\u30b0\u5f62\u5f0f\u306e\u307f\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u8981\u7d04\u5185\u5bb9\u3092\u307e\u3068\u3081\u3066\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. Dify \u30a8\u30fc\u30b8\u30a7\u30f3\u30c8\u306e\u8a2d\u5b9a<\/strong><\/h4>\n\n\n\n<p><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30d7\u30ed\u30f3\u30d7\u30c8\u306e\u8a2d\u5b9a<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Dify \u306e\u30a8\u30fc\u30b8\u30a7\u30f3\u30c8\u3067\u30d7\u30ed\u30f3\u30d7\u30c8\u3092\u6b21\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002css\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3059\u308b<code>\u4ee5\u4e0b\u306e\u30c6\u30ad\u30b9\u30c8\u3092\u8981\u7d04\u3057\u3066\u304f\u3060\u3055\u3044: {\u5b57\u5e55\u30c7\u30fc\u30bf}<\/code><\/li>\n\n\n\n<li><code>{\u5b57\u5e55\u30c7\u30fc\u30bf}<\/code> \u306b GAS \u304b\u3089\u53d6\u5f97\u3057\u305f\u5b57\u5e55\u3092\u633f\u5165\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>API URL \u3092\u53d6\u5f97<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Dify \u306e API URL \u3092\u30b3\u30d4\u30fc\u3057\u307e\u3059\uff08\u4f8b: <code>https:\/\/your-dify-endpoint.com\/api\/v1\/agent\/completions<\/code>\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. GAS \u304b\u3089 Dify API \u3092\u547c\u3073\u51fa\u3059<\/strong><\/h4>\n\n\n\n<p>GAS \u304b\u3089 Dify \u306e API \u306b\u5b57\u5e55\u30c7\u30fc\u30bf\u3092\u9001\u4fe1\u3057\u3001\u8981\u7d04\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092 GAS \u306b\u8ffd\u52a0:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">javascript\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3059\u308b<code>function summarizeCaptions(captions) {\n  const apiUrl = \"https:\/\/your-dify-endpoint.com\/api\/v1\/agent\/completions\"; \/\/ Dify \u306e\u30a8\u30fc\u30b8\u30a7\u30f3\u30c8 API URL\n  const apiKey = \"YOUR_DIFY_API_KEY\"; \/\/ Dify \u306e API \u30ad\u30fc\n\n  const payload = {\n    prompt: `\u4ee5\u4e0b\u306e\u30c6\u30ad\u30b9\u30c8\u3092\u8981\u7d04\u3057\u3066\u304f\u3060\u3055\u3044:\\n${captions}`,\n    max_tokens: 500,\n  };\n\n  const options = {\n    method: \"post\",\n    contentType: \"application\/json\",\n    headers: {\n      \"Authorization\": `Bearer ${apiKey}`,\n    },\n    payload: JSON.stringify(payload),\n  };\n\n  const response = UrlFetchApp.fetch(apiUrl, options);\n  const data = JSON.parse(response.getContentText());\n  return data.choices[0].text; \/\/ \u8981\u7d04\u7d50\u679c\u3092\u8fd4\u3059\n}\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. \u30e1\u30a4\u30f3\u51e6\u7406\u306e\u7d71\u5408<\/strong><\/h4>\n\n\n\n<p>\u3059\u3079\u3066\u3092\u7d71\u5408\u3057\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">javascript\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3059\u308b<code>function processYoutubeVideo(videoUrl) {\n  const captions = getYoutubeCaptions(videoUrl);\n  if (!captions || captions === \"\u5b57\u5e55\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3002\") {\n    return \"\u5b57\u5e55\u30c7\u30fc\u30bf\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002\";\n  }\n\n  const summary = summarizeCaptions(captions);\n  return summary;\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>processYoutubeVideo<\/code> \u95a2\u6570\u306b\u52d5\u753b URL \u3092\u6e21\u3059\u3068\u3001\u8981\u7d04\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u30b9\u30c6\u30c3\u30d7 4: \u52d5\u4f5c\u78ba\u8a8d<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>GAS \u306e\u5b9f\u884c<\/strong>:\n<ul class=\"wp-block-list\">\n<li><code>processYoutubeVideo(\"https:\/\/www.youtube.com\/watch?v=YOUR_VIDEO_ID\")<\/code> \u3092\u547c\u3073\u51fa\u3057\u3002<\/li>\n\n\n\n<li>\u5b57\u5e55\u30c7\u30fc\u30bf\u304c\u53d6\u5f97\u3055\u308c\u3001\u8981\u7d04\u304c Dify \u304b\u3089\u8fd4\u3055\u308c\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u30a8\u30e9\u30fc\u51e6\u7406<\/strong>:\n<ul class=\"wp-block-list\">\n<li>\u5b57\u5e55\u304c\u306a\u3044\u5834\u5408\u3084 API \u30a8\u30e9\u30fc\u306b\u5bfe\u51e6\u3059\u308b\u305f\u3081\u306e\u4f8b\u5916\u51e6\u7406\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u30b9\u30c6\u30c3\u30d7 5: \u5c06\u6765\u7684\u306a\u6539\u5584<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Dify \u30a8\u30fc\u30b8\u30a7\u30f3\u30c8\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba<\/strong>:\n<ul class=\"wp-block-list\">\n<li>\u3088\u308a\u8a73\u7d30\u306a\u8981\u7d04\u3084\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\u62bd\u51fa\u3092\u5b9f\u73fe\u3059\u308b\u305f\u3081\u3001\u30d7\u30ed\u30f3\u30d7\u30c8\u3092\u8abf\u6574\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u5b57\u5e55\u7ffb\u8a33<\/strong>:\n<ul class=\"wp-block-list\">\n<li>\u5b57\u5e55\u3092\u7ffb\u8a33\u3057\u3066\u304b\u3089\u8981\u7d04\u3059\u308b\u6a5f\u80fd\u3092\u8ffd\u52a0\uff08Google Translation API \u3092\u4f7f\u7528\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>UI \u306e\u69cb\u7bc9<\/strong>:\n<ul class=\"wp-block-list\">\n<li>\u7d50\u679c\u3092\u8868\u793a\u3059\u308b Web \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u69cb\u7bc9\uff08Google Sheets \u307e\u305f\u306f Web \u30a2\u30d7\u30ea\u3067\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u30b9\u30c6\u30c3\u30d7 1: \u5168\u4f53\u69cb\u60f3 \u30b9\u30c6\u30c3\u30d7 2: Google Apps Script (GAS) \u306e\u5b9f\u88c5 GAS \u3092\u4f7f\u7528\u3057\u3066\u3001YouTube \u52d5\u753b\u304b\u3089\u5b57\u5e55\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002 1. Google Cloud Console \u8a2d\u5b9a 2<\/p>\n","protected":false},"author":1,"featured_media":2976,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jin_ogp_image_url":"","_jin_last_featured_id":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2949","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/2949","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2949"}],"version-history":[{"count":2,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/2949\/revisions"}],"predecessor-version":[{"id":2956,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/2949\/revisions\/2956"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/media\/2976"}],"wp:attachment":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}