Move work command
[yt-mango.git] / data / format.go
blob154fa28406632f7dc15b60c7d038ef6461bb97b1
1 package data
3 import "encoding/json"
5 type FormatType uint8
7 const (
8 FormatVideoOnly = 1 << iota
9 FormatAudioOnly
10 Format3D
11 FormatHLS
12 FormatDASH
13 FormatHighFps
14 FormatStd = 0
17 type Format struct {
18 ID string `json:"id"`
19 Extension string `json:"ext"`
20 Width uint32 `json:"width"`
21 Height uint32 `json:"height"`
22 VideoCodec string `json:"vcodec"`
23 AudioCodec string `json:"acodec"`
24 AudioBitrate uint32 `json:"abr"`
25 Flags FormatType `json:"flags"`
28 var FormatsById map[string]*Format
30 func init() {
31 ids := []string {
32 "5", "6", "13", "17", "18", "22", "34", "35",
33 "36", "37", "38", "43", "44", "45", "46", "59",
34 "78", "82", "83", "84", "85", "100", "101", "102",
35 "91", "92", "93", "94", "95", "96", "132", "151",
36 "133", "134", "135", "136", "137", "138", "160", "212",
37 "264", "298", "299", "266", "139", "140", "141", "256",
38 "258", "325", "328", "167", "168", "169", "170", "218",
39 "219", "278", "242", "243", "244", "245", "246", "247",
40 "248", "271", "272", "302", "303", "308", "313", "315",
41 "171", "172", "249", "250", "251",
43 FormatsById = make(map[string]*Format)
44 for i, id := range ids {
45 format := &Formats[i]
46 if format.ID != id { panic("misaligned IDs: " + id + "/" + format.ID) }
47 FormatsById[id] = format
51 // Taken from github.com/rg3/youtube-dl
52 // As in youtube_dl/extractor/youtube.py
53 var Formats = []Format{
54 // Standard formats
55 { "5", "flv", 400, 240, "h263", "mp3", 64, FormatStd },
56 { "6", "flv", 450, 270, "h263", "mp3", 64, FormatStd },
57 { "13", "3gp", 0, 0, "mp4v", "aac", 0, FormatStd },
58 { "17", "3gp", 176, 144, "mp4v", "aac", 24, FormatStd },
59 { "18", "mp4", 640, 360, "h264", "aac", 96, FormatStd },
60 { "22", "mp4", 1280, 720, "h264", "aac", 192, FormatStd },
61 { "34", "flv", 640, 360, "h264", "aac", 128, FormatStd },
62 { "35", "flv", 854, 480, "h264", "aac", 128, FormatStd },
63 // * ID 36 videos are either 320x180 (BaW_jenozKc) or 320x240 (__2ABJjxzNo), abr varies as well
64 { "36", "3gp", 320, 0, "mp4v", "aac", 0, FormatStd },
65 { "37", "mp4", 1920, 1080, "h264", "aac", 192, FormatStd },
66 { "38", "mp4", 4096, 3072, "h264", "aac", 192, FormatStd },
67 { "43", "webm", 640, 360, "vp8", "vorbis", 128, FormatStd },
68 { "44", "webm", 854, 480, "vp8", "vorbis", 128, FormatStd },
69 { "45", "webm", 1280, 720, "vp8", "vorbis", 192, FormatStd },
70 { "46", "webm", 1920, 1080, "vp8", "vorbis", 192, FormatStd },
71 { "59", "mp4", 854, 480, "h264", "aac", 128, FormatStd },
72 { "78", "mp4", 854, 480, "h264", "aac", 128, FormatStd },
74 // 3D videos
75 { "82", "mp4", 0, 360, "h264", "aac", 128, Format3D },
76 { "83", "mp4", 0, 480, "h264", "aac", 128, Format3D },
77 { "84", "mp4", 0, 720, "h264", "aac", 192, Format3D },
78 { "85", "mp4", 0, 1080, "h264", "aac", 192, Format3D },
79 { "100", "webm", 0, 360, "vp8", "vorbis", 128, Format3D },
80 { "101", "webm", 0, 480, "vp8", "vorbis", 192, Format3D },
81 { "102", "webm", 0, 720, "vp8", "vorbis", 192, Format3D },
83 // Apple HTTP Live Streaming
84 { "91", "mp4", 0, 144, "h264", "aac", 48, FormatHLS },
85 { "92", "mp4", 0, 240, "h264", "aac", 48, FormatHLS },
86 { "93", "mp4", 0, 360, "h264", "aac", 128, FormatHLS },
87 { "94", "mp4", 0, 480, "h264", "aac", 128, FormatHLS },
88 { "95", "mp4", 0, 720, "h264", "aac", 256, FormatHLS },
89 { "96", "mp4", 0, 1080, "h264", "aac", 256, FormatHLS },
90 { "132", "mp4", 0, 240, "h264", "aac", 48, FormatHLS },
91 { "151", "mp4", 0, 72, "h264", "aac", 24, FormatHLS },
93 // DASH mp4 video
94 { "133", "mp4", 0, 240, "h264", "", 0, FormatDASH | FormatVideoOnly },
95 { "134", "mp4", 0, 360, "h264", "", 0, FormatDASH | FormatVideoOnly },
96 { "135", "mp4", 0, 480, "h264", "", 0, FormatDASH | FormatVideoOnly },
97 { "136", "mp4", 0, 720, "h264", "", 0, FormatDASH | FormatVideoOnly },
98 { "137", "mp4", 0, 1080, "h264", "", 0, FormatDASH | FormatVideoOnly },
99 { "138", "mp4", 0, 0, "h264", "", 0, FormatDASH | FormatVideoOnly }, // Height can vary (https://github.com/rg3/youtube-dl/issues/4559)
100 { "160", "mp4", 0, 144, "h264", "", 0, FormatDASH | FormatVideoOnly },
101 { "212", "mp4", 0, 480, "h264", "", 0, FormatDASH | FormatVideoOnly },
102 { "264", "mp4", 0, 1440, "h264", "", 0, FormatDASH | FormatVideoOnly },
103 { "298", "mp4", 0, 720, "h264", "", 0, FormatDASH | FormatVideoOnly | FormatHighFps },
104 { "299", "mp4", 0, 1080, "h264", "", 0, FormatDASH | FormatVideoOnly | FormatHighFps },
105 { "266", "mp4", 0, 2160, "h264", "", 0, FormatDASH | FormatVideoOnly },
107 // DASH mp4 audio
108 { "139", "m4a", 0, 0, "", "aac", 48, FormatDASH | FormatAudioOnly },
109 { "140", "m4a", 0, 0, "", "aac", 128, FormatDASH | FormatAudioOnly },
110 { "141", "m4a", 0, 0, "", "aac", 256, FormatDASH | FormatAudioOnly },
111 { "256", "m4a", 0, 0, "", "aac", 0, FormatDASH | FormatAudioOnly },
112 { "258", "m4a", 0, 0, "", "aac", 0, FormatDASH | FormatAudioOnly },
113 { "325", "m4a", 0, 0, "", "dtse", 0, FormatDASH | FormatAudioOnly },
114 { "328", "m4a", 0, 0, "", "ec-3", 0, FormatDASH | FormatAudioOnly },
116 // DASH webm
117 { "167", "webm", 640, 360, "vp8", "", 0, FormatDASH | FormatVideoOnly },
118 { "168", "webm", 854, 480, "vp8", "", 0, FormatDASH | FormatVideoOnly },
119 { "169", "webm", 1280, 720, "vp8", "", 0, FormatDASH | FormatVideoOnly },
120 { "170", "webm", 1920, 1080, "vp8", "", 0, FormatDASH | FormatVideoOnly },
121 { "218", "webm", 854, 480, "vp8", "", 0, FormatDASH | FormatVideoOnly },
122 { "219", "webm", 854, 480, "vp8", "", 0, FormatDASH | FormatVideoOnly },
123 { "278", "webm", 0, 144, "vp9", "", 0, FormatDASH | FormatVideoOnly },
124 { "242", "webm", 0, 240, "vp9", "", 0, FormatDASH | FormatVideoOnly },
125 { "243", "webm", 0, 360, "vp9", "", 0, FormatDASH | FormatVideoOnly },
126 { "244", "webm", 0, 480, "vp9", "", 0, FormatDASH | FormatVideoOnly },
127 { "245", "webm", 0, 480, "vp9", "", 0, FormatDASH | FormatVideoOnly },
128 { "246", "webm", 0, 480, "vp9", "", 0, FormatDASH | FormatVideoOnly },
129 { "247", "webm", 0, 720, "vp9", "", 0, FormatDASH | FormatVideoOnly },
130 { "248", "webm", 0, 1080, "vp9", "", 0, FormatDASH | FormatVideoOnly },
131 { "271", "webm", 0, 1440, "vp9", "", 0, FormatDASH | FormatVideoOnly },
132 // * ID 272 videos are either 3840x2160 (e.g. RtoitU2A-3E) or 7680x4320 (sLprVF6d7Ug)
133 { "272", "webm", 0, 2160, "vp9", "", 0, FormatDASH | FormatVideoOnly },
134 { "302", "webm", 0, 720, "vp9", "", 0, FormatDASH | FormatVideoOnly | FormatHighFps },
135 { "303", "webm", 0, 1080, "vp9", "", 0, FormatDASH | FormatVideoOnly | FormatHighFps },
136 { "308", "webm", 0, 1440, "vp9", "", 0, FormatDASH | FormatVideoOnly | FormatHighFps },
137 { "313", "webm", 0, 2160, "vp9", "", 0, FormatDASH | FormatVideoOnly },
138 { "315", "webm", 0, 2160, "vp9", "", 0, FormatDASH | FormatVideoOnly | FormatHighFps },
140 // DASH webm audio
141 { "171", "webm", 0, 0, "", "vorbis", 128, FormatDASH | FormatAudioOnly },
142 { "172", "webm", 0, 0, "", "vorbis", 256, FormatDASH | FormatAudioOnly },
144 // DASH webm opus audio
145 { "249", "webm", 0, 0, "", "opus", 50, FormatDASH | FormatAudioOnly },
146 { "250", "webm", 0, 0, "", "opus", 70, FormatDASH | FormatAudioOnly },
147 { "251", "webm", 0, 0, "", "opus", 160, FormatDASH | FormatAudioOnly },
150 func (f FormatType) MarshalJSON() ([]byte, error) {
151 flags := make([]string, 0)
152 setFlag := func(mask FormatType, name string) {
153 if f&mask != 0 {
154 flags = append(flags, name)
157 setFlag(FormatVideoOnly, "videoOnly")
158 setFlag(FormatAudioOnly, "audioOnly")
159 setFlag(Format3D, "3d")
160 setFlag(FormatHLS, "hls")
161 setFlag(FormatDASH, "dash")
162 setFlag(FormatHighFps, "hiFps")
163 return json.Marshal(flags)