forked from nkanaev/yarr
/
media.go
55 lines (48 loc) · 1.41 KB
/
media.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package parser
type media struct {
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"`
MediaDescriptions []mediaDescription `xml:"http://search.yahoo.com/mrss/ description"`
}
type mediaGroup struct {
MediaThumbnails []mediaThumbnail `xml:"http://search.yahoo.com/mrss/ thumbnail"`
MediaDescriptions []mediaDescription `xml:"http://search.yahoo.com/mrss/ description"`
}
type mediaContent struct {
MediaThumbnails []mediaThumbnail `xml:"http://search.yahoo.com/mrss/ thumbnail"`
}
type mediaThumbnail struct {
URL string `xml:"url,attr"`
}
type mediaDescription struct {
Type string `xml:"type,attr"`
Description string `xml:",chardata"`
}
func (m *media) firstMediaThumbnail() string {
for _, c := range m.MediaContents {
for _, t := range c.MediaThumbnails {
return t.URL
}
}
for _, t := range m.MediaThumbnails {
return t.URL
}
for _, g := range m.MediaGroups {
for _, t := range g.MediaThumbnails {
return t.URL
}
}
return ""
}
func (m *media) firstMediaDescription() string {
for _, d := range m.MediaDescriptions {
return plain2html(d.Description)
}
for _, g := range m.MediaGroups {
for _, d := range g.MediaDescriptions {
return plain2html(d.Description)
}
}
return ""
}