-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update: The search function has been dec and the Playlist listing fea…
…ture has been added (The channel has been defined but not written yet.)
- Loading branch information
Showing
5 changed files
with
154 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package youtubego | ||
|
||
import "fmt" | ||
|
||
func ParsePlaylist(data interface{}) PlaylistParser { | ||
if data != nil { | ||
return PlaylistParser{ | ||
IsSuccess: false, | ||
} | ||
} else { | ||
return PlaylistParser{ | ||
IsSuccess: false, | ||
} | ||
} | ||
} | ||
|
||
func ParseChannel(data interface{}) ChannelParser { | ||
if data != nil { | ||
navEndpoint := data.(map[string]interface{})["navigationEndpoint"] | ||
url := fmt.Sprintf("https://www.youtube.com%s", navEndpoint.(map[string]interface{})["browseEndpoint"].(map[string]interface{})["canonicalBaseUrl"] || navEndpoint.(map[string]interface{})["commandMetadata"].(map[string]interface{})["webCommandMetadata"].(map[string]interface{})["url"]) | ||
thumbnail := data.(map[string]interface{})["thumbnail"].(map[string]interface{})["thumbnails"] | ||
|
||
var out ChannelParser | ||
out = ChannelParser{ | ||
Id: data.(map[string]interface{})["channelId"].(string), | ||
Url: url, | ||
Name: data.(map[string]interface{})["title"].(map[string]interface{})["simpleText"].(string), | ||
Icon: thumbnail.([]interface{})[len(thumbnail.([]interface{}))-1], | ||
Subscribers: data.(map[string]interface{})["subscriberCountText"].(map[string]interface{})["simpleText"], | ||
} | ||
} else { | ||
return ChannelParser{ | ||
IsSuccess: false, | ||
} | ||
} | ||
} | ||
|
||
func ParseVideo(data interface{}) VideoParser { | ||
if data != nil { | ||
thumbnail := data.(map[string]interface{})["thumbnail"].(map[string]interface{})["thumbnails"].([]interface{}) | ||
|
||
var out VideoParser | ||
out = VideoParser{ | ||
Video: Video{ | ||
Id: data.(map[string]interface{})["videoId"].(string), | ||
Title: data.(map[string]interface{})["title"].(map[string]interface{})["runs"].([]interface{})[0].(map[string]interface{})["text"].(string), | ||
Url: fmt.Sprintf("https://www.youtube.com/watch?v=%s", data.(map[string]interface{})["videoId"].(string)), | ||
Thumbnail: Thumbnail{ | ||
Id: data.(map[string]interface{})["videoId"].(string), | ||
Url: thumbnail[len(thumbnail)-1].(map[string]interface{})["url"].(string), | ||
Width: fmt.Sprintf("%v", thumbnail[len(thumbnail)-1].(map[string]interface{})["width"]), | ||
Height: fmt.Sprintf("%v", thumbnail[len(thumbnail)-1].(map[string]interface{})["height"]), | ||
}, | ||
}, | ||
IsSuccess: true, | ||
} | ||
|
||
return out | ||
} else { | ||
return VideoParser{ | ||
IsSuccess: false, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
package youtubego | ||
|
||
type Thumbnail struct { | ||
Id string | ||
Width string | ||
Height string | ||
Url string | ||
Id, Width, Height, Url string | ||
} | ||
|
||
type Video struct { | ||
Thumbnail | ||
Id string | ||
Title string | ||
Url string | ||
Id, Title, Url string | ||
} | ||
|
||
type VideoParser struct { | ||
Video | ||
IsSuccess bool | ||
} | ||
|
||
type Channel struct { | ||
Thumbnail | ||
Id, Url, Name, Subscribers string | ||
Verified bool | ||
} | ||
|
||
type ChannelParser struct { | ||
Channel | ||
IsSuccess bool | ||
} | ||
|
||
type Playlist struct { | ||
Thumbnail | ||
Channel | ||
Id, title string | ||
Videos int | ||
} | ||
|
||
type PlaylistParser struct { | ||
Playlist | ||
IsSuccess bool | ||
} | ||
|
||
type SearchResult struct { | ||
Video | ||
Playlist | ||
Channels | ||
} | ||
|
||
type SearchOptions struct { | ||
Limit int | ||
Type string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package youtubego | ||
|
||
func SearchVideos(searchq string) []Video { | ||
res := CreateRequest(searchq) | ||
func Search(searchq string, options SearchOptions) []interface{} { | ||
res := CreateRequest(searchq, options) | ||
|
||
return res | ||
} |