This commit is contained in:
+25
-7
@@ -45,7 +45,7 @@ func NewSearchService(baseURL, googleVideoEngine, webEngine string) *SearchServi
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SearchService) SearchMedia(queries []string) ([]SearchResult, error) {
|
||||
func (s *SearchService) SearchMedia(queries []string, enabledPlatforms map[string]bool) ([]SearchResult, error) {
|
||||
if s.BaseURL == "" {
|
||||
return nil, fmt.Errorf("searxng base url is not configured")
|
||||
}
|
||||
@@ -93,6 +93,9 @@ func (s *SearchService) SearchMedia(queries []string) ([]SearchResult, error) {
|
||||
continue
|
||||
}
|
||||
for _, source := range sources {
|
||||
if len(enabledPlatforms) > 0 && !enabledPlatforms[strings.ToLower(source.name)] {
|
||||
continue
|
||||
}
|
||||
for _, searchQuery := range source.build(base) {
|
||||
items, err := s.search(searchQuery, source.categories, source.engine, source.name)
|
||||
if err != nil {
|
||||
@@ -205,6 +208,9 @@ func (s *SearchService) enrichArtgrid(result SearchResult) SearchResult {
|
||||
extractMetaContent(html, "og:image"),
|
||||
extractMetaContent(html, "twitter:image"),
|
||||
)
|
||||
if result.ThumbnailURL == "" {
|
||||
result.ThumbnailURL = extractArtgridBackgroundThumbnail(html, clipID)
|
||||
}
|
||||
}
|
||||
if result.PreviewVideoURL == "" {
|
||||
result.PreviewVideoURL = extractVideoPreviewURL(html)
|
||||
@@ -283,7 +289,7 @@ func buildGoogleVideoQueries(base string) []string {
|
||||
func buildEnvatoQueries(base string) []string {
|
||||
return []string{
|
||||
fmt.Sprintf(`"%s" ("stock footage" OR "stock video" OR "b-roll" OR cinematic) site:elements.envato.com`, base),
|
||||
fmt.Sprintf(`"%s" ("stock footage" OR "stock video" OR "b-roll" OR cinematic) site:videohive.net/item`, base),
|
||||
fmt.Sprintf(`"%s" ("stock footage" OR "stock video" OR "b-roll" OR cinematic) site:elements.envato.com/stock-video`, base),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,6 +301,10 @@ func buildArtgridQueries(base string) []string {
|
||||
}
|
||||
|
||||
func isUsefulGoogleVideoResult(result SearchResult) bool {
|
||||
lowerLink := strings.ToLower(result.Link)
|
||||
if !(strings.Contains(lowerLink, "youtube.com/watch") || strings.Contains(lowerLink, "youtu.be/") || strings.Contains(lowerLink, "youtube.com/shorts/")) {
|
||||
return false
|
||||
}
|
||||
text := strings.ToLower(result.Title + " " + result.Snippet)
|
||||
for _, banned := range []string{
|
||||
"tutorial", "how to", "review", "reaction", "podcast", "interview", "walkthrough",
|
||||
@@ -315,11 +325,8 @@ func isRenderableEnvatoResult(result SearchResult) bool {
|
||||
}
|
||||
host := strings.ToLower(parsed.Host)
|
||||
path := strings.Trim(parsed.Path, "/")
|
||||
if strings.Contains(host, "videohive.net") {
|
||||
return strings.HasPrefix(path, "item/") && len(strings.Split(path, "/")) >= 2
|
||||
}
|
||||
if strings.Contains(host, "elements.envato.com") {
|
||||
if path == "" || strings.Contains(path, "/") {
|
||||
if path == "" || strings.Contains(path, "/stock-video") || strings.Contains(path, "/video-templates") {
|
||||
return false
|
||||
}
|
||||
return regexp.MustCompile(`-[A-Z0-9]{6,}$`).MatchString(path)
|
||||
@@ -407,13 +414,24 @@ func extractVideoPreviewURL(html string) string {
|
||||
candidate := strings.ReplaceAll(match, `\/`, `/`)
|
||||
candidate = strings.ReplaceAll(candidate, `\u002F`, `/`)
|
||||
candidate = strings.ReplaceAll(candidate, `\\`, "")
|
||||
if strings.Contains(strings.ToLower(candidate), "preview") || strings.Contains(strings.ToLower(candidate), "video") {
|
||||
if strings.Contains(strings.ToLower(candidate), "preview") || strings.Contains(strings.ToLower(candidate), "video") || strings.Contains(strings.ToLower(candidate), "watermark") {
|
||||
return candidate
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func extractArtgridBackgroundThumbnail(html, clipID string) string {
|
||||
pattern := regexp.MustCompile(`https://[^"'\\s>]+(?:artgrid\.imgix\.net|cms-public-artifacts\.artlist\.io|artlist-content-images\.imgix\.net)[^"'\\s>]+(?:jpeg|jpg|png|webp)`)
|
||||
matches := pattern.FindAllString(html, -1)
|
||||
for _, match := range matches {
|
||||
if strings.Contains(match, clipID) || strings.Contains(strings.ToLower(match), "graded-thumbnail") {
|
||||
return match
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func extractArtgridClipID(link string) string {
|
||||
matches := regexp.MustCompile(`/clip/([0-9]+)/`).FindStringSubmatch(link)
|
||||
if len(matches) == 2 {
|
||||
|
||||
Reference in New Issue
Block a user