@@ -49,10 +49,20 @@ func (t *TwitchBuilder) Build(_ctx context.Context, cfg *feed.Config) (*model.Fe
4949 feed .CoverArt = user .ProfileImageURL
5050 feed .PubDate = user .CreatedAt .Time
5151
52+ isStreaming := false
53+ streamID := ""
54+ streams , err := t .client .GetStreams (& helix.StreamsParams {
55+ UserIDs : []string {user .ID },
56+ })
57+ if len (streams .Data .Streams ) > 0 {
58+ isStreaming = true
59+ streamID = streams .Data .Streams [0 ].ID
60+ }
61+
5262 videos , err := t .client .GetVideos (& helix.VideosParams {
5363 UserID : user .ID ,
5464 Period : "all" ,
55- Type : "all " ,
65+ Type : "archive " ,
5666 Sort : "time" ,
5767 First : 10 ,
5868 })
@@ -63,35 +73,39 @@ func (t *TwitchBuilder) Build(_ctx context.Context, cfg *feed.Config) (*model.Fe
6373 var added = 0
6474 for _ , video := range videos .Data .Videos {
6575
66- date , err := time .Parse (time .RFC3339 , video .PublishedAt )
67- if err != nil {
68- return nil , errors .Wrapf (err , "cannot parse PublishedAt time: %s" , video .PublishedAt )
69- }
70-
71- replacer := strings .NewReplacer ("%{width}" , "300" , "%{height}" , "300" )
72- thumbnailUrl := replacer .Replace (video .ThumbnailURL )
73-
74- duration , err := time .ParseDuration (video .Duration )
75- if err != nil {
76- return nil , errors .Wrapf (err , "cannot parse duration: %s" , video .Duration )
77- }
78- durationSeconds := int64 (duration .Seconds ())
79-
80- feed .Episodes = append (feed .Episodes , & model.Episode {
81- ID : video .ID ,
82- Title : fmt .Sprintf ("%s (%s)" , video .Title , date ),
83- Description : video .Description ,
84- Thumbnail : thumbnailUrl ,
85- Duration : durationSeconds ,
86- Size : durationSeconds * 33013 , // Very rough estimate
87- VideoURL : video .URL ,
88- PubDate : date ,
89- Status : model .EpisodeNew ,
90- })
91-
92- added ++
93- if added >= feed .PageSize {
94- return feed , nil
76+ // Do not add the video of an ongoing stream because it will be incomplete
77+ if ! isStreaming || video .StreamID != streamID {
78+
79+ date , err := time .Parse (time .RFC3339 , video .PublishedAt )
80+ if err != nil {
81+ return nil , errors .Wrapf (err , "cannot parse PublishedAt time: %s" , video .PublishedAt )
82+ }
83+
84+ replacer := strings .NewReplacer ("%{width}" , "300" , "%{height}" , "300" )
85+ thumbnailUrl := replacer .Replace (video .ThumbnailURL )
86+
87+ duration , err := time .ParseDuration (video .Duration )
88+ if err != nil {
89+ return nil , errors .Wrapf (err , "cannot parse duration: %s" , video .Duration )
90+ }
91+ durationSeconds := int64 (duration .Seconds ())
92+
93+ feed .Episodes = append (feed .Episodes , & model.Episode {
94+ ID : video .ID ,
95+ Title : fmt .Sprintf ("%s (%s)" , video .Title , date ),
96+ Description : video .Description ,
97+ Thumbnail : thumbnailUrl ,
98+ Duration : durationSeconds ,
99+ Size : durationSeconds * 33013 , // Very rough estimate
100+ VideoURL : video .URL ,
101+ PubDate : date ,
102+ Status : model .EpisodeNew ,
103+ })
104+
105+ added ++
106+ if added >= feed .PageSize {
107+ return feed , nil
108+ }
95109 }
96110
97111 }
0 commit comments