Skip to content

Instantly share code, notes, and snippets.

@oq-x
Last active December 1, 2024 15:07
Show Gist options
  • Save oq-x/2552b11c51dadf3814174fb1bbc734c7 to your computer and use it in GitHub Desktop.
Save oq-x/2552b11c51dadf3814174fb1bbc734c7 to your computer and use it in GitHub Desktop.
Tokyvideo.com API

Search AJAX (limited video information): GET https://api.tokyvideo.com/search-ajax?q=someQuery&wr=false&lang=en_US

Search: POST https://api.tokyvideo.com/search-videos (json body: {"term":"someQuery"})

Get Video (using internal numeral id): GET https://api.tokyvideo.com/video/VIDEOID

To retrieve the numeral id from the path (https://www.tokyvideo.com/video/video-path), find the first script with type=application/ld+json, as it contains a bunch of json info

golang example:

type videoObject struct {
	Description string `json:"description"`
	EmbedUrl    string `json:"embedUrl"`
}
func (a api) Video(id string) (source.Video, error) {
	res, err := http.Get("https://tokyvideo.com/video/" + id)
	if err != nil {
		return source.Video{}, err
	}
	doc, err := goquery.NewDocumentFromReader(res.Body)
	if err != nil {
		return source.Video{}, err
	}

	s := doc.Find(`script[type="application/ld+json"]`).First().Text()

	var videoObj []videoObject
	if err := json.Unmarshal([]byte(s), &videoObj); err != nil {
		return source.Video{}, err
	}

	internalVideoId := videoObj[0].EmbedUrl[strings.LastIndex(videoObj[0].EmbedUrl, "/")+1:]
	description := videoObj[0].Description

	v, err := a.VideoByInternalId(internalVideoId)
	v.Description = description

	return v, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment