aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Hurst <julian.hurst92@gmail.com>2021-01-09 23:26:00 +0100
committerJulian Hurst <julian.hurst92@gmail.com>2021-01-09 23:26:00 +0100
commit9b9cfc7555277ceab79805933b57ae82c9750d01 (patch)
tree4790f52e6d6345a25cb9eb0e9d44fff05350a4ab
parent6118566d444ee0dc2f31bd9e0443ca39828c1c05 (diff)
downloadytparser-9b9cfc7555277ceab79805933b57ae82c9750d01.tar.gz
Add LengthText support
-rw-r--r--ytparser.go67
1 files changed, 38 insertions, 29 deletions
diff --git a/ytparser.go b/ytparser.go
index 91e63b2..8edbf6a 100644
--- a/ytparser.go
+++ b/ytparser.go
@@ -29,6 +29,7 @@ type Item struct {
ChannelTitle string
ChannelUrl string
Published string // The published date provided by youtube as is.
+ LengthText string // The length of the video rendered as text by youtube.
}
// Executes a given template on an item and returns the resulting string.
@@ -95,50 +96,58 @@ func parsejson(data string) ([]Item, error) {
isValue = true
} else {
//fmt.Println(names[len(names) - 1])
- if depth >= 2 && names[depth-2] == "videoRenderer" &&
- names[depth-1] == "videoId" {
+ if depth >= 2 &&
+ names[depth-2] == "videoRenderer" &&
+ names[depth-1] == "videoId" {
item.Id = t
item.Url = fmt.Sprintf("https://youtube.com/watch?v=%s", t)
}
- if depth >= 3 && names[depth-3] == "title" &&
- names[depth-2] == "runs" &&
- names[depth-1] == "text" {
+ if depth >= 3 &&
+ names[depth-3] == "title" &&
+ names[depth-2] == "runs" &&
+ names[depth-1] == "text" {
item.Title = t
}
- if depth >= 3 && names[depth-3] == "ownerText" &&
- names[depth-2] == "runs" &&
- names[depth-1] == "text" {
+ if depth >= 3 &&
+ names[depth-3] == "ownerText" &&
+ names[depth-2] == "runs" &&
+ names[depth-1] == "text" {
item.ChannelTitle = t
}
if depth >= 6 &&
- names[depth-6] == "ownerText" &&
- names[depth-5] == "runs" &&
- names[depth-4] == "navigationEndpoint" &&
- names[depth-3] == "commandMetadata" &&
- names[depth-2] == "webCommandMetadata" &&
- names[depth-1] == "url" {
+ names[depth-6] == "ownerText" &&
+ names[depth-5] == "runs" &&
+ names[depth-4] == "navigationEndpoint" &&
+ names[depth-3] == "commandMetadata" &&
+ names[depth-2] == "webCommandMetadata" &&
+ names[depth-1] == "url" {
item.ChannelUrl = baseUrl + t
}
if depth >= 4 &&
- names[depth-4] == "videoRenderer" &&
- names[depth-3] == "thumbnail" &&
- names[depth-2] == "thumbnails" &&
- names[depth-1] == "url" {
- item.ThumbUrl = t
+ names[depth-4] == "videoRenderer" &&
+ names[depth-3] == "thumbnail" &&
+ names[depth-2] == "thumbnails" &&
+ names[depth-1] == "url" {
+ item.ThumbUrl = t
}
if depth >= 3 &&
- names[depth-3] == "videoRenderer" &&
- names[depth-2] == "publishedTimeText" &&
- names[depth-1] == "simpleText" {
- item.Published = t
+ names[depth-3] == "videoRenderer" &&
+ names[depth-2] == "publishedTimeText" &&
+ names[depth-1] == "simpleText" {
+ item.Published = t
}
if depth >= 5 &&
- names[depth-5] == "longBylineText" &&
- names[depth-4] == "runs" &&
- names[depth-3] == "navigationEndpoint" &&
- names[depth-2] == "browseEndpoint" &&
- names[depth-1] == "browseId" {
- item.ChannelId = t
+ names[depth-5] == "longBylineText" &&
+ names[depth-4] == "runs" &&
+ names[depth-3] == "navigationEndpoint" &&
+ names[depth-2] == "browseEndpoint" &&
+ names[depth-1] == "browseId" {
+ item.ChannelId = t
+ }
+ if depth >= 2 &&
+ names[depth-2] == "lengthText" &&
+ names[depth-1] == "simpleText" {
+ item.LengthText = t
}
isValue = false
}