~cytrogen/ytm

ytm/types.go -rw-r--r-- 1.1 KiB
f884dc98 — HallowDem Initial commit: YTM - YouTube Music Downloader a month ago
                                                                                
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
package main

import (
	"regexp"
	"strings"
)

const InnerTubeBase = "https://music.youtube.com/youtubei/v1"

type Artist struct {
	ID           string
	Name         string
	ReleaseCount int
}

type Release struct {
	MPREID     string
	OLAKID     string
	Title      string
	Artist     string
	TrackCount int
	Tracks     []Track
}

type Track struct {
	Index   int
	Title   string
	VideoID string
}

var (
	reChannelID   = regexp.MustCompile(`UC[a-zA-Z0-9_-]{22}`)
	reMPREID      = regexp.MustCompile(`MPREb_[a-zA-Z0-9_-]+`)
	reOLAKID      = regexp.MustCompile(`OLAK5uy_[a-zA-Z0-9_-]+`)
	reTitle       = regexp.MustCompile(`"text"\s*:\s*"((?:[^"\\]|\\.)*)"`)
	reHeaderTag    = regexp.MustCompile(`"musicImmersiveHeaderRenderer"`)
	reStrapline    = regexp.MustCompile(`"straplineTextOne":\{"runs":\[\{"text":"((?:[^"\\]|\\.)*)"`)
)

var windowsIllegal = strings.NewReplacer(
	"<", "_",
	">", "_",
	":", "_",
	"\"", "_",
	"/", "_",
	"\\", "_",
	"|", "_",
	"?", "_",
	"*", "_",
)

func sanitizePath(name string) string {
	s := windowsIllegal.Replace(name)
	s = strings.TrimSpace(s)
	if len(s) > 100 {
		s = s[:100]
	}
	return s
}