1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LogiOptions+でyoutube要約を自動化!

Posted at

前置き

いつもYouTubeや動画コンテンツは1.5~2倍速で見ているのですが、最近は倍速で見ていても「なげぇなぁ~」と思うことがあります。そしたらなんとchromeの拡張機能に[YouTube Summary with ChatGPT & Claude]という便利そうな拡張機能あるではないですか!
早速インストールして使ってみます。
image.png
設定画面はこんな感じでモデルを選んでカスタムプロンプトを入れると。
image.png
拡張機能を入れるとYouTubeの画面にこんなもんが。
image.png
このロボットの右のChatGPTのロゴを押すとChatGPTが勝手に開いてカスタムプロンプトと字幕が入力されるようです。

そして何度も要約を繰り返していると上限が来てしまうようです。
image.png
当然課金する気もなく、でも便利だよあぁと感じていたので最近触っていたLogiOptions+のSmart Actionsと組み合わせれば同じようなことができんじゃね?ということd、いざ実践。

本題

前提

  • windows11
  • python
  • LogiOptions+

手順

  1. まずはPythonでYouTubeの字幕を取得するためのスクリプトを書く

    from youtube_transcript_api import YouTubeTranscriptApi
    import pyperclip
    import re
    import sys
    
    def extract_video_id(url):
        pattern = r'(?:v=|\/)([0-9A-Za-z_-]{11})'  # YouTubeのビデオID抽出パターン
        match = re.search(pattern, url)
        return match.group(1) if match else None
    
    def clean_transcript(text):
        text = re.sub(r'\[.*?\]', '', text)  # [音楽]などの効果音表記を削除
        text = re.sub(r'♪+', '', text)       # 音符記号を削除
        text = re.sub(r'\s+', '', text)       # 空白文字を削除
        return text.strip()
    
    def get_video_transcript(video_id):
        transcript_list = YouTubeTranscriptApi.list_transcripts(video_id)
        
        try:
            transcript = transcript_list.find_transcript(['en', 'ja'])
            transcript_type = "手動作成"
        except:
            transcript = transcript_list.find_generated_transcript(['en', 'ja'])
            transcript_type = "自動生成"
        
        print(f"字幕言語: {transcript.language_code} ({transcript_type})")
        
        # 字幕テキストを結合
        full_text = ''.join(
            clean_transcript(tr['text'])
            for tr in transcript.fetch()
            if clean_transcript(tr['text'])
        )
        
        pyperclip.copy(full_text)
        return full_text
    
    if __name__ == "__main__":
        try:
            youtube_url = input("YouTubeのURLを入力してください: ")
            if video_id := extract_video_id(youtube_url):
                transcript = get_video_transcript(video_id)
                print("字幕テキストをクリップボードにコピーしました。")
                print("\n処理結果:")
                print(transcript)
            else:
                print("エラー: 有効なYouTube URLではありません")
                sys.exit(1)
        except Exception as e:
            print(f"エラー: 字幕を取得できませんでした - {str(e)}")
            sys.exit(1)
        except KeyboardInterrupt:
            print("\n処理を中断しました")
            sys.exit(0)
    
  2. Smart Actionsの設定
    ①Ctrl + L, Ctrl + C
    image.png
    image.png
    ㉕Ctrl + V, Enter

  3. Smart Actionsを任意のキーに設定
    4.ブラウザから要約したいYouTubeの動画を開いてボタンを押す
    すると。。。
    なんと普通にできました!
    image.png
    いやぁAI半端ないね。
    これからはまず長尺動画は要約を見てから動画を見るか決める時代だわこれ。
    ちなみに英語の動画もこんな感じで要約を出した後翻訳させるだけで日本語で読めるんでぜひお試しください!

ちなみに㉓はカスタムプロンプト、㉔はカスタムプロンプトの入力にかかる秒数なので各々カスタマイズして下さい!では!

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?