{"id":463330,"date":"2025-06-13T15:01:20","date_gmt":"2025-06-13T15:01:20","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=463330"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=463330","title":{"rendered":"<span>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430: \u043a\u0430\u043a \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u0443\u043c\u043d\u043e\u0433\u043e Tg-\u0431\u043e\u0442\u0430 \u0434\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0432\u0438\u0434\u0435\u043e \u0438\u0437 VK (\u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0434\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f, NutsDB, yt-dlp)<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/655\/d83\/ddb\/655d83ddb9f0c7d4376a82c72248eec6.png\" alt=\"\u041c\u0430\u0441\u043a\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0441\u0442\u0430\u043b\u0430 \u0443\u0436\u0435 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u0435\u0439\" title=\"\u041c\u0430\u0441\u043a\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0441\u0442\u0430\u043b\u0430 \u0443\u0436\u0435 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u0435\u0439\" width=\"1024\" height=\"1024\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/655\/d83\/ddb\/655d83ddb9f0c7d4376a82c72248eec6.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/655\/d83\/ddb\/655d83ddb9f0c7d4376a82c72248eec6.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041c\u0430\u0441\u043a\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0441\u0442\u0430\u043b\u0430 \u0443\u0436\u0435 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u0435\u0439<\/figcaption><\/div>\n<\/figure>\n<p>\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435, \u043a\u043e\u043b\u043b\u0435\u0433\u0438!<\/p>\n<p>\u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043e\u043f\u044b\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 production-ready Telegram-\u0431\u043e\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0441\u0432\u0435\u0436\u0438\u0439 \u0432\u0438\u0434\u0435\u043e\u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0438\u0437 \u043f\u0430\u0431\u043b\u0438\u043a\u0430 \u0412\u041a\u043e\u043d\u0442\u0430\u043a\u0442\u0435 \u2014 \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u0442\u043e <em>\u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0435\u0439, \u0441 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0435\u0439 \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438 \u0438 \u043c\u0435\u043c\u043d\u044b\u043c\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u044f\u043c\u0438 \u043d\u0430 \u0431\u0430\u0437\u0435 OpenAI<\/em>. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443, \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0444\u0438\u0448\u043a\u0430\u0445, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u0432\u0438\u0434\u0435\u043e (NutsDB), \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c (deduplication), \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 yt-dlp \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 OpenAI \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0439.<\/p>\n<blockquote>\n<p><strong>\u041a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u2014 <\/strong><a href=\"https:\/\/github.com\/digkill\/posterAndGrabberBot\" rel=\"noopener noreferrer nofollow\"><strong>github.com\/digkill\/posterAndGrabberBot<\/strong><\/a><\/p>\n<\/blockquote>\n<h3>TL;DR<\/h3>\n<ul>\n<li>\n<p><strong>Go<\/strong><\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u0441\u0442\u044b VK, \u0438\u0449\u0435\u043c \u0432\u0438\u0434\u0435\u043e, \u043a\u043b\u0430\u0434\u0451\u043c URL \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c (NutsDB) \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u0432\u0438\u0434\u0435\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u0440\u0430\u043d\u0435\u0435<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u0438\u0434\u0435\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/yt-dlp\/yt-dlp\" rel=\"noopener noreferrer nofollow\">yt-dlp<\/a><\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u0430\u044f (deduplication)<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\/\u0432\u0438\u0434\u0435\u043e \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e\u0442\u0441\u044f \u0432 Telegram \u0441 \u043f\u043e\u0434\u043f\u0438\u0441\u044c\u044e \u043e\u0442 OpenAI<\/p>\n<\/li>\n<\/ul>\n<h3>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0431\u0449\u0443\u044e \u0441\u0445\u0435\u043c\u0443:<\/p>\n<pre><code class=\"go\">VK API --&gt; Fetcher (\u0438\u0449\u0435\u0442 \u0432\u0438\u0434\u0435\u043e) --&gt; NutsDB (pending queue)    |                                      |    |------------------------------------&gt; goroutine (yt-dlp downloader)    |                                          |    |                                 (media directory)    |                                          |    |--&gt; Poster (OpenAI captions) ------------&gt; Telegram API<\/code><\/pre>\n<ul>\n<li>\n<p><strong>Fetcher:<\/strong> \u041f\u0430\u0440\u0441\u0438\u0442 \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0441\u0442\u044b \u0412\u041a, \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0432\u0438\u0434\u0435\u043e, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u2014 \u0431\u044b\u043b\u043e \u043b\u0438 \u0441\u043a\u0430\u0447\u0430\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p><strong>NutsDB:<\/strong> \u041b\u0451\u0433\u043a\u0430\u044f embedded-\u0431\u0430\u0437\u0430 \u0434\u043b\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u0438 URL \u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f processed-\u043c\u0430\u0440\u043a\u0435\u0440\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u0438\u0434\u0435\u043e-\u0432\u043e\u0440\u043a\u0435\u0440:<\/strong> \u041f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0435 \u0432\u0438\u0434\u0435\u043e yt-dlp, \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044f \u0434\u0443\u0431\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>Poster:<\/strong> \u041f\u043e\u0441\u0442\u0438\u0442 \u0444\u043e\u0442\u043e\/\u0432\u0438\u0434\u0435\u043e \u0432 Telegram-\u043a\u0430\u043d\u0430\u043b \u0441 \u043f\u043e\u0434\u043f\u0438\u0441\u044c\u044e \u0447\u0435\u0440\u0435\u0437 OpenAI.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041a\u043e\u043d\u0444\u0438\u0433 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a<\/h3>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"yaml\">telegram_bot_token     = \"\u0432\u0430\u0448_\u0442\u043e\u043a\u0435\u043d_\u0431\u043e\u0442\u0430\" telegram_channel_id    = \"\u0432\u0430\u0448_\u0438\u0434_\u043a\u0430\u043d\u0430\u043b\u0430_\u0434\u043b\u044f_\u043f\u043e\u0441\u0442\u043e\u0432\" vk_token               = \"\u0432\u0430\u0448_VK_API_\u0442\u043e\u043a\u0435\u043d\" fetch_interval         = \"10m\" notification_interval  = \"1m\" openai_key             = \"sk-...\" openai_model           = \"gpt-4o\" openai_prompt          = \"Make a meme caption for the image\" images_directory       = \".\/media\"<\/code><\/pre>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439:<\/p>\n<pre><code class=\"bash\">go mod tidy<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a:<\/p>\n<pre><code class=\"bash\">go run .\/cmd\/posterAndGrabberBot\/main.go<\/code><\/pre>\n<h3>\u041c\u043e\u0434\u0443\u043b\u044c\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430<\/h3>\n<h4>1. Fetcher: \u0441\u0431\u043e\u0440 \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u0441\u0442\u043e\u0432<\/h4>\n<p>Fetcher \u2014 \u0432\u043e\u0440\u043a\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 VK API, \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0441\u0442\u044b, \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 url \u0432\u0438\u0434\u0435\u043e \u0438 \u043a\u043b\u0430\u0434\u0451\u0442 \u0438\u0445 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 URL.<\/p>\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442:<\/strong><\/p>\n<pre><code class=\"go\">func (f *Fetcher) Fetch(ctx context.Context) error {     ...     for _, attach := range post.Attachments {         if attach.Type == \"video\" &amp;&amp; attach.Video != nil {             videoUrl := fmt.Sprintf(\"https:\/\/vk.com\/video%d_%d\", attach.Video.OwnerID, attach.Video.ID)             \/\/ \u0414\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f: \u043a\u043b\u0430\u0434\u0451\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u043a\u0430\u0447\u0430\u043d\u043e             if !nutsdb.IsVideoURLProcessed(videoUrl) {                 nutsdb.SaveVideoLink(videoUrl)             }         }     }     ... } <\/code><\/pre>\n<h4>2. NutsDB: \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/h4>\n<p>NutsDB \u2014 \u0431\u044b\u0441\u0442\u0440\u0430\u044f embedded key-value \u0431\u0430\u0437\u0430.<br \/> \u041c\u044b \u0445\u0440\u0430\u043d\u0438\u043c:<\/p>\n<ul>\n<li>\n<p>pending (list): url-\u044b \u0434\u043b\u044f \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>processed (set \u043f\u043e url): \u0445\u044d\u0448\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 url<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438 \u043f\u043e\u043c\u0435\u0442\u043a\u0430:<\/strong><\/p>\n<pre><code class=\"go\">import (     \"crypto\/md5\"     \"encoding\/hex\" )  func urlKey(url string) []byte {     h := md5.Sum([]byte(url))     return []byte(\"processed_\" + hex.EncodeToString(h[:])) }  func (n *NutsDB) IsVideoURLProcessed(url string) bool {     found := false     n.db.View(func(tx *nutsdb.Tx) error {         ds := nutsdb.DataStructureBPTree         bucket := \"videos\"         key := urlKey(url)         if tx.Has(bucket, key) == nil {             found = true         }         return nil     })     return found }  func (n *NutsDB) MarkVideoURLProcessed(url string) error {     return n.db.Update(func(tx *nutsdb.Tx) error {         ds := nutsdb.DataStructureBPTree         bucket := \"videos\"         key := urlKey(url)         return tx.Put(bucket, key, []byte{1})     }) } <\/code><\/pre>\n<h4>3. \u0413\u043e\u0440\u0443\u0442\u0438\u043d\u0430-\u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0442\u0435\u043b\u044c \u0447\u0435\u0440\u0435\u0437 yt-dlp<\/h4>\n<p>\u0412 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u043c\u044b \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0441\u0442\u0430\u0451\u043c URL \u0438\u0437 pending, \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0432\u0438\u0434\u0435\u043e \u0438 \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u043c url \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439.<\/p>\n<pre><code class=\"go\">func StartVideoDownloader(ctx context.Context, n *NutsDB) {     ticker := time.NewTicker(1 * time.Minute)     defer ticker.Stop()     for {         select {         case &lt;-ctx.Done():             return         case &lt;-ticker.C:             links, _ := n.GetAllPendingVideoLinks()             for _, url := range links {                 if err := DownloadVKVideo(url); err == nil {                     n.MarkVideoURLProcessed(url)                     n.RemoveVideoLink(url)                 }             }         }     } }  \/\/ yt-dlp shell exec: func DownloadVKVideo(videoUrl string) error {     cmd := exec.Command(\"yt-dlp\", \"-P\", \".\/media\", videoUrl)     var outBuf, errBuf bytes.Buffer     cmd.Stdout = &amp;outBuf     cmd.Stderr = &amp;errBuf     err := cmd.Run()     if err != nil {         return fmt.Errorf(\"yt-dlp error: %w\\nSTDOUT:\\n%s\\nSTDERR:\\n%s\", err, outBuf.String(), errBuf.String())     }     return nil } <\/code><\/pre>\n<h4>4. Poster: \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u0432 Telegram \u0441 AI-\u043f\u043e\u0434\u043f\u0438\u0441\u044c\u044e<\/h4>\n<p>Poster \u2014 \u0432\u043e\u0440\u043a\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0435\u0440\u0451\u0442 \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0438\u0437 \u043f\u0430\u043f\u043a\u0438, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0434\u043f\u0438\u0441\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OpenAI \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0432 \u043a\u0430\u043d\u0430\u043b:<\/p>\n<pre><code class=\"go\">func (p *Poster) processAndSendImage(imgPath string) error {     ...     imgBase64, _ := helpers.EncodeImageToBase64(data, ext)     caption, _ := p.openai.SetCaption(\"\u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u043c\u0435\u043c\", imgBase64)      photoMsg := tgbotapi.NewPhoto(p.channelID, tgbotapi.FileReader{Name: file.Name(), Reader: file})     photoMsg.Caption = caption      _, err := p.bot.Send(photoMsg)     return err } <\/code><\/pre>\n<p>\u0412\u0438\u0434\u0435\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e\u0442\u0441\u044f \u2014 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f thumbnail \u0447\u0435\u0440\u0435\u0437 ffmpeg.<\/p>\n<h3>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043d\u044e\u0430\u043d\u0441\u044b \u0438 best practices<\/h3>\n<ul>\n<li>\n<p><strong>\u041e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0441\u0442\u044c:<\/strong> \u0413\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0439-\u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u043d\u0435\u043b\u044c\u0437\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 yt-dlp \u0441 \u043e\u0434\u043d\u0438\u043c \u0444\u0430\u0439\u043b\u043e\u043c \u2014 \u0434\u0435\u0440\u0436\u0438\u0442\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u0442\u0440\u043e\u0433\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u0411\u0430\u0437\u0430:<\/strong> \u041d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0439\u0442\u0435 NutsDB \u0434\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0432\u043e\u0440\u043a\u0435\u0440\u043e\u0432!<\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f:<\/strong> \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0445\u044d\u0448\u0430 URL \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 (\u0434\u0430\u0436\u0435 \u043e\u0447\u0435\u043d\u044c \u0434\u043b\u0438\u043d\u043d\u044b\u0435) \u0441\u0441\u044b\u043b\u043a\u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0441 O(1) lookup.<\/p>\n<\/li>\n<li>\n<p><strong>yt-dlp:<\/strong> \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c yt-dlp \u0438 ffmpeg \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\/\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440.<\/p>\n<\/li>\n<li>\n<p><strong>Error handling:<\/strong> \u041b\u043e\u0433\u0438\u0440\u0443\u0439\u0442\u0435 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0448\u0438\u0431\u043a\u0438 yt-dlp, \u043d\u043e \u0438 \u0432\u0441\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0430 \u043c\u0435\u0441\u0442\u0430).<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c:<\/strong> NutsDB \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0442\u044f\u043d\u0435\u0442 \u0441\u043e\u0442\u043d\u0438 \u0442\u044b\u0441\u044f\u0447 \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u0438\u0434\u0435\u043e \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u2014 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0447\u0438\u0441\u0442\u0438\u0442\u0435 \u0441\u0442\u0430\u0440\u044b\u0435 processed \u043a\u043b\u044e\u0447\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e \u0434\u0430\u0442\u0435).<\/p>\n<\/li>\n<\/ul>\n<h3>\u0418\u0442\u043e\u0433\u0438 \u0438 \u0432\u044b\u0432\u043e\u0434\u044b<\/h3>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0438 \u043b\u044e\u0431\u044b\u0435 \u0441\u043e\u0446\u0441\u0435\u0442\u0438.<br \/>\u0412\u043c\u0435\u0441\u0442\u043e VK \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a (YouTube, TikTok, Reddit) \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0439\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 Source \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0439\u0442\u0435 \u0441 \u0442\u043e\u0439 \u0436\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u044c\u044e.<br \/>\u0414\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0430 NutsDB \u0434\u0435\u043b\u0430\u044e\u0442 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d &#171;\u043e\u0433\u043d\u0435\u0443\u043f\u043e\u0440\u043d\u044b\u043c&#187;: \u043d\u0438 \u043e\u0434\u043d\u043e \u0432\u0438\u0434\u0435\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u0430\u0447\u0430\u043d\u043e \u0434\u0432\u0430\u0436\u0434\u044b, \u0431\u043e\u0442 \u043d\u0435 \u043f\u0430\u0434\u0430\u0435\u0442 \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u0441\u0431\u043e\u044f\u0445 \u0441\u0435\u0442\u0438 \u0438\u043b\u0438 \u0440\u0435\u0441\u0442\u0430\u0440\u0442\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430.<\/p>\n<blockquote>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442: <a href=\"https:\/\/github.com\/digkill\/posterAndGrabberBot\" rel=\"noopener noreferrer nofollow\">github.com\/digkill\/posterAndGrabberBot<\/a><\/p>\n<\/blockquote>\n<h3>\u0412\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u0438\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0438\u0434\u0435\u0438 \u2014 \u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445!<br \/>PR \u0438 \u0437\u0432\u0435\u0437\u0434\u043e\u0447\u043a\u0438 \u043d\u0430 GitHub \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442\u0441\u044f.<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 \u0443\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Go Lang!<\/p>\n<p>P.S. \u0422\u0435\u043a\u0441\u0442 \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c\u0438 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u044f \u0431\u0443\u0434\u0443 \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/918186\/\"> https:\/\/habr.com\/ru\/articles\/918186\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\">\n<div><figcaption>\u041c\u0430\u0441\u043a\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0441\u0442\u0430\u043b\u0430 \u0443\u0436\u0435 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u0435\u0439<\/figcaption><\/div>\n<\/figure>\n<p>\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435, \u043a\u043e\u043b\u043b\u0435\u0433\u0438!<\/p>\n<p>\u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043e\u043f\u044b\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 production-ready Telegram-\u0431\u043e\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0441\u0432\u0435\u0436\u0438\u0439 \u0432\u0438\u0434\u0435\u043e\u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0438\u0437 \u043f\u0430\u0431\u043b\u0438\u043a\u0430 \u0412\u041a\u043e\u043d\u0442\u0430\u043a\u0442\u0435 \u2014 \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u0442\u043e <em>\u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0435\u0439, \u0441 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0435\u0439 \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438 \u0438 \u043c\u0435\u043c\u043d\u044b\u043c\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u044f\u043c\u0438 \u043d\u0430 \u0431\u0430\u0437\u0435 OpenAI<\/em>. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443, \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0444\u0438\u0448\u043a\u0430\u0445, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u0432\u0438\u0434\u0435\u043e (NutsDB), \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c (deduplication), \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 yt-dlp \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 OpenAI \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0439.<\/p>\n<blockquote>\n<p><strong>\u041a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u2014 <\/strong><a href=\"https:\/\/github.com\/digkill\/posterAndGrabberBot\" rel=\"noopener noreferrer nofollow\"><strong>github.com\/digkill\/posterAndGrabberBot<\/strong><\/a><\/p>\n<\/blockquote>\n<h3>TL;DR<\/h3>\n<ul>\n<li>\n<p><strong>Go<\/strong><\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u0441\u0442\u044b VK, \u0438\u0449\u0435\u043c \u0432\u0438\u0434\u0435\u043e, \u043a\u043b\u0430\u0434\u0451\u043c URL \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c (NutsDB) \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u0432\u0438\u0434\u0435\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u0440\u0430\u043d\u0435\u0435<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u0438\u0434\u0435\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/yt-dlp\/yt-dlp\" rel=\"noopener noreferrer nofollow\">yt-dlp<\/a><\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u0430\u044f (deduplication)<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\/\u0432\u0438\u0434\u0435\u043e \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e\u0442\u0441\u044f \u0432 Telegram \u0441 \u043f\u043e\u0434\u043f\u0438\u0441\u044c\u044e \u043e\u0442 OpenAI<\/p>\n<\/li>\n<\/ul>\n<h3>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0431\u0449\u0443\u044e \u0441\u0445\u0435\u043c\u0443:<\/p>\n<pre><code class=\"go\">VK API --&gt; Fetcher (\u0438\u0449\u0435\u0442 \u0432\u0438\u0434\u0435\u043e) --&gt; NutsDB (pending queue)    |                                      |    |------------------------------------&gt; goroutine (yt-dlp downloader)    |                                          |    |                                 (media directory)    |                                          |    |--&gt; Poster (OpenAI captions) ------------&gt; Telegram API<\/code><\/pre>\n<ul>\n<li>\n<p><strong>Fetcher:<\/strong> \u041f\u0430\u0440\u0441\u0438\u0442 \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0441\u0442\u044b \u0412\u041a, \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0432\u0438\u0434\u0435\u043e, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u2014 \u0431\u044b\u043b\u043e \u043b\u0438 \u0441\u043a\u0430\u0447\u0430\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p><strong>NutsDB:<\/strong> \u041b\u0451\u0433\u043a\u0430\u044f embedded-\u0431\u0430\u0437\u0430 \u0434\u043b\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u0438 URL \u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f processed-\u043c\u0430\u0440\u043a\u0435\u0440\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u0438\u0434\u0435\u043e-\u0432\u043e\u0440\u043a\u0435\u0440:<\/strong> \u041f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0435 \u0432\u0438\u0434\u0435\u043e yt-dlp, \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044f \u0434\u0443\u0431\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>Poster:<\/strong> \u041f\u043e\u0441\u0442\u0438\u0442 \u0444\u043e\u0442\u043e\/\u0432\u0438\u0434\u0435\u043e \u0432 Telegram-\u043a\u0430\u043d\u0430\u043b \u0441 \u043f\u043e\u0434\u043f\u0438\u0441\u044c\u044e \u0447\u0435\u0440\u0435\u0437 OpenAI.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041a\u043e\u043d\u0444\u0438\u0433 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a<\/h3>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"yaml\">telegram_bot_token     = \"\u0432\u0430\u0448_\u0442\u043e\u043a\u0435\u043d_\u0431\u043e\u0442\u0430\" telegram_channel_id    = \"\u0432\u0430\u0448_\u0438\u0434_\u043a\u0430\u043d\u0430\u043b\u0430_\u0434\u043b\u044f_\u043f\u043e\u0441\u0442\u043e\u0432\" vk_token               = \"\u0432\u0430\u0448_VK_API_\u0442\u043e\u043a\u0435\u043d\" fetch_interval         = \"10m\" notification_interval  = \"1m\" openai_key             = \"sk-...\" openai_model           = \"gpt-4o\" openai_prompt          = \"Make a meme caption for the image\" images_directory       = \".\/media\"<\/code><\/pre>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439:<\/p>\n<pre><code class=\"bash\">go mod tidy<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a:<\/p>\n<pre><code class=\"bash\">go run .\/cmd\/posterAndGrabberBot\/main.go<\/code><\/pre>\n<h3>\u041c\u043e\u0434\u0443\u043b\u044c\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430<\/h3>\n<h4>1. Fetcher: \u0441\u0431\u043e\u0440 \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u0441\u0442\u043e\u0432<\/h4>\n<p>Fetcher \u2014 \u0432\u043e\u0440\u043a\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 VK API, \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0441\u0442\u044b, \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 url \u0432\u0438\u0434\u0435\u043e \u0438 \u043a\u043b\u0430\u0434\u0451\u0442 \u0438\u0445 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 URL.<\/p>\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442:<\/strong><\/p>\n<pre><code class=\"go\">func (f *Fetcher) Fetch(ctx context.Context) error {     ...     for _, attach := range post.Attachments {         if attach.Type == \"video\" &amp;&amp; attach.Video != nil {             videoUrl := fmt.Sprintf(\"https:\/\/vk.com\/video%d_%d\", attach.Video.OwnerID, attach.Video.ID)             \/\/ \u0414\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f: \u043a\u043b\u0430\u0434\u0451\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u043a\u0430\u0447\u0430\u043d\u043e             if !nutsdb.IsVideoURLProcessed(videoUrl) {                 nutsdb.SaveVideoLink(videoUrl)             }         }     }     ... } <\/code><\/pre>\n<h4>2. NutsDB: \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/h4>\n<p>NutsDB \u2014 \u0431\u044b\u0441\u0442\u0440\u0430\u044f embedded key-value \u0431\u0430\u0437\u0430.<br \/> \u041c\u044b \u0445\u0440\u0430\u043d\u0438\u043c:<\/p>\n<ul>\n<li>\n<p>pending (list): url-\u044b \u0434\u043b\u044f \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>processed (set \u043f\u043e url): \u0445\u044d\u0448\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 url<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438 \u043f\u043e\u043c\u0435\u0442\u043a\u0430:<\/strong><\/p>\n<pre><code class=\"go\">import (     \"crypto\/md5\"     \"encoding\/hex\" )  func urlKey(url string) []byte {     h := md5.Sum([]byte(url))     return []byte(\"processed_\" + hex.EncodeToString(h[:])) }  func (n *NutsDB) IsVideoURLProcessed(url string) bool {     found := false     n.db.View(func(tx *nutsdb.Tx) error {         ds := nutsdb.DataStructureBPTree         bucket := \"videos\"         key := urlKey(url)         if tx.Has(bucket, key) == nil {             found = true         }         return nil     })     return found }  func (n *NutsDB) MarkVideoURLProcessed(url string) error {     return n.db.Update(func(tx *nutsdb.Tx) error {         ds := nutsdb.DataStructureBPTree         bucket := \"videos\"         key := urlKey(url)         return tx.Put(bucket, key, []byte{1})     }) } <\/code><\/pre>\n<h4>3. \u0413\u043e\u0440\u0443\u0442\u0438\u043d\u0430-\u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0442\u0435\u043b\u044c \u0447\u0435\u0440\u0435\u0437 yt-dlp<\/h4>\n<p>\u0412 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u043c\u044b \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0441\u0442\u0430\u0451\u043c URL \u0438\u0437 pending, \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0432\u0438\u0434\u0435\u043e \u0438 \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u043c url \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439.<\/p>\n<pre><code class=\"go\">func StartVideoDownloader(ctx context.Context, n *NutsDB) {     ticker := time.NewTicker(1 * time.Minute)     defer ticker.Stop()     for {         select {         case &lt;-ctx.Done():             return         case &lt;-ticker.C:             links, _ := n.GetAllPendingVideoLinks()             for _, url := range links {                 if err := DownloadVKVideo(url); err == nil {                     n.MarkVideoURLProcessed(url)                     n.RemoveVideoLink(url)                 }             }         }     } }  \/\/ yt-dlp shell exec: func DownloadVKVideo(videoUrl string) error {     cmd := exec.Command(\"yt-dlp\", \"-P\", \".\/media\", videoUrl)     var outBuf, errBuf bytes.Buffer     cmd.Stdout = &amp;outBuf     cmd.Stderr = &amp;errBuf     err := cmd.Run()     if err != nil {         return fmt.Errorf(\"yt-dlp error: %w\\nSTDOUT:\\n%s\\nSTDERR:\\n%s\", err, outBuf.String(), errBuf.String())     }     return nil } <\/code><\/pre>\n<h4>4. Poster: \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u0432 Telegram \u0441 AI-\u043f\u043e\u0434\u043f\u0438\u0441\u044c\u044e<\/h4>\n<p>Poster \u2014 \u0432\u043e\u0440\u043a\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0435\u0440\u0451\u0442 \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0438\u0437 \u043f\u0430\u043f\u043a\u0438, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0434\u043f\u0438\u0441\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OpenAI \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0432 \u043a\u0430\u043d\u0430\u043b:<\/p>\n<pre><code class=\"go\">func (p *Poster) processAndSendImage(imgPath string) error {     ...     imgBase64, _ := helpers.EncodeImageToBase64(data, ext)     caption, _ := p.openai.SetCaption(\"\u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u043c\u0435\u043c\", imgBase64)      photoMsg := tgbotapi.NewPhoto(p.channelID, tgbotapi.FileReader{Name: file.Name(), Reader: file})     photoMsg.Caption = caption      _, err := p.bot.Send(photoMsg)     return err } <\/code><\/pre>\n<p>\u0412\u0438\u0434\u0435\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e\u0442\u0441\u044f \u2014 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f thumbnail \u0447\u0435\u0440\u0435\u0437 ffmpeg.<\/p>\n<h3>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043d\u044e\u0430\u043d\u0441\u044b \u0438 best practices<\/h3>\n<ul>\n<li>\n<p><strong>\u041e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0441\u0442\u044c:<\/strong> \u0413\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0439-\u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u043d\u0435\u043b\u044c\u0437\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 yt-dlp \u0441 \u043e\u0434\u043d\u0438\u043c \u0444\u0430\u0439\u043b\u043e\u043c \u2014 \u0434\u0435\u0440\u0436\u0438\u0442\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u0442\u0440\u043e\u0433\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u0411\u0430\u0437\u0430:<\/strong> \u041d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0439\u0442\u0435 NutsDB \u0434\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0432\u043e\u0440\u043a\u0435\u0440\u043e\u0432!<\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f:<\/strong> \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0445\u044d\u0448\u0430 URL \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 (\u0434\u0430\u0436\u0435 \u043e\u0447\u0435\u043d\u044c \u0434\u043b\u0438\u043d\u043d\u044b\u0435) \u0441\u0441\u044b\u043b\u043a\u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0441 O(1) lookup.<\/p>\n<\/li>\n<li>\n<p><strong>yt-dlp:<\/strong> \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c yt-dlp \u0438 ffmpeg \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\/\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440.<\/p>\n<\/li>\n<li>\n<p><strong>Error handling:<\/strong> \u041b\u043e\u0433\u0438\u0440\u0443\u0439\u0442\u0435 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0448\u0438\u0431\u043a\u0438 yt-dlp, \u043d\u043e \u0438 \u0432\u0441\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0430 \u043c\u0435\u0441\u0442\u0430).<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c:<\/strong> NutsDB \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0442\u044f\u043d\u0435\u0442 \u0441\u043e\u0442\u043d\u0438 \u0442\u044b\u0441\u044f\u0447 \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u0438\u0434\u0435\u043e \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u2014 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0447\u0438\u0441\u0442\u0438\u0442\u0435 \u0441\u0442\u0430\u0440\u044b\u0435 processed \u043a\u043b\u044e\u0447\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e \u0434\u0430\u0442\u0435).<\/p>\n<\/li>\n<\/ul>\n<h3>\u0418\u0442\u043e\u0433\u0438 \u0438 \u0432\u044b\u0432\u043e\u0434\u044b<\/h3>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0438 \u043b\u044e\u0431\u044b\u0435 \u0441\u043e\u0446\u0441\u0435\u0442\u0438.<br \/>\u0412\u043c\u0435\u0441\u0442\u043e VK \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a (YouTube, TikTok, Reddit) \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0439\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 Source \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0439\u0442\u0435 \u0441 \u0442\u043e\u0439 \u0436\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u044c\u044e.<br \/>\u0414\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0430 NutsDB \u0434\u0435\u043b\u0430\u044e\u0442 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d &#171;\u043e\u0433\u043d\u0435\u0443\u043f\u043e\u0440\u043d\u044b\u043c&#187;: \u043d\u0438 \u043e\u0434\u043d\u043e \u0432\u0438\u0434\u0435\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u0430\u0447\u0430\u043d\u043e \u0434\u0432\u0430\u0436\u0434\u044b, \u0431\u043e\u0442 \u043d\u0435 \u043f\u0430\u0434\u0430\u0435\u0442 \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u0441\u0431\u043e\u044f\u0445 \u0441\u0435\u0442\u0438 \u0438\u043b\u0438 \u0440\u0435\u0441\u0442\u0430\u0440\u0442\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430.<\/p>\n<blockquote>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442: <a href=\"https:\/\/github.com\/digkill\/posterAndGrabberBot\" rel=\"noopener noreferrer nofollow\">github.com\/digkill\/posterAndGrabberBot<\/a><\/p>\n<\/blockquote>\n<h3>\u0412\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u0438\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0438\u0434\u0435\u0438 \u2014 \u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445!<br \/>PR \u0438 \u0437\u0432\u0435\u0437\u0434\u043e\u0447\u043a\u0438 \u043d\u0430 GitHub \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442\u0441\u044f.<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 \u0443\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Go Lang!<\/p>\n<p>P.S. \u0422\u0435\u043a\u0441\u0442 \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c\u0438 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u044f \u0431\u0443\u0434\u0443 \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/918186\/\"> https:\/\/habr.com\/ru\/articles\/918186\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-463330","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/463330","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=463330"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/463330\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=463330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=463330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=463330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}