-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
releasetags.go
398 lines (360 loc) · 15.9 KB
/
releasetags.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
// Copyright (c) 2021 - 2023, Ludvig Lundgren and the autobrr contributors.
// SPDX-License-Identifier: GPL-2.0-or-later
package domain
import (
"fmt"
"regexp"
"github.com/autobrr/autobrr/pkg/errors"
)
var types map[string][]*TagInfo
func init() {
types = make(map[string][]*TagInfo)
audio := []*TagInfo{
{tag: "24BIT", title: "", regexp: "(?-i:24BIT)", re: nil},
{tag: "24BIT Lossless", title: "", regexp: "(?:24BIT lossless)", re: nil},
{tag: "16BIT", title: "", regexp: "(?-i:16BIT)", re: nil},
{tag: "320", title: "320 Kbps", regexp: "320[\\\\-\\\\._ kbps]?", re: nil},
{tag: "256", title: "256 Kbps", regexp: "256[\\\\-\\\\._ kbps]?", re: nil},
{tag: "192", title: "192 Kbps", regexp: "192[\\\\-\\\\._ kbps]?", re: nil},
{tag: "128", title: "128 Kbps", regexp: "128[\\\\-\\\\._ kbps]?", re: nil},
{tag: "AAC-LC", title: "Advanced Audio Coding (LC)", regexp: "aac[\\-\\._ ]?lc", re: nil},
{tag: "AAC", title: "Advanced Audio Coding (LC)", regexp: "", re: nil},
{tag: "AC3D", title: "", regexp: "ac[\\-\\._ ]?3d", re: nil},
{tag: "Atmos", title: "Dolby Atmos", regexp: "", re: nil},
{tag: "CBR", title: "Constant Bit Rate", regexp: "", re: nil},
{tag: "Cue", title: "Cue File", regexp: "", re: nil},
{tag: "DDPA", title: "Dolby Digital+ Atmos (E-AC-3+Atmos)", regexp: "dd[p\\+]a", re: nil},
{tag: "DDP", title: "Dolby Digital+ (E-AC-3)", regexp: "dd[p\\+]|e[\\-\\._ ]?ac3", re: nil},
{tag: "DD", title: "Dolby Digital (AC-3)", regexp: "dd|ac3|dolby[\\-\\._ ]?digital", re: nil},
{tag: "DTS-HD.HRA", title: "DTS (HD HRA)", regexp: "dts[\\-\\._ ]?hd[\\-\\._ ]?hra", re: nil},
{tag: "DTS-HD.HR", title: "DTS (HD HR)", regexp: "dts[\\-\\._ ]?hd[\\-\\._ ]?hr", re: nil},
{tag: "DTS-HD.MA", title: "DTS (HD MA)", regexp: "dts[\\-\\._ ]?hd[\\-\\._ ]?ma", re: nil},
{tag: "DTS-HD", title: "DTS (HD)", regexp: "dts[\\-\\._ ]?hd[\\-\\._ ]?", re: nil},
{tag: "DTS-MA", title: "DTS (MA)", regexp: "dts[\\-\\._ ]?ma[\\-\\._ ]?", re: nil},
{tag: "DTS-X", title: "DTS (X)", regexp: "dts[\\-\\._ ]?x", re: nil},
{tag: "DTS", title: "", regexp: "", re: nil},
{tag: "DUAL.AUDIO", title: "Dual Audio", regexp: "dual(?:[\\-\\._ ]?audio)?", re: nil},
{tag: "EAC3D", title: "", regexp: "", re: nil},
{tag: "ES", title: "Dolby Digital (ES)", regexp: "(?-i:ES)", re: nil},
{tag: "EX", title: "Dolby Digital (EX)", regexp: "(?-i:EX)", re: nil},
{tag: "FLAC", title: "Free Lossless Audio Codec", regexp: "", re: nil},
{tag: "LiNE", title: "Line", regexp: "(?-i:L[iI]NE)", re: nil},
{tag: "Lossless", title: "", regexp: "(?i:(?:^|[^t] )Lossless)", re: nil},
{tag: "Log100", title: "", regexp: "(log 100%|log \\(100%\\))", re: nil},
{tag: "Log", title: "", regexp: "(?:log)", re: nil},
{tag: "LPCM", title: "Linear Pulse-Code Modulation", regexp: "", re: nil},
{tag: "MP3", title: "", regexp: "", re: nil},
{tag: "OGG", title: "", regexp: "", re: nil},
{tag: "OPUS", title: "", regexp: "", re: nil},
{tag: "TrueHD", title: "Dolby TrueHD", regexp: "(?:dolby[\\-\\._ ]?)?true[\\-\\._ ]?hd", re: nil},
{tag: "VBR", title: "Variable Bit Rate", regexp: "", re: nil},
}
types["audio"] = audio
bonus := []*TagInfo{
{tag: "Freeleech", title: "Freeleech", regexp: "freeleech", re: nil},
}
types["bonus"] = bonus
channels := []*TagInfo{
{tag: "7.1", title: "", regexp: "7\\.1(?:[\\-\\._ ]?audios)?", re: nil},
{tag: "6.1", title: "", regexp: "6\\.1(?:[\\-\\._ ]?audios)?", re: nil},
{tag: "6.0", title: "", regexp: "6\\.0(?:[\\-\\._ ]?audios)?", re: nil},
{tag: "5.1", title: "", regexp: "5\\.1(?:[\\-\\._ ]?audios)?", re: nil},
{tag: "5.0", title: "", regexp: "5\\.0(?:[\\-\\._ ]?audios)?", re: nil},
{tag: "4.1", title: "", regexp: "4\\.1(?:[\\-\\._ ]?audios)?", re: nil},
{tag: "4.0", title: "", regexp: "4\\.0(?:[\\-\\._ ]?audios)?", re: nil},
{tag: "3.1", title: "", regexp: "3\\.1(?:[\\-\\._ ]?audios)?", re: nil},
{tag: "3.0", title: "", regexp: "3\\.0(?:[\\-\\._ ]?audios)?", re: nil},
{tag: "2.1", title: "", regexp: "2\\.1(?:[\\-\\._ ]?audios)?", re: nil},
{tag: "2.0", title: "", regexp: "2\\.0(?:[\\-\\._ ]?audios)?", re: nil},
{tag: "1.0", title: "", regexp: "1\\.0(?:[\\-\\._ ]?audios)?", re: nil},
}
types["channels"] = channels
codecs := []*TagInfo{
{tag: "DiVX.SBC", title: "DivX SBC", regexp: "(?:divx[\\-\\._ ]?)?sbc", re: nil},
{tag: "x264.HQ", title: "x264 (HQ)", regexp: "x[\\\\-\\\\._ ]?264[\\\\-\\\\._ ]?hq", re: nil},
{tag: "MPEG-2", title: "", regexp: "mpe?g(?:[\\-\\._ ]?2)?", re: nil},
{tag: "H.265", title: "", regexp: "h[\\-\\._ ]?265", re: nil},
{tag: "H.264", title: "", regexp: "h[\\-\\._ ]?264", re: nil},
{tag: "H.263", title: "", regexp: "h[\\-\\._ ]?263", re: nil},
{tag: "H.262", title: "", regexp: "h[\\-\\._ ]?2[26]2", re: nil},
{tag: "H.261", title: "", regexp: "h[\\-\\._ ]?261", re: nil},
{tag: "dxva", title: "Direct-X Video Acceleration", regexp: "", re: nil},
{tag: "HEVC", title: "High Efficiency Video Coding", regexp: "", re: nil},
{tag: "VC-1", title: "", regexp: "vc[\\-\\._ ]?1", re: nil},
{tag: "x265", title: "", regexp: "x[\\-\\._ ]?265", re: nil},
{tag: "x264", title: "", regexp: "x[\\-\\._ ]?264", re: nil},
{tag: "XViD", title: "Xvid", regexp: "", re: nil},
{tag: "AVC", title: "Advanced Video Coding", regexp: "avc(?:[\\-\\._ ]?1)?", re: nil},
{tag: "VP9", title: "", regexp: "vp[\\-\\._ ]?9", re: nil},
{tag: "VP8", title: "", regexp: "vp[\\-\\._ ]?8", re: nil},
{tag: "VP7", title: "", regexp: "vp[\\-\\._ ]?7", re: nil},
}
types["codecs"] = codecs
container := []*TagInfo{
{tag: "avi", title: "Audio Video Interleave (avi)", regexp: "", re: nil},
{tag: "img", title: "IMG", regexp: "", re: nil},
{tag: "iso", title: "ISO", regexp: "\\biso\\b", re: nil},
{tag: "mkv", title: "Matroska (mkv)", regexp: "", re: nil},
{tag: "mov", title: "MOV", regexp: "", re: nil},
{tag: "mp4", title: "MP4", regexp: "", re: nil},
{tag: "mpg", title: "MPEG", regexp: "mpe?g", re: nil},
{tag: "m2ts", title: "BluRay Disc (m2ts)", regexp: "", re: nil},
{tag: "vob", title: "VOB", regexp: "", re: nil},
}
types["container"] = container
hdr := []*TagInfo{
{tag: "HDR10+", title: "High Dynamic Range (10-bit+)", regexp: "hdr[\\-\\.]?10\\+|10\\+[\\-\\.]?bit|hdr10plus|hi10p", re: nil},
{tag: "HDR10", title: "High Dynamic Range (10-bit)", regexp: "hdr[\\-\\.]?10|10[\\-\\.]?bit|hi10", re: nil},
{tag: "HDR+", title: "High Dynamic Range+", regexp: "hdr\\+", re: nil},
{tag: "HDR", title: "High Dynamic Range", regexp: "", re: nil},
{tag: "SDR", title: "Standard Dynamic Range", regexp: "", re: nil},
{tag: "DV", title: "Dolby Vision", regexp: "(?i:dolby[\\-\\._ ]vision|dovi|\\Qdv\\E\\b)", re: nil},
}
types["hdr"] = hdr
other := []*TagInfo{
{tag: "HYBRID", title: "Hybrid", regexp: "", re: nil},
{tag: "REMUX", title: "Remux", regexp: "", re: nil},
{tag: "REPACK", title: "Repack", regexp: "repack(?:ed)?", re: nil},
{tag: "REREPACK", title: "Rerepack", regexp: "rerepack(?:ed)?", re: nil},
}
types["other"] = other
origin := []*TagInfo{
{tag: "P2P", title: "P2P", regexp: "", re: nil},
{tag: "Scene", title: "Scene", regexp: "", re: nil},
{tag: "O-Scene", title: "O-Scene", regexp: "", re: nil},
{tag: "Internal", title: "Internal", regexp: "", re: nil},
{tag: "User", title: "User", regexp: "", re: nil},
}
types["origin"] = origin
source := []*TagInfo{
{tag: "Cassette", title: "Cassette", regexp: "", re: nil},
{tag: "CD", title: "Compact Disc", regexp: "cd[\\-\\._ ]?(?:album)?", re: nil},
{tag: "BDRiP", title: "BluRay (rip)", regexp: "b[dr]?[\\-\\._ ]?rip", re: nil},
{tag: "BDSCR", title: "BluRay (screener)", regexp: "b[dr][\\-\\._ ]?scr(?:eener)?", re: nil},
{tag: "BluRay3D", title: "", regexp: "blu[\\-\\._ ]?ray[\\-\\._ ]?3d|bd3d", re: nil},
{tag: "BluRayRiP", title: "BluRay (rip)", regexp: "", re: nil},
{tag: "BluRay", title: "", regexp: "blu[\\-\\._ ]?ray|bd", re: nil},
{tag: "BRDRip", title: "BluRay Disc (rip)", regexp: "", re: nil},
{tag: "DAT", title: "Datacable", regexp: "(?-i:DAT)", re: nil},
{tag: "DVBRiP", title: "Digital Video Broadcasting (rip)", regexp: "dvb[\\-\\._ ]?rip", re: nil},
{tag: "DVDA", title: "Audio DVD", regexp: "", re: nil},
{tag: "DVDRiP", title: "Digital Video Disc (rip)", regexp: "dvd[\\-\\._ ]?rip", re: nil},
{tag: "DVDSCRRiP", title: "Digital Video Disc (screener rip)", regexp: "(?:dvd[\\-\\._ ]?)?scr(?:eener)?[\\-\\._ ]?rip", re: nil},
{tag: "DVDSCR", title: "Digital Video Disc (screener)", regexp: "(?:dvd[\\-\\._ ]?)?scr(?:eener)?", re: nil},
{tag: "DVDS", title: "Digital Video Disc (single)", regexp: "dvds(?:ingle)?", re: nil},
{tag: "DVD", title: "Digital Video Disc", regexp: "dvd", re: nil},
{tag: "SACD", title: "Super Audio Compact Disc", regexp: "", re: nil},
{tag: "RADIO", title: "Radio", regexp: "(?-i:R[aA]D[iI][oO])", re: nil},
{tag: "SATRiP", title: "Satellite (rip)", regexp: "sat[\\-\\._ ]?rip", re: nil},
{tag: "SAT", title: "Satellite Radio", regexp: "(?-i:SAT)", re: nil},
{tag: "SBD", title: "Soundboard", regexp: "(?-i:SBD|DAB|Soundboard)", re: nil},
{tag: "UHD.BDRiP", title: "Ultra High-Definition BluRay (rip)", regexp: "uhd[\\-\\._ ]?(?:bd)?rip", re: nil},
{tag: "UHD.BluRay", title: "Ultra High-Definition BluRay", regexp: "uhd[\\-\\._ ]?(?:blu[\\-\\._ ]?ray|bd)", re: nil},
{tag: "UHDTV", title: "Ultra High-Definition TV", regexp: "", re: nil},
{tag: "UMDMOVIE", title: "Universal Media Disc Movie", regexp: "", re: nil},
{tag: "Vinyl", title: "Vinyl", regexp: "vinyl|vl", re: nil},
{tag: "WEB-DL", title: "Web (DL)", regexp: "web[\\-\\._ ]?dl", re: nil},
{tag: "WEB-HD", title: "Web (HD)", regexp: "web[\\-\\._ ]?hd", re: nil},
{tag: "WEBFLAC", title: "Web (FLAC)", regexp: "", re: nil},
{tag: "WebHDRiP", title: "Web (HD rip)", regexp: "", re: nil},
{tag: "WEBRiP", title: "Web (rip)", regexp: "web[\\-\\._ ]?rip", re: nil},
{tag: "WEBSCR", title: "Web (screener)", regexp: "web[\\-\\._ ]?scr(?:eener)?", re: nil},
{tag: "WebUHD", title: "Web (UHD)", regexp: "", re: nil},
{tag: "WEB", title: "Web", regexp: "", re: nil},
}
types["source"] = source
resolution := []*TagInfo{
{tag: "PN", title: "Selector", regexp: "p(?:al)?[\\-\\._ ]?n(?:tsc)?[\\-\\._ ]selector", re: nil},
{tag: "DCI4K", title: "DCI 4k", regexp: "dci[\\-\\._ ]?4k|4096x2160", re: nil},
{tag: "DCI2K", title: "DCI 2k", regexp: "dci[\\-\\._ ]?2k|2048x1080", re: nil},
{tag: "4320p", title: "UltraHD 8K (4320p)", regexp: "4320p|7680x4320", re: nil},
{tag: "2880p", title: "5k (2880p)", regexp: "2880p|5k|5120x2880", re: nil},
{tag: "2160p", title: "UltraHD 4K (2160p)", regexp: "2160p|3840x2160|uhd|4k", re: nil},
{tag: "1800p", title: "QHD+ (1800p)", regexp: "1800p|3200x1800", re: nil},
{tag: "1440p", title: "QHD (1440p)", regexp: "1440p|2560x1440", re: nil},
{tag: "1080p", title: "FullHD (1080p)", regexp: "1080[ip]|1920x1080", re: nil},
{tag: "900p", title: "900[ip]|1600x900", regexp: "900[ip]|1600x900", re: nil},
{tag: "720p", title: "HD (720p)", regexp: "720[ip]|1280x720", re: nil},
{tag: "576p", title: "PAL (576p)", regexp: "576[ip]|720x576|pal", re: nil},
{tag: "540p", title: "qHD (540p)", regexp: "540[ip]|960x540", re: nil},
{tag: "480p", title: "NTSC (480p)", regexp: "480[ip]|720x480|848x480|854x480|ntsc", re: nil},
{tag: "360p", title: "nHD (360p)", regexp: "360[ip]|640x360", re: nil},
{tag: "$1p", title: "Other ($1p)", regexp: "([123]\\d{3})p", re: nil},
}
types["resolution"] = resolution
// language `(?i)\b((DK|DKSUBS|DANiSH|DUTCH|NL|NLSUBBED|ENG|FI|FLEMiSH|FiNNiSH|DE|FRENCH|GERMAN|HE|HEBREW|HebSub|HiNDi|iCELANDiC|KOR|MULTi|MULTiSUBS|NORWEGiAN|NO|NORDiC|PL|PO|POLiSH|PLDUB|RO|ROMANiAN|RUS|SPANiSH|SE|SWEDiSH|SWESUB||))\b`)
// websites `(?i)\b((AMBC|AS|AMZN|AMC|ANPL|ATVP|iP|CORE|BCORE|CMOR|CN|CBC|CBS|CMAX|CNBC|CC|CRIT|CR|CSPN|CW|DAZN|DCU|DISC|DSCP|DSNY|DSNP|DPLY|ESPN|FOX|FUNI|PLAY|HBO|HMAX|HIST|HS|HOTSTAR|HULU|iT|MNBC|MTV|NATG|NBC|NF|NICK|NRK|PMNT|PMNP|PCOK|PBS|PBSK|PSN|QIBI|SBS|SHO|STAN|STZ|SVT|SYFY|TLC|TRVL|TUBI|TV3|TV4|TVL|VH1|VICE|VMEO|UFC|USAN|VIAP|VIAPLAY|VL|WWEN|XBOX|YHOO|YT|RED))\b`)
for s, infos := range types {
for _, info := range infos {
var err error
//if info.re, err = regexp.Compile(`(?i)^(?:` + info.RE() + `)$`); err != nil {
if info.re, err = regexp.Compile(`(?i)(?:` + info.RE() + `)`); err != nil {
errors.Wrap(err, "tag %q has invalid regexp %q\n", s, info.re)
}
}
}
}
type TagInfo struct {
tag string
title string
regexp string
re *regexp.Regexp
}
// Tag returns the tag info tag.
func (info *TagInfo) Tag() string {
return info.tag
}
// Title returns the tag info title.
func (info *TagInfo) Title() string {
return info.title
}
// Regexp returns the tag info regexp.
func (info *TagInfo) Regexp() string {
return info.regexp
}
//// Other returns the tag info other.
//func (info *TagInfo) Other() string {
// return info.other
//}
//
//// Type returns the tag info type.
//func (info *TagInfo) Type() int {
// return info.typ
//}
//// Excl returns the tag info excl.
//func (info *TagInfo) Excl() bool {
// return info.excl
//}
// RE returns the tag info regexp string.
func (info *TagInfo) RE() string {
if info.regexp != "" {
return info.regexp
}
return `\Q` + info.tag + `\E`
}
// Match matches the tag info to s.
func (info *TagInfo) Match(s string) bool {
return info.re.MatchString(s)
}
// FindFunc is the find signature..
type FindFunc func(string) *TagInfo
// Find returns a func to find tag info.
func Find(infos ...*TagInfo) FindFunc {
n := len(infos)
return func(s string) *TagInfo {
for i := 0; i < n; i++ {
if infos[i].Match(s) {
return infos[i]
}
}
return nil
}
}
type ReleaseTags struct {
Audio []string
Bonus []string
Channels string
Codec string
Container string
HDR []string
Origin string
Other []string
Resolution string
Source string
}
func ParseReleaseTags(tags []string) ReleaseTags {
releaseTags := ReleaseTags{}
for _, tag := range tags {
for tagType, tagInfos := range types {
for _, info := range tagInfos {
// check tag
match := info.Match(tag)
if match {
fmt.Printf("match: %v, info: %v\n", tag, info.Tag())
switch tagType {
case "audio":
releaseTags.Audio = append(releaseTags.Audio, info.Tag())
continue
case "bonus":
releaseTags.Bonus = append(releaseTags.Bonus, info.Tag())
continue
case "channels":
releaseTags.Channels = info.Tag()
break
case "codecs":
releaseTags.Codec = info.Tag()
break
case "container":
releaseTags.Container = info.Tag()
break
case "hdr":
releaseTags.HDR = append(releaseTags.HDR, info.Tag())
continue
case "origin":
releaseTags.Origin = info.Tag()
break
case "other":
releaseTags.Other = append(releaseTags.Other, info.Tag())
continue
case "source":
releaseTags.Source = info.Tag()
break
case "resolution":
releaseTags.Resolution = info.Tag()
break
}
break
}
}
}
}
return releaseTags
}
func ParseReleaseTagString(tags string) ReleaseTags {
releaseTags := ReleaseTags{}
for tagType, tagInfos := range types {
//fmt.Printf("tagType: %v\n", tagType)
for _, info := range tagInfos {
// check tag
match := info.Match(tags)
if !match {
continue
}
//fmt.Printf("match: info: %v\n", info.Tag())
switch tagType {
case "audio":
releaseTags.Audio = append(releaseTags.Audio, info.Tag())
continue
case "bonus":
releaseTags.Bonus = append(releaseTags.Bonus, info.Tag())
continue
case "channels":
releaseTags.Channels = info.Tag()
break
case "codecs":
releaseTags.Codec = info.Tag()
break
case "container":
releaseTags.Container = info.Tag()
break
case "hdr":
releaseTags.HDR = append(releaseTags.HDR, info.Tag())
continue
case "origin":
releaseTags.Origin = info.Tag()
break
case "other":
releaseTags.Other = append(releaseTags.Other, info.Tag())
continue
case "source":
releaseTags.Source = info.Tag()
break
case "resolution":
releaseTags.Resolution = info.Tag()
break
}
break
}
}
return releaseTags
}