Skip to content

Commit fd3f1c0

Browse files
committed
re: refactor
1 parent 95f7dab commit fd3f1c0

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

cmd/ytgo/resparse.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ type VideoRes string // Video Response
1313
func (r VideoRes) Parse() (*Video, error) {
1414
re := regexp.MustCompile(`var ytInitialPlayerResponse = ({.*?});`)
1515
s := re.FindStringSubmatch(string(r))[1]
16-
var j interface{}
16+
var j any
1717
err := json.Unmarshal([]byte(s), &j)
1818
if err != nil {
1919
return nil, err
2020
}
21-
k, ok := j.(map[string]interface{})["videoDetails"].(map[string]interface{})
21+
k, ok := j.(map[string]any)["videoDetails"].(map[string]any)
2222
if ok {
2323
return getVideoFromDetails(&k)
2424
} else {
2525
return &Video{}, errors.New("interface type mismatch")
2626
}
2727
}
2828

29-
func getVideoFromDetails(j *map[string]interface{}) (*Video, error) {
29+
func getVideoFromDetails(j *map[string]any) (*Video, error) {
3030
t, err := strconv.Atoi((*j)["lengthSeconds"].(string))
3131
if err != nil {
3232
t = 0
@@ -51,16 +51,16 @@ type SearchRes string // Search Response
5151
func (r SearchRes) Parse() (*[]Video, error) {
5252
re := regexp.MustCompile(`var ytInitialData = ({.*?});`)
5353
s := re.FindStringSubmatch(string(r))[1]
54-
var j interface{}
54+
var j any
5555
err := json.Unmarshal([]byte(s), &j)
5656
if err != nil {
5757
return nil, err
5858
}
59-
res := j.(map[string]interface{})["contents"].(map[string]interface{})["twoColumnSearchResultsRenderer"].(map[string]interface{})["primaryContents"].(map[string]interface{})["sectionListRenderer"].(map[string]interface{})["contents"].([]interface{})[0].(map[string]interface{})["itemSectionRenderer"].(map[string]interface{})["contents"].([]interface{})
59+
res := j.(map[string]any)["contents"].(map[string]any)["twoColumnSearchResultsRenderer"].(map[string]any)["primaryContents"].(map[string]any)["sectionListRenderer"].(map[string]any)["contents"].([]any)[0].(map[string]any)["itemSectionRenderer"].(map[string]any)["contents"].([]any)
6060
return getVideoList(&res), nil
6161
}
6262

63-
func getVideoList(j *[]interface{}) *[]Video {
63+
func getVideoList(j *[]any) *[]Video {
6464
var vs []Video
6565
for _, i := range *j {
6666
v, isVideo := getVideoFromEntry(&i)
@@ -71,16 +71,16 @@ func getVideoList(j *[]interface{}) *[]Video {
7171
return &vs
7272
}
7373

74-
func getVideoFromEntry(j *interface{}) (*Video, bool) {
75-
k := (*j).(map[string]interface{})["videoRenderer"]
74+
func getVideoFromEntry(j *any) (*Video, bool) {
75+
k := (*j).(map[string]any)["videoRenderer"]
7676
if k == nil {
7777
return nil, false // when radioRenderer, shelfRenderer, reelShelfRenderer, etc.
7878
}
79-
l := k.(map[string]interface{})
79+
l := k.(map[string]any)
8080
return &Video{
8181
Id: VID(l["videoId"].(string)),
82-
Title: l["title"].(map[string]interface{})["runs"].([]interface{})[0].(map[string]interface{})["text"].(string),
83-
Channel: l["ownerText"].(map[string]interface{})["runs"].([]interface{})[0].(map[string]interface{})["text"].(string),
84-
Duration: l["lengthText"].(map[string]interface{})["simpleText"].(string),
82+
Title: l["title"].(map[string]any)["runs"].([]any)[0].(map[string]any)["text"].(string),
83+
Channel: l["ownerText"].(map[string]any)["runs"].([]any)[0].(map[string]any)["text"].(string),
84+
Duration: l["lengthText"].(map[string]any)["simpleText"].(string),
8585
}, true
8686
}

cmd/ytgo/vid.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func (v Video) Desc() string {
3333
}
3434

3535
func (v Video) Play(m bool) error {
36-
fmt.Println("Playing:", v)
3736
bestaudio, novideo := "", ""
3837
if m {
3938
bestaudio, novideo = "--ytdl-format=bestaudio", "--no-video"

cmd/ytgo/yt.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ entrypoint:
9898
} else if d {
9999
fmt.Println(v.Id.URL())
100100
} else {
101+
fmt.Println("Playing:", v)
101102
err = v.Play(m)
102103
}
103104
if err != nil {

0 commit comments

Comments
 (0)