Add YouTube search (#241)

This commit is contained in:
Asim Aslam
2021-10-25 11:37:05 +01:00
committed by GitHub
parent 5cee69a09e
commit 55464e8104
15 changed files with 901 additions and 4 deletions

2
youtube/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
youtube

3
youtube/Dockerfile Normal file
View File

@@ -0,0 +1,3 @@
FROM alpine
ADD youtube /youtube
ENTRYPOINT [ "/youtube" ]

28
youtube/Makefile Normal file
View File

@@ -0,0 +1,28 @@
GOPATH:=$(shell go env GOPATH)
.PHONY: init
init:
go get -u github.com/golang/protobuf/proto
go get -u github.com/golang/protobuf/protoc-gen-go
go get github.com/micro/micro/v3/cmd/protoc-gen-micro
go get github.com/micro/micro/v3/cmd/protoc-gen-openapi
.PHONY: api
api:
protoc --openapi_out=. --proto_path=. proto/youtube.proto
.PHONY: proto
proto:
protoc --proto_path=. --micro_out=. --go_out=:. proto/youtube.proto
.PHONY: build
build:
go build -o youtube *.go
.PHONY: test
test:
go test -v ./... -cover
.PHONY: docker
docker:
docker build . -t youtube:latest

6
youtube/README.md Normal file
View File

@@ -0,0 +1,6 @@
Search for YouTube videos
# Youtube Service
Simple search for YouTube videos. Find whatever you're looking for programmatically.

70
youtube/examples.json Normal file
View File

@@ -0,0 +1,70 @@
{
"search": [{
"title": "Search for videos",
"run_check": false,
"description": "Search for videos on youtube",
"request": {
"query": "donuts"
},
"response": {
"results": [
{
"id": "w6TxH8ha8XU",
"kind": "video",
"title": "Melt In Your Mouth Glazed Donuts Recipe ( How to make the BEST Yeast Donuts ! ) Homemade Donuts",
"description": "The Fluffiest Glazed Donuts Recipe ! Homemade Glazed Donuts ( Doughnut Recipe ) Learn how to make donuts that taste just like krispy kreme donuts if not ...",
"channel_id": "UCgmOd6sRQRK7QoSazOfaIjQ",
"channel_title": "Emma's Goodies",
"published_at": "2019-11-21T15:10:33Z",
"broadcasting": "none",
"url": "https://www.youtube.com/watch?v=w6TxH8ha8XU"
},
{
"id": "PpKoNGRXujY",
"kind": "video",
"title": "Making Easy Classic Donuts At Home",
"description": "Is it donuts or doughnuts? Either way we're making both homemade yeasted and sour cream old fashioned donuts. Eating these freshly fried and still a little ...",
"channel_id": "UChBEbMKI1eCcejTtmI32UEw",
"channel_title": "Joshua Weissman",
"published_at": "2020-02-19T19:09:59Z",
"broadcasting": "none",
"url": "https://www.youtube.com/watch?v=PpKoNGRXujY"
},
{
"id": "S4T0VVNm07o",
"kind": "video",
"title": "Best Doughnuts In Every State | 50 State Favorites",
"description": "We list the best places to get doughnuts from every state in the US. Many mom-and-pop shops just know how to make good classic doughnuts, while others are ...",
"channel_id": "UCwiTOchWeKjrJZw7S1H__1g",
"channel_title": "Food Insider",
"published_at": "2020-11-20T17:00:09Z",
"broadcasting": "none",
"url": "https://www.youtube.com/watch?v=S4T0VVNm07o"
},
{
"id": "OS1bu8p8GZk",
"kind": "video",
"title": "SOFT DONUT | SUGAR DONUT|How to make soft \u0026amp; good shape donut without donut cutter",
"description": "Bread Flour is another type of flour that has higher protein which produces more gluten, results a higher dough rise \u0026 becomes more elastic than what All ...",
"channel_id": "UChFNptV9OEEMziTPsgOXQAw",
"channel_title": "Yeast Mode",
"published_at": "2020-08-09T09:13:35Z",
"broadcasting": "none",
"url": "https://www.youtube.com/watch?v=OS1bu8p8GZk"
},
{
"id": "LYLRon4ppks",
"kind": "video",
"title": "Learn Colors with Donuts | Numbers Song | Kids Kitchen | Nursery Rhymes | Baby Songs | BabyBus",
"description": "BabyBus - Nursery Rhymes ▻ https://www.youtube.com/channel/UCpYye8D5fFMUPf9nSfgd4bA?sub_confirmation=1 BabyBus | Baby Panda Chef | Cooking ...",
"channel_id": "UCpYye8D5fFMUPf9nSfgd4bA",
"channel_title": "BabyBus - Nursery Rhymes",
"published_at": "2018-12-06T09:15:01Z",
"broadcasting": "none",
"url": "https://www.youtube.com/watch?v=LYLRon4ppks"
}
]
}
}]
}

3
youtube/generate.go Normal file
View File

@@ -0,0 +1,3 @@
package main
//go:generate make proto

View File

@@ -0,0 +1,66 @@
package handler
import (
"context"
"strings"
"github.com/micro/micro/v3/service/errors"
"github.com/micro/micro/v3/service/logger"
pb "github.com/micro/services/youtube/proto"
"google.golang.org/api/option"
"google.golang.org/api/youtube/v3"
)
type Youtube struct {
Client *youtube.Service
}
func New(apiKey string) *Youtube {
ctx := context.TODO()
yt, _ := youtube.NewService(ctx, option.WithAPIKey(apiKey))
return &Youtube{
Client: yt,
}
}
func (y *Youtube) Search(ctx context.Context, req *pb.SearchRequest, rsp *pb.SearchResponse) error {
if len(req.Query) == 0 {
return errors.BadRequest("youtube.search", "missing query")
}
resp, err := y.Client.Search.List([]string{"id", "snippet"}).Q(req.Query).MaxResults(25).Do()
if err != nil {
logger.Errorf("failed to search youtube for %v: %v", req.Query, err)
return errors.InternalServerError("youtube.search", "Failed to search for "+req.Query)
}
for _, item := range resp.Items {
var id, url string
kind := strings.Split(item.Id.Kind, "#")[1]
switch kind {
case "video":
id = item.Id.VideoId
url = "https://www.youtube.com/watch?v=" + id
case "playlist":
id = item.Id.PlaylistId
url = "https://www.youtube.com/playlist?list=" + id
case "channel":
id = item.Id.ChannelId
url = "https://www.youtube.com/channel/" + id
}
rsp.Results = append(rsp.Results, &pb.SearchResult{
Id: id,
Kind: kind,
Title: item.Snippet.Title,
ChannelId: item.Snippet.ChannelId,
ChannelTitle: item.Snippet.ChannelTitle,
Description: item.Snippet.Description,
PublishedAt: item.Snippet.PublishedAt,
Broadcasting: item.Snippet.LiveBroadcastContent,
Url: url,
})
}
return nil
}

35
youtube/main.go Normal file
View File

@@ -0,0 +1,35 @@
package main
import (
"github.com/micro/micro/v3/service"
"github.com/micro/micro/v3/service/config"
"github.com/micro/micro/v3/service/logger"
"github.com/micro/services/youtube/handler"
pb "github.com/micro/services/youtube/proto"
)
func main() {
// Create service
srv := service.New(
service.Name("youtube"),
service.Version("latest"),
)
// Setup google maps
c, err := config.Get("google.apikey")
if err != nil {
logger.Fatalf("Error loading config: %v", err)
}
apiKey := c.String("")
if len(apiKey) == 0 {
logger.Fatalf("Missing required config: google.apikey")
}
// Register handler
pb.RegisterYoutubeHandler(srv.Server(), handler.New(apiKey))
// Run service
if err := srv.Run(); err != nil {
logger.Fatal(err)
}
}

1
youtube/micro.mu Normal file
View File

@@ -0,0 +1 @@
service youtube

368
youtube/proto/youtube.pb.go Normal file
View File

@@ -0,0 +1,368 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1
// protoc v3.15.6
// source: proto/youtube.proto
package youtube
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type SearchResult struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// id of the result
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
// kind of result; "video", "channel", "playlist"
Kind string `protobuf:"bytes,2,opt,name=kind,proto3" json:"kind,omitempty"`
// title of the result
Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"`
// the result description
Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"`
// the channel id
ChannelId string `protobuf:"bytes,5,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"`
// the channel title
ChannelTitle string `protobuf:"bytes,6,opt,name=channel_title,json=channelTitle,proto3" json:"channel_title,omitempty"`
// published at time
PublishedAt string `protobuf:"bytes,7,opt,name=published_at,json=publishedAt,proto3" json:"published_at,omitempty"`
// if live broadcast then indicates activity.
// none, upcoming, live, completed
Broadcasting string `protobuf:"bytes,8,opt,name=broadcasting,proto3" json:"broadcasting,omitempty"`
// the associated url
Url string `protobuf:"bytes,9,opt,name=url,proto3" json:"url,omitempty"`
}
func (x *SearchResult) Reset() {
*x = SearchResult{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_youtube_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SearchResult) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SearchResult) ProtoMessage() {}
func (x *SearchResult) ProtoReflect() protoreflect.Message {
mi := &file_proto_youtube_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SearchResult.ProtoReflect.Descriptor instead.
func (*SearchResult) Descriptor() ([]byte, []int) {
return file_proto_youtube_proto_rawDescGZIP(), []int{0}
}
func (x *SearchResult) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *SearchResult) GetKind() string {
if x != nil {
return x.Kind
}
return ""
}
func (x *SearchResult) GetTitle() string {
if x != nil {
return x.Title
}
return ""
}
func (x *SearchResult) GetDescription() string {
if x != nil {
return x.Description
}
return ""
}
func (x *SearchResult) GetChannelId() string {
if x != nil {
return x.ChannelId
}
return ""
}
func (x *SearchResult) GetChannelTitle() string {
if x != nil {
return x.ChannelTitle
}
return ""
}
func (x *SearchResult) GetPublishedAt() string {
if x != nil {
return x.PublishedAt
}
return ""
}
func (x *SearchResult) GetBroadcasting() string {
if x != nil {
return x.Broadcasting
}
return ""
}
func (x *SearchResult) GetUrl() string {
if x != nil {
return x.Url
}
return ""
}
// Search for videos on YouTube
type SearchRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// Query to search for
Query string `protobuf:"bytes,1,opt,name=query,proto3" json:"query,omitempty"`
}
func (x *SearchRequest) Reset() {
*x = SearchRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_youtube_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SearchRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SearchRequest) ProtoMessage() {}
func (x *SearchRequest) ProtoReflect() protoreflect.Message {
mi := &file_proto_youtube_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SearchRequest.ProtoReflect.Descriptor instead.
func (*SearchRequest) Descriptor() ([]byte, []int) {
return file_proto_youtube_proto_rawDescGZIP(), []int{1}
}
func (x *SearchRequest) GetQuery() string {
if x != nil {
return x.Query
}
return ""
}
type SearchResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// List of results for the query
Results []*SearchResult `protobuf:"bytes,1,rep,name=results,proto3" json:"results,omitempty"`
}
func (x *SearchResponse) Reset() {
*x = SearchResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_youtube_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SearchResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SearchResponse) ProtoMessage() {}
func (x *SearchResponse) ProtoReflect() protoreflect.Message {
mi := &file_proto_youtube_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SearchResponse.ProtoReflect.Descriptor instead.
func (*SearchResponse) Descriptor() ([]byte, []int) {
return file_proto_youtube_proto_rawDescGZIP(), []int{2}
}
func (x *SearchResponse) GetResults() []*SearchResult {
if x != nil {
return x.Results
}
return nil
}
var File_proto_youtube_proto protoreflect.FileDescriptor
var file_proto_youtube_proto_rawDesc = []byte{
0x0a, 0x13, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x79, 0x6f, 0x75, 0x74, 0x75, 0x62, 0x65, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x79, 0x6f, 0x75, 0x74, 0x75, 0x62, 0x65, 0x22, 0x87,
0x02, 0x0a, 0x0c, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12,
0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12,
0x12, 0x0a, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6b,
0x69, 0x6e, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x03, 0x20, 0x01,
0x28, 0x09, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73,
0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b,
0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x63,
0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52,
0x09, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x68,
0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28,
0x09, 0x52, 0x0c, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x12,
0x21, 0x0a, 0x0c, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18,
0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, 0x64,
0x41, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x69,
0x6e, 0x67, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63,
0x61, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x09, 0x20,
0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22, 0x25, 0x0a, 0x0d, 0x53, 0x65, 0x61, 0x72,
0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x71, 0x75, 0x65,
0x72, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x22,
0x41, 0x0a, 0x0e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x12, 0x2f, 0x0a, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03,
0x28, 0x0b, 0x32, 0x15, 0x2e, 0x79, 0x6f, 0x75, 0x74, 0x75, 0x62, 0x65, 0x2e, 0x53, 0x65, 0x61,
0x72, 0x63, 0x68, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c,
0x74, 0x73, 0x32, 0x46, 0x0a, 0x07, 0x59, 0x6f, 0x75, 0x74, 0x75, 0x62, 0x65, 0x12, 0x3b, 0x0a,
0x06, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x12, 0x16, 0x2e, 0x79, 0x6f, 0x75, 0x74, 0x75, 0x62,
0x65, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x17, 0x2e, 0x79, 0x6f, 0x75, 0x74, 0x75, 0x62, 0x65, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x11, 0x5a, 0x0f, 0x2e, 0x2f,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x79, 0x6f, 0x75, 0x74, 0x75, 0x62, 0x65, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_proto_youtube_proto_rawDescOnce sync.Once
file_proto_youtube_proto_rawDescData = file_proto_youtube_proto_rawDesc
)
func file_proto_youtube_proto_rawDescGZIP() []byte {
file_proto_youtube_proto_rawDescOnce.Do(func() {
file_proto_youtube_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_youtube_proto_rawDescData)
})
return file_proto_youtube_proto_rawDescData
}
var file_proto_youtube_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_proto_youtube_proto_goTypes = []interface{}{
(*SearchResult)(nil), // 0: youtube.SearchResult
(*SearchRequest)(nil), // 1: youtube.SearchRequest
(*SearchResponse)(nil), // 2: youtube.SearchResponse
}
var file_proto_youtube_proto_depIdxs = []int32{
0, // 0: youtube.SearchResponse.results:type_name -> youtube.SearchResult
1, // 1: youtube.Youtube.Search:input_type -> youtube.SearchRequest
2, // 2: youtube.Youtube.Search:output_type -> youtube.SearchResponse
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_proto_youtube_proto_init() }
func file_proto_youtube_proto_init() {
if File_proto_youtube_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_proto_youtube_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SearchResult); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_youtube_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SearchRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_youtube_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SearchResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto_youtube_proto_rawDesc,
NumEnums: 0,
NumMessages: 3,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_proto_youtube_proto_goTypes,
DependencyIndexes: file_proto_youtube_proto_depIdxs,
MessageInfos: file_proto_youtube_proto_msgTypes,
}.Build()
File_proto_youtube_proto = out.File
file_proto_youtube_proto_rawDesc = nil
file_proto_youtube_proto_goTypes = nil
file_proto_youtube_proto_depIdxs = nil
}

View File

@@ -0,0 +1,93 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: proto/youtube.proto
package youtube
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
import (
context "context"
api "github.com/micro/micro/v3/service/api"
client "github.com/micro/micro/v3/service/client"
server "github.com/micro/micro/v3/service/server"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// Reference imports to suppress errors if they are not otherwise used.
var _ api.Endpoint
var _ context.Context
var _ client.Option
var _ server.Option
// Api Endpoints for Youtube service
func NewYoutubeEndpoints() []*api.Endpoint {
return []*api.Endpoint{}
}
// Client API for Youtube service
type YoutubeService interface {
Search(ctx context.Context, in *SearchRequest, opts ...client.CallOption) (*SearchResponse, error)
}
type youtubeService struct {
c client.Client
name string
}
func NewYoutubeService(name string, c client.Client) YoutubeService {
return &youtubeService{
c: c,
name: name,
}
}
func (c *youtubeService) Search(ctx context.Context, in *SearchRequest, opts ...client.CallOption) (*SearchResponse, error) {
req := c.c.NewRequest(c.name, "Youtube.Search", in)
out := new(SearchResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Youtube service
type YoutubeHandler interface {
Search(context.Context, *SearchRequest, *SearchResponse) error
}
func RegisterYoutubeHandler(s server.Server, hdlr YoutubeHandler, opts ...server.HandlerOption) error {
type youtube interface {
Search(ctx context.Context, in *SearchRequest, out *SearchResponse) error
}
type Youtube struct {
youtube
}
h := &youtubeHandler{hdlr}
return s.Handle(s.NewHandler(&Youtube{h}, opts...))
}
type youtubeHandler struct {
YoutubeHandler
}
func (h *youtubeHandler) Search(ctx context.Context, in *SearchRequest, out *SearchResponse) error {
return h.YoutubeHandler.Search(ctx, in, out)
}

View File

@@ -0,0 +1,42 @@
syntax = "proto3";
package youtube;
option go_package = "./proto;youtube";
service Youtube {
rpc Search(SearchRequest) returns (SearchResponse) {}
}
message SearchResult {
// id of the result
string id = 1;
// kind of result; "video", "channel", "playlist"
string kind = 2;
// title of the result
string title = 3;
// the result description
string description = 4;
// the channel id
string channel_id = 5;
// the channel title
string channel_title = 6;
// published at time
string published_at = 7;
// if live broadcast then indicates activity.
// none, upcoming, live, completed
string broadcasting = 8;
// the associated url
string url = 9;
}
// Search for videos on YouTube
message SearchRequest {
// Query to search for
string query = 1;
}
message SearchResponse {
// List of results for the query
repeated SearchResult results = 1;
}

6
youtube/publicapi.json Normal file
View File

@@ -0,0 +1,6 @@
{
"name": "youtube",
"icon": "📺",
"category": "video",
"display_name": "YouTube"
}