@@ -13,20 +13,20 @@ type VideoRes string // Video Response
1313func (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
5151func (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}
0 commit comments