mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Improve file size estimation
This commit is contained in:
@@ -17,6 +17,8 @@ const (
|
|||||||
maxYoutubeResults = 50
|
maxYoutubeResults = 50
|
||||||
hdBytesPerSecond = 350000
|
hdBytesPerSecond = 350000
|
||||||
ldBytesPerSecond = 100000
|
ldBytesPerSecond = 100000
|
||||||
|
lowAudioBytesPerSecond = 48000 / 8
|
||||||
|
highAudioBytesPerSecond = 128000 / 8
|
||||||
)
|
)
|
||||||
|
|
||||||
type apiKey string
|
type apiKey string
|
||||||
@@ -184,24 +186,22 @@ func (yt *YouTubeBuilder) queryFeed(feed *api.Feed) (*itunes.Podcast, string, er
|
|||||||
return nil, "", errors.New("unsupported link format")
|
return nil, "", errors.New("unsupported link format")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (yt *YouTubeBuilder) getVideoSize(definition string, duration int64, fmt api.Format) int64 {
|
// Video size information requires 1 additional call for each video (1 feed = 50 videos = 50 calls),
|
||||||
// Video size information requires 1 additional call for each video (1 feed = 50 videos = 50 calls),
|
// which is too expensive, so get approximated size depending on duration and definition params
|
||||||
// which is too expensive, so get approximated size depending on duration and definition params
|
func (yt *YouTubeBuilder) getSize(duration int64, feed *api.Feed) int64 {
|
||||||
var size int64 = 0
|
if feed.Format == api.AudioFormat {
|
||||||
|
if feed.Quality == api.HighQuality {
|
||||||
if definition == "hd" {
|
return highAudioBytesPerSecond * duration
|
||||||
size = duration * hdBytesPerSecond
|
|
||||||
} else {
|
} else {
|
||||||
size = duration * ldBytesPerSecond
|
return lowAudioBytesPerSecond * duration
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if feed.Quality == api.HighQuality {
|
||||||
|
return duration * hdBytesPerSecond
|
||||||
|
} else {
|
||||||
|
return duration * ldBytesPerSecond
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some podcasts are coming in with exactly double the actual runtime and with the second half just silence.
|
|
||||||
// https://github.com/mxpv/Podsync/issues/6
|
|
||||||
if fmt == api.AudioFormat {
|
|
||||||
size /= 2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return size
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (yt *YouTubeBuilder) queryVideoDescriptions(ids []string, feed *api.Feed, podcast *itunes.Podcast) error {
|
func (yt *YouTubeBuilder) queryVideoDescriptions(ids []string, feed *api.Feed, podcast *itunes.Podcast) error {
|
||||||
@@ -245,8 +245,7 @@ func (yt *YouTubeBuilder) queryVideoDescriptions(ids []string, feed *api.Feed, p
|
|||||||
item.AddDuration(seconds)
|
item.AddDuration(seconds)
|
||||||
|
|
||||||
// Add download links
|
// Add download links
|
||||||
|
size := yt.getSize(seconds, feed)
|
||||||
size := yt.getVideoSize(video.ContentDetails.Definition, seconds, feed.Format)
|
|
||||||
item.AddEnclosure(makeEnclosure(feed, video.Id, size))
|
item.AddEnclosure(makeEnclosure(feed, video.Id, size))
|
||||||
|
|
||||||
// podcast.AddItem requires description to be not empty, use workaround
|
// podcast.AddItem requires description to be not empty, use workaround
|
||||||
|
Reference in New Issue
Block a user