2021-09-13 18:58:28 +00:00
|
|
|
package media
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-09-14 20:26:46 +00:00
|
|
|
"time"
|
2021-11-02 18:03:26 +00:00
|
|
|
|
|
|
|
"github.com/google/uuid"
|
2021-09-13 18:58:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const SizeOfInt16 = 2
|
|
|
|
|
2021-09-14 20:26:46 +00:00
|
|
|
type Audio struct {
|
2021-11-29 11:46:33 +00:00
|
|
|
ContentLength int64
|
|
|
|
Channels int
|
2021-10-27 19:34:59 +00:00
|
|
|
// ApproxFrames is used during initial processing when a precise frame count
|
|
|
|
// cannot be determined. Prefer Frames in all other cases.
|
2021-11-29 11:46:33 +00:00
|
|
|
ApproxFrames int64
|
|
|
|
Frames int64
|
|
|
|
SampleRate int
|
|
|
|
YoutubeItag int
|
|
|
|
MimeType string
|
2021-09-14 20:26:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Video struct {
|
2021-11-29 11:46:33 +00:00
|
|
|
ContentLength int64
|
|
|
|
Duration time.Duration
|
2021-10-27 19:34:59 +00:00
|
|
|
// not sure if this are needed any more?
|
2021-11-29 11:46:33 +00:00
|
|
|
ThumbnailWidth int
|
|
|
|
ThumbnailHeight int
|
|
|
|
YoutubeItag int
|
|
|
|
MimeType string
|
2021-09-14 20:26:46 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 18:58:28 +00:00
|
|
|
// MediaSet represents the media and metadata associated with a single media
|
|
|
|
// resource (for example, a YouTube video).
|
|
|
|
type MediaSet struct {
|
2021-11-02 18:03:26 +00:00
|
|
|
Audio Audio `json:"audio"`
|
|
|
|
Video Video `json:"video"`
|
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
YoutubeID string `json:"youtube_id"`
|
2021-09-13 18:58:28 +00:00
|
|
|
|
2021-11-16 06:48:30 +00:00
|
|
|
exists bool
|
2021-09-13 18:58:28 +00:00
|
|
|
}
|
|
|
|
|
2021-09-25 17:00:19 +00:00
|
|
|
// New builds a new MediaSet with the given ID.
|
2021-11-01 05:28:40 +00:00
|
|
|
func NewMediaSet(youtubeID string) *MediaSet {
|
|
|
|
return &MediaSet{YoutubeID: youtubeID}
|
2021-09-25 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2021-09-14 20:26:46 +00:00
|
|
|
// TODO: pass io.Readers/Writers instead of strings.
|
2021-11-01 05:28:40 +00:00
|
|
|
func (m *MediaSet) RawAudioPath() string { return fmt.Sprintf("cache/%s.raw", m.YoutubeID) }
|
|
|
|
func (m *MediaSet) EncodedAudioPath() string { return fmt.Sprintf("cache/%s.m4a", m.YoutubeID) }
|
|
|
|
func (m *MediaSet) VideoPath() string { return fmt.Sprintf("cache/%s.mp4", m.YoutubeID) }
|
|
|
|
func (m *MediaSet) ThumbnailPath() string { return fmt.Sprintf("cache/%s.jpg", m.YoutubeID) }
|
|
|
|
func (m *MediaSet) MetadataPath() string { return fmt.Sprintf("cache/%s.json", m.YoutubeID) }
|