Skip to content

Commit

Permalink
Feat: impl emby playbackinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed May 7, 2024
1 parent b088421 commit 863ca90
Show file tree
Hide file tree
Showing 8 changed files with 885 additions and 324 deletions.
665 changes: 447 additions & 218 deletions api/emby/emby.pb.go

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion api/emby/emby.proto
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ service Emby {
body : "*"
};
}

rpc PlaybackInfo(PlaybackInfoReq) returns (PlaybackInfoResp) {
option (google.api.http) = {
post : "/emby/Playback/Info"
body : "*"
};
}
}

message LoginReq {
Expand Down Expand Up @@ -111,6 +118,8 @@ message MediaSourceInfo {
uint64 defaultSubtitleStreamIndex = 6;
uint64 defaultAudioStreamIndex = 7;
repeated MediaStreamInfo mediaStreamInfo = 8;
string directPlayUrl = 9;
string transcodingUrl = 10;
}

message Item {
Expand Down Expand Up @@ -200,4 +209,19 @@ message LogoutReq {
string token = 2;
}

message Empty {}
message Empty {}

message PlaybackInfoReq {
string host = 1;
string token = 2;
string userId = 3;
string itemId = 4;
string mediaSourceId = 5;
string audioStreamIndex = 6;
string subtitleStreamIndex = 7;
}

message PlaybackInfoResp {
string playSessionID = 1;
repeated MediaSourceInfo mediaSourceInfo = 2;
}
37 changes: 37 additions & 0 deletions api/emby/emby_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions api/emby/emby_http.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,24 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/api.emby.LoginResp'
/emby/Playback/Info:
post:
tags:
- Emby
operationId: Emby_PlaybackInfo
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/api.emby.PlaybackInfoReq'
required: true
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/api.emby.PlaybackInfoResp'
/emby/Sessions/Logout:
post:
tags:
Expand Down Expand Up @@ -1202,6 +1220,10 @@ components:
type: array
items:
$ref: '#/components/schemas/api.emby.MediaStreamInfo'
directPlayUrl:
type: string
transcodingUrl:
type: string
api.emby.MediaStreamInfo:
type: object
properties:
Expand Down Expand Up @@ -1230,6 +1252,32 @@ components:
type: string
path:
type: string
api.emby.PlaybackInfoReq:
type: object
properties:
host:
type: string
token:
type: string
userId:
type: string
itemId:
type: string
mediaSourceId:
type: string
audioStreamIndex:
type: string
subtitleStreamIndex:
type: string
api.emby.PlaybackInfoResp:
type: object
properties:
playSessionID:
type: string
mediaSourceInfo:
type: array
items:
$ref: '#/components/schemas/api.emby.MediaSourceInfo'
api.emby.SystemInfoReq:
type: object
properties:
Expand Down
76 changes: 50 additions & 26 deletions service/emby/emby.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,43 @@ func (a *EmbyService) Me(ctx context.Context, req *pb.MeReq) (*pb.MeResp, error)
}, nil
}

func mediaStreamInfo2pb(msi []emby.MediaStreams) []*pb.MediaStreamInfo {
var pbmsi []*pb.MediaStreamInfo = make([]*pb.MediaStreamInfo, len(msi))
for i, msi := range msi {
pbmsi[i] = &pb.MediaStreamInfo{
Codec: msi.Codec,
Language: msi.Language,
Type: msi.Type,
Title: msi.Title,
DisplayTitle: msi.DisplayTitle,
DisplayLanguage: msi.DisplayLanguage,
IsDefault: msi.IsDefault,
Index: msi.Index,
Protocol: msi.Protocol,
}
}
return pbmsi
}

func mediaSources2pb(ms []emby.MediaSources) []*pb.MediaSourceInfo {
var pbms []*pb.MediaSourceInfo = make([]*pb.MediaSourceInfo, len(ms))
for i, msi := range ms {
pbms[i] = &pb.MediaSourceInfo{
Id: msi.ID,
Name: msi.Name,
Path: msi.Path,
Protocol: msi.Protocol,
Container: msi.Container,
DefaultSubtitleStreamIndex: msi.DefaultSubtitleStreamIndex,
DefaultAudioStreamIndex: msi.DefaultAudioStreamIndex,
MediaStreamInfo: mediaStreamInfo2pb(msi.MediaStreams),
DirectPlayUrl: msi.DirectStreamURL,
TranscodingUrl: msi.TranscodingURL,
}
}
return pbms
}

func item2pb(item *emby.Items) *pb.Item {
pi := &pb.Item{
Id: item.ID,
Expand All @@ -56,34 +93,9 @@ func item2pb(item *emby.Items) *pb.Item {
SeasonId: item.SeasonID,
SeriesName: item.SeriesName,
SeriesId: item.SeriesID,
MediaSourceInfo: make([]*pb.MediaSourceInfo, len(item.MediaSources)),
MediaSourceInfo: mediaSources2pb(item.MediaSources),
CollectionType: item.CollectionType,
}
for i, msi := range item.MediaSources {
pi.MediaSourceInfo[i] = &pb.MediaSourceInfo{
Id: msi.ID,
Name: msi.Name,
Path: msi.Path,
Protocol: msi.Protocol,
Container: msi.Container,
DefaultSubtitleStreamIndex: msi.DefaultSubtitleStreamIndex,
DefaultAudioStreamIndex: msi.DefaultAudioStreamIndex,
MediaStreamInfo: make([]*pb.MediaStreamInfo, len(msi.MediaStreams)),
}
for j, msi := range msi.MediaStreams {
pi.MediaSourceInfo[i].MediaStreamInfo[j] = &pb.MediaStreamInfo{
Codec: msi.Codec,
Language: msi.Language,
Type: msi.Type,
Title: msi.Title,
DisplayTitle: msi.DisplayTitle,
DisplayLanguage: msi.DisplayLanguage,
IsDefault: msi.IsDefault,
Index: msi.Index,
Protocol: msi.Protocol,
}
}
}
return pi
}

Expand Down Expand Up @@ -325,3 +337,15 @@ func (a *EmbyService) Logout(ctx context.Context, req *pb.LogoutReq) (*pb.Empty,
}
return &pb.Empty{}, nil
}

func (a *EmbyService) PlaybackInfo(ctx context.Context, req *pb.PlaybackInfoReq) (*pb.PlaybackInfoResp, error) {
cli := emby.NewClient(req.Host, emby.WithContext(ctx), emby.WithKey(req.Token), emby.WithUserID(req.UserId))
r, err := cli.UserPlaybackInfo(req.ItemId)
if err != nil {
return nil, err
}
return &pb.PlaybackInfoResp{
PlaySessionID: r.PlaySessionID,
MediaSourceInfo: mediaSources2pb(r.MediaSources),
}, nil
}
Loading

0 comments on commit 863ca90

Please sign in to comment.