mirror of
				https://github.com/nkanaev/yarr.git
				synced 2025-10-31 06:53:30 +00:00 
			
		
		
		
	extract thumbnails from vimeo feeds
This commit is contained in:
		| @@ -1,8 +1,8 @@ | |||||||
| package parser | package parser | ||||||
|  |  | ||||||
| type media struct { | type media struct { | ||||||
| 	MediaGroups []mediaGroup `xml:"http://search.yahoo.com/mrss/ group"` | 	MediaGroups       []mediaGroup       `xml:"http://search.yahoo.com/mrss/ group"` | ||||||
|  | 	MediaContents     []mediaContent     `xml:"http://search.yahoo.com/mrss/ content"` | ||||||
| 	MediaThumbnails   []mediaThumbnail   `xml:"http://search.yahoo.com/mrss/ thumbnail"` | 	MediaThumbnails   []mediaThumbnail   `xml:"http://search.yahoo.com/mrss/ thumbnail"` | ||||||
| 	MediaDescriptions []mediaDescription `xml:"http://search.yahoo.com/mrss/ description"` | 	MediaDescriptions []mediaDescription `xml:"http://search.yahoo.com/mrss/ description"` | ||||||
| } | } | ||||||
| @@ -12,6 +12,10 @@ type mediaGroup struct { | |||||||
| 	MediaDescriptions []mediaDescription `xml:"http://search.yahoo.com/mrss/ description"` | 	MediaDescriptions []mediaDescription `xml:"http://search.yahoo.com/mrss/ description"` | ||||||
| } | } | ||||||
|  |  | ||||||
|  | type mediaContent struct { | ||||||
|  | 	MediaThumbnails []mediaThumbnail `xml:"http://search.yahoo.com/mrss/ thumbnail"` | ||||||
|  | } | ||||||
|  |  | ||||||
| type mediaThumbnail struct { | type mediaThumbnail struct { | ||||||
| 	URL string `xml:"url,attr"` | 	URL string `xml:"url,attr"` | ||||||
| } | } | ||||||
| @@ -22,6 +26,11 @@ type mediaDescription struct { | |||||||
| } | } | ||||||
|  |  | ||||||
| func (m *media) firstMediaThumbnail() string { | func (m *media) firstMediaThumbnail() string { | ||||||
|  | 	for _, c := range m.MediaContents { | ||||||
|  | 		for _, t := range c.MediaThumbnails { | ||||||
|  | 			return t.URL | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 	for _, t := range m.MediaThumbnails { | 	for _, t := range m.MediaThumbnails { | ||||||
| 		return t.URL | 		return t.URL | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -34,6 +34,7 @@ type rssItem struct { | |||||||
| 	ItunesSubtitle    string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd subtitle"` | 	ItunesSubtitle    string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd subtitle"` | ||||||
| 	ItunesSummary     string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"` | 	ItunesSummary     string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"` | ||||||
| 	GoogleDescription string `xml:"http://www.google.com/schemas/play-podcasts/1.0 description"` | 	GoogleDescription string `xml:"http://www.google.com/schemas/play-podcasts/1.0 description"` | ||||||
|  | 	media | ||||||
| } | } | ||||||
|  |  | ||||||
| type rssLink struct { | type rssLink struct { | ||||||
| @@ -84,6 +85,7 @@ func ParseRSS(r io.Reader) (*Feed, error) { | |||||||
| 			Title:    srcitem.Title, | 			Title:    srcitem.Title, | ||||||
| 			Content:  firstNonEmpty(srcitem.ContentEncoded, srcitem.Description), | 			Content:  firstNonEmpty(srcitem.ContentEncoded, srcitem.Description), | ||||||
| 			AudioURL: podcastURL, | 			AudioURL: podcastURL, | ||||||
|  | 			ImageURL: srcitem.firstMediaThumbnail(), | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| 	return dstfeed, nil | 	return dstfeed, nil | ||||||
|   | |||||||
| @@ -54,3 +54,32 @@ func TestRSSFeed(t *testing.T) { | |||||||
| 		t.Fatal("invalid rss") | 		t.Fatal("invalid rss") | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func TestRSSMediaContentThumbnail(t *testing.T) { | ||||||
|  | 	// see: https://vimeo.com/channels/staffpicks/videos/rss | ||||||
|  | 	feed, _ := Parse(strings.NewReader(` | ||||||
|  | 		<?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | 		<rss version="2.0" | ||||||
|  | 			xmlns:atom="http://www.w3.org/2005/Atom" | ||||||
|  | 			xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US"> | ||||||
|  | 			<channel> | ||||||
|  | 				<item> | ||||||
|  | 					<title></title> | ||||||
|  | 					<media:content> | ||||||
|  | 						<media:player url="https://player.vimeo.com/video/527877676"/> | ||||||
|  | 						<media:credit role="author" scheme="urn:ebu"></media:credit> | ||||||
|  | 						<media:thumbnail height="540" width="960" url="https://i.vimeocdn.com/video/1092705247_960.jpg"/> | ||||||
|  | 						<media:title></media:title> | ||||||
|  | 					</media:content> | ||||||
|  | 				</item> | ||||||
|  | 			</channel> | ||||||
|  | 		</rss> | ||||||
|  | 	`)) | ||||||
|  | 	have := feed.Items[0].ImageURL | ||||||
|  | 	want := "https://i.vimeocdn.com/video/1092705247_960.jpg" | ||||||
|  | 	if have != want { | ||||||
|  | 		t.Logf("want: %#v", want) | ||||||
|  | 		t.Logf("have: %#v", have) | ||||||
|  | 		t.FailNow() | ||||||
|  | 	} | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user