parseSearchItem 解析单个搜索结果项
(s *goquery.Selection, keyword string)
| 191 | |
| 192 | // parseSearchItem 解析单个搜索结果项 |
| 193 | func (p *ErxiaoAsyncPlugin) parseSearchItem(s *goquery.Selection, keyword string) model.SearchResult { |
| 194 | result := model.SearchResult{} |
| 195 | |
| 196 | // 提取详情页链接和ID |
| 197 | detailLink, exists := s.Find(".video-info-header h3 a").First().Attr("href") |
| 198 | if !exists { |
| 199 | return result |
| 200 | } |
| 201 | |
| 202 | // 提取ID |
| 203 | matches := detailIDRegex.FindStringSubmatch(detailLink) |
| 204 | if len(matches) < 2 { |
| 205 | return result |
| 206 | } |
| 207 | itemID := matches[1] |
| 208 | |
| 209 | // 构建唯一ID |
| 210 | uniqueID := fmt.Sprintf("%s-%s", p.Name(), itemID) |
| 211 | |
| 212 | // 提取标题 |
| 213 | title := strings.TrimSpace(s.Find(".video-info-header h3 a").First().Text()) |
| 214 | if title == "" { |
| 215 | return result |
| 216 | } |
| 217 | |
| 218 | // 提取分类 |
| 219 | category := strings.TrimSpace(s.Find(".video-info-items").First().Find(".video-info-item").First().Text()) |
| 220 | |
| 221 | // 提取导演 |
| 222 | directorElement := s.Find(".video-info-items").FilterFunction(func(i int, item *goquery.Selection) bool { |
| 223 | title := strings.TrimSpace(item.Find(".video-info-itemtitle").Text()) |
| 224 | return strings.Contains(title, "导演") |
| 225 | }) |
| 226 | director := strings.TrimSpace(directorElement.Find(".video-info-item").Text()) |
| 227 | |
| 228 | // 提取主演 |
| 229 | actorElement := s.Find(".video-info-items").FilterFunction(func(i int, item *goquery.Selection) bool { |
| 230 | title := strings.TrimSpace(item.Find(".video-info-itemtitle").Text()) |
| 231 | return strings.Contains(title, "主演") |
| 232 | }) |
| 233 | actor := strings.TrimSpace(actorElement.Find(".video-info-item").Text()) |
| 234 | |
| 235 | // 提取年份 |
| 236 | year := strings.TrimSpace(s.Find(".video-info-items").Last().Find(".video-info-item").First().Text()) |
| 237 | |
| 238 | // 提取质量/状态 |
| 239 | quality := strings.TrimSpace(s.Find(".video-info-header .video-info-remarks").Text()) |
| 240 | |
| 241 | // 提取剧情简介 |
| 242 | plotElement := s.Find(".video-info-items").FilterFunction(func(i int, item *goquery.Selection) bool { |
| 243 | title := strings.TrimSpace(item.Find(".video-info-itemtitle").Text()) |
| 244 | return strings.Contains(title, "剧情") |
| 245 | }) |
| 246 | plot := strings.TrimSpace(plotElement.Find(".video-info-item").Text()) |
| 247 | |
| 248 | // 提取封面图片 |
| 249 | var images []string |
| 250 | if picURL, exists := s.Find(".module-item-pic > img").Attr("data-src"); exists && picURL != "" { |