diff --git a/app.go b/app.go index abba8a2..65a6aee 100644 --- a/app.go +++ b/app.go @@ -479,3 +479,49 @@ func (a *App) ShareWorkspace(id int) error { err = util.OpenURL("https://sharegpt.com/c/" + response.ID) return nil } + +type YoutubeVideoResult struct { + Details YoutubeVideoDetails `json:"details"` + Captions []util.YtCustomCaption `json:"captions"` +} +type YoutubeVideoDetails struct { + Title string `json:"title"` + LengthSeconds string `json:"length_seconds"` + Description string `json:"description"` + Keywords []string `json:"keywords"` + PicURL string `json:"pic_url"` + Author string `json:"author"` +} + +func (a *App) GetYoutubeVideo(url string) (YoutubeVideoResult, error) { + var result YoutubeVideoResult + yt, err := util.NewYoutube(url, a.settings.config.Proxy) + if err != nil { + return result, err + } + vd, err := yt.GetVideoDetails() + if err != nil { + return result, err + } + cp, err := yt.GetCaptions() + if err != nil { + return result, err + } + th, _ := lo.Last(vd.Thumbnail.Thumbnails) + result = YoutubeVideoResult{ + Details: YoutubeVideoDetails{ + Title: vd.Title, + LengthSeconds: vd.LengthSeconds, + Description: vd.ShortDescription, + Keywords: vd.Keywords, + PicURL: th.Url, + Author: vd.Author, + }, + Captions: cp, + } + return result, nil +} + +func (a *App) GetYoutubeTranscript(caption util.YtCustomCaption) ([]util.YtTranscriptText, error) { + return caption.GetTranscript(a.settings.config.Proxy) +} diff --git a/config.go b/config.go index 095c467..6d3f828 100644 --- a/config.go +++ b/config.go @@ -81,6 +81,7 @@ type Migration struct { SydneyPreset20240304 bool `json:"sydney_preset_20240304"` ThemeColor20240304 bool `json:"theme_color_20240304"` Quick20240326 bool `json:"quick_20240326"` + Quick20240405 bool `json:"quick_20240405"` } func fillDefault[T comparable](pointer *T, defaultValue T) { @@ -126,6 +127,15 @@ func (o *Config) DoMigration() { } o.Migration.Quick20240326 = true } + if !o.Migration.Quick20240405 { + _, ok := lo.Find(o.Quick, func(item string) bool { + return item == "Summarize the video from Youtube according to the given information." + }) + if !ok { + o.Quick = append(o.Quick, "Summarize the video from Youtube according to the given information.") + } + o.Migration.Quick20240405 = true + } } func (o *Config) FillDefault() { if len(o.Presets) == 0 { @@ -151,6 +161,7 @@ func (o *Config) FillDefault() { "Fix grammar errors and polish the writing of the text above.", "Translate the text above into Chinese in a fluent way.", "Continue the conversation in context. Assistant:", + "Summarize the video from Youtube according to the given information.", "[user](#message)"} } if len(o.OpenAIBackends) == 0 { diff --git a/frontend/src/components/index/InsertVideoButton.vue b/frontend/src/components/index/InsertVideoButton.vue new file mode 100644 index 0000000..c3a2b7b --- /dev/null +++ b/frontend/src/components/index/InsertVideoButton.vue @@ -0,0 +1,103 @@ + + + + + \ No newline at end of file diff --git a/frontend/src/pages/IndexPage.vue b/frontend/src/pages/IndexPage.vue index e45aa39..e3d543c 100644 --- a/frontend/src/pages/IndexPage.vue +++ b/frontend/src/pages/IndexPage.vue @@ -17,6 +17,7 @@ import UploadPanelButton from "../components/index/UploadPanelButton.vue" import UploadDocumentButton from "../components/index/UploadDocumentButton.vue" import FetchWebpageButton from "../components/index/FetchWebpageButton.vue" import RevokeButton from "../components/index/RevokeButton.vue" +import InsertVideoButton from "../components/index/InsertVideoButton.vue" import AskOptions = main.AskOptions import Workspace = main.Workspace import ChatFinishResult = main.ChatFinishResult @@ -620,6 +621,7 @@ function generateTitle() { > +