Fix noodlemagazine empty titles
The title div gained attributes (data-video-title-text); match the class and fall back to the thumbnail alt text. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MUYdCh2nCVsQYgJAT7gwSi
This commit is contained in:
@@ -498,13 +498,26 @@ impl NoodlemagazineProvider {
|
||||
|
||||
let video_url = format!("{}{}", self.url, href);
|
||||
|
||||
// The title div now carries extra attributes
|
||||
// (`<div class="title" data-video-title-text>`), so match the class
|
||||
// and skip to the tag end; fall back to the thumbnail `alt`, which
|
||||
// holds the same text.
|
||||
let mut title = video_segment
|
||||
.split("<div class=\"title\">")
|
||||
.split("<div class=\"title\"")
|
||||
.nth(1)
|
||||
.and_then(|s| s.split('<').next())
|
||||
.unwrap_or("")
|
||||
.trim()
|
||||
.to_string();
|
||||
.and_then(|s| s.split_once('>'))
|
||||
.and_then(|(_, rest)| rest.split('<').next())
|
||||
.map(|t| t.trim().to_string())
|
||||
.filter(|t| !t.is_empty())
|
||||
.or_else(|| {
|
||||
video_segment
|
||||
.split("alt=\"")
|
||||
.nth(1)
|
||||
.and_then(|s| s.split('"').next())
|
||||
.map(|t| t.trim().to_string())
|
||||
.filter(|t| !t.is_empty())
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
title = decode(title.as_bytes())
|
||||
.to_string()
|
||||
@@ -671,6 +684,30 @@ mod tests {
|
||||
assert_eq!(items[0].formats.as_ref().map(|f| f.len()), Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_title_when_title_div_has_extra_attributes() {
|
||||
let provider = NoodlemagazineProvider::new();
|
||||
let options = options();
|
||||
let html = r##"
|
||||
<div class="list_videos" id="list_videos">
|
||||
<div class="item" data-video-title-base="x">
|
||||
<a href="/watch/-1_2" class="item_link">
|
||||
<div class="i_img"><img src="data:image/gif;base64,R0lG" data-src="https://img.pvvstream.pro/preview/a/b.jpg" class="lazyload" alt="Alt text">
|
||||
<div class="m_views"><svg class="icon icon-eye"><use xlink:href="#eye"></use></svg> 133</div>
|
||||
<div class="m_time"><svg class="icon icon-clock-o"><use xlink:href="#clock-o"></use></svg> 04:55</div></div>
|
||||
<div class="i_info"><div class="title" data-video-title-text>The girl & her lover</div></div>
|
||||
</a>
|
||||
</div>
|
||||
>Show more</div>
|
||||
"##;
|
||||
|
||||
let items = provider.get_video_items_from_html(html.to_string(), &options);
|
||||
|
||||
assert_eq!(items.len(), 1);
|
||||
assert_eq!(items[0].title, "The Girl & Her Lover");
|
||||
assert_eq!(items[0].duration, 295);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_https_cdn_thumbs_but_drops_non_images() {
|
||||
let provider = NoodlemagazineProvider::new();
|
||||
|
||||
Reference in New Issue
Block a user