forked from podpalinc/rss-feed-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enclosure.go
83 lines (73 loc) · 1.75 KB
/
enclosure.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package podcast
import (
"encoding/xml"
)
// EnclosureType specifies the type of the enclosure.
const (
M4A EnclosureType = iota
M4V
MP4
MP3
MOV
PDF
EPUB
)
const (
enclosureDefault = "application/octet-stream"
)
// EnclosureType specifies the type of the enclosure.
type EnclosureType int
func (et EnclosureType) GetEnclosureType(enclosureType string) EnclosureType {
switch enclosureType {
case "audio/x-m4a":
return M4A
case "audio/mpeg":
return MP3
case "video/x-m4v":
return M4V
case "video/mp4":
return MP4
case "video/quicktime":
return MOV
}
return MP3
}
// String returns the MIME type encoding of the specified EnclosureType.
func (et EnclosureType) String() string {
// https://help.apple.com/itc/podcasts_connect/#/itcb54353390
switch et {
case M4A:
return "audio/x-m4a"
case M4V:
return "video/x-m4v"
case MP4:
return "video/mp4"
case MP3:
return "audio/mpeg"
case MOV:
return "video/quicktime"
case PDF:
return "application/pdf"
case EPUB:
return "document/x-epub"
}
return enclosureDefault
}
// Enclosure represents a download enclosure.
type Enclosure struct {
XMLName xml.Name `xml:"enclosure"`
// URL is the downloadable url for the content. (Required)
URL string `xml:"url,attr"`
// Length is the size in Bytes of the download. (Required)
Length int64 `xml:"-"`
// LengthFormatted is the size in Bytes of the download. (Required)
//
// This field gets overwritten with the API when setting Length.
LengthFormatted string `xml:"length,attr"`
// Type is MIME type encoding of the download. (Required)
Type EnclosureType `xml:"-"`
// TypeFormatted is MIME type encoding of the download. (Required)
//
// This field gets overwritten with the API when setting Type.
TypeFormatted string `xml:"type,attr"`
}