From 2128658e67e513a1e90fbd61c01487b6e6fff953 Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Thu, 4 Apr 2024 17:32:51 +0100 Subject: [PATCH] Add youtube embeds to FB import --- tools/.archiveignore | 1 + tools/archive/facebook/exportfile.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/.archiveignore b/tools/.archiveignore index 8dcc3b69..b4d2072e 100644 --- a/tools/.archiveignore +++ b/tools/.archiveignore @@ -1,3 +1,4 @@ rtv2nwevsrb7jskkoi2niza6qq tuoyt24xgoknswodnhizqehx2u lsdjotoggybiqsetlzmwcpptay +b3atqewyj3xseyeu2tmyogss4e \ No newline at end of file diff --git a/tools/archive/facebook/exportfile.go b/tools/archive/facebook/exportfile.go index cc26ef60..08d077b0 100644 --- a/tools/archive/facebook/exportfile.go +++ b/tools/archive/facebook/exportfile.go @@ -34,6 +34,8 @@ func makePostPath(postType string, postDate time.Time, postHash string) string { return path.Join("content", postType+"s", "facebook", postDate.Format("2006-01"), postHash) } +var youtubeRE = regexp.MustCompile(`youtu(?:\.be/|be.com/watch\?v=)(.+)`) + func postize(e PostCheckinPhotoOrVideo, matches []string) (shared.Post, shared.MediaMap, bool, error) { archiveRoot := matches[1] @@ -57,6 +59,11 @@ func postize(e PostCheckinPhotoOrVideo, matches []string) (shared.Post, shared.M }, } + // Ignore my posts on others' walls + if strings.HasPrefix(post.FrontMatter.Title, "JP Hastings-Spital wrote on") { + return post, nil, true, nil + } + for _, attach := range e.Attachments { linkURLs := attach.Data.GetSubstrings("external_context", "url") for _, link := range linkURLs { @@ -111,9 +118,8 @@ func postize(e PostCheckinPhotoOrVideo, matches []string) (shared.Post, shared.M post.PostFile = postFile - // Ignore my posts on others' walls - if strings.HasPrefix(post.FrontMatter.Title, "JP Hastings-Spital wrote on") { - return post, nil, true, nil + if match := youtubeRE.FindStringSubmatch(post.FrontMatter.BookmarkOf); len(match) > 1 { + post.PostFile = fmt.Sprintf("%s\n\n{{< youtube \"%s\" >}}", post.PostFile, match[1]) } return post, mm, false, nil