@@ -6,17 +6,19 @@ import (
66 "strconv"
77 "strings"
88
9+ "github.com/wader/ydls/internal/humnum"
910 "github.com/wader/ydls/internal/timerange"
1011)
1112
1213// RequestOptions request options
1314type RequestOptions struct {
14- MediaRawURL string // youtubedl media URL
15- Format * Format // output format
16- Codecs []string // force codecs
17- Retranscode bool // force retranscode even if same input codec
18- TimeRange timerange.TimeRange // time range limit
19- Items uint // feed item count limit
15+ MediaRawURL string // youtubedl media URL
16+ Format * Format // output format
17+ Codecs []string // force codecs
18+ Retranscode bool // force retranscode even if same input codec
19+ TimeRange timerange.TimeRange // time range limit
20+ Items uint // feed item count limit
21+ HTTPChunkSize uint // youtubedl http chunk size option
2022}
2123
2224// NewRequestOptionsFromQuery /?url=...&format=...
@@ -70,13 +72,24 @@ func NewRequestOptionsFromQuery(v url.Values, formats Formats) (RequestOptions,
7072 items = uint (itemsN )
7173 }
7274
75+ httpChunkSize := uint (0 )
76+ httpChunkSizeStr := v .Get ("httpchunksize" )
77+ if httpChunkSizeStr != "" {
78+ httpChunkSizeN , httpChunkSizeNErr := humnum .Atoi (httpChunkSizeStr )
79+ if httpChunkSizeNErr != nil {
80+ return RequestOptions {}, fmt .Errorf ("invalid HTTP chunk size" )
81+ }
82+ httpChunkSize = uint (httpChunkSizeN )
83+ }
84+
7385 return RequestOptions {
74- MediaRawURL : mediaRawURL ,
75- Format : format ,
76- Codecs : codecs ,
77- Retranscode : v .Get ("retranscode" ) != "" ,
78- TimeRange : timeRange ,
79- Items : items ,
86+ MediaRawURL : mediaRawURL ,
87+ Format : format ,
88+ Codecs : codecs ,
89+ Retranscode : v .Get ("retranscode" ) != "" ,
90+ TimeRange : timeRange ,
91+ Items : items ,
92+ HTTPChunkSize : httpChunkSize ,
8093 }, nil
8194}
8295
@@ -173,7 +186,6 @@ func NewRequestOptionsFromOpts(opts []string, formats Formats) (RequestOptions,
173186 return RequestOptions {}, fmt .Errorf ("invalid items count" )
174187 }
175188 r .Items = uint (itemsN )
176- strconv .ParseUint ("" , 10 , 32 )
177189 } else if _ , ok := codecNames [opt ]; ok {
178190 r .Codecs = append (r .Codecs , opt )
179191 } else if tr , trErr := timerange .NewTimeRangeFromString (opt ); trErr == nil {
@@ -206,5 +218,8 @@ func (r RequestOptions) QueryValues() url.Values {
206218 if r .Items > 0 {
207219 v .Set ("items" , strconv .Itoa (int (r .Items )))
208220 }
221+ if r .HTTPChunkSize != 0 {
222+ v .Set ("httpchunksize" , strconv .Itoa (int (r .HTTPChunkSize )))
223+ }
209224 return v
210225}
0 commit comments