-
Notifications
You must be signed in to change notification settings - Fork 13
/
timeshift.go
43 lines (36 loc) · 1.02 KB
/
timeshift.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package radiko
import (
"context"
"path"
"time"
"github.com/yyoshiki41/go-radiko/internal/m3u8"
"github.com/yyoshiki41/go-radiko/internal/util"
)
// TimeshiftPlaylistM3U8 returns uri.
func (c *Client) TimeshiftPlaylistM3U8(ctx context.Context, stationID string, start time.Time) (string, error) {
prog, err := c.GetProgramByStartTime(ctx, stationID, start)
if err != nil {
return "", err
}
apiEndpoint := apiPath(apiV2, "ts/playlist.m3u8")
req, err := c.newRequest(ctx, "POST", apiEndpoint, &Params{
query: map[string]string{
"station_id": stationID,
"ft": prog.Ft,
"to": prog.To,
"l": "15", // must?
},
setAuthToken: true,
})
resp, err := c.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
return m3u8.GetURI(resp.Body)
}
// GetTimeshiftURL returns a timeshift url for web browser.
func GetTimeshiftURL(stationID string, start time.Time) string {
endpoint := path.Join("#!/ts", stationID, util.Datetime(start))
return defaultEndpoint + "/" + endpoint
}