This commit is contained in:
r4 2021-07-11 15:03:22 +02:00
parent 4e0274d7eb
commit f240fff54e

View File

@ -38,8 +38,8 @@ func NewExtractor(respHdr http.Header) (*Extractor, error) {
func (d *Extractor) ReadBlock(r io.Reader, w io.Writer) (isFirst bool, err error) { func (d *Extractor) ReadBlock(r io.Reader, w io.Writer) (isFirst bool, err error) {
var musicData bytes.Buffer var musicData bytes.Buffer
// We want to write everything to the output, as well as musicData for // We want to write everything except the metadata to the output and to
// calculating the checksum. // musicData for calculating the checksum.
multi := io.MultiWriter(w, &musicData) multi := io.MultiWriter(w, &musicData)
// Read until the metadata chunk. The part that is read here is also what // Read until the metadata chunk. The part that is read here is also what
@ -57,8 +57,8 @@ func (d *Extractor) ReadBlock(r io.Reader, w io.Writer) (isFirst bool, err error
// Read metadata blocks. // Read metadata blocks.
if numBlocks > 0 { if numBlocks > 0 {
// Metadata is only actually stored in the first metadata chunk // Metadata is only actually stored in the first metadata chunk
// of a given file. Therefore, every metadata chunk with more than 1 // of a given file. Therefore, every metadata chunk with more than 0
// block always marks the beginning of a file. // blocks always marks the beginning of a file.
isBOF = true isBOF = true
// Each block is 16 bytes in size. Any excess bytes in the last block // Each block is 16 bytes in size. Any excess bytes in the last block
@ -84,8 +84,7 @@ func (d *Extractor) ReadBlock(r io.Reader, w io.Writer) (isFirst bool, err error
t = t[1 : len(t)-1] t = t[1 : len(t)-1]
if t == "Unknown" { if t == "Unknown" {
// If there is no stream title, use format: // If there is no stream title, use format:
// Unknown_<crc32 checksum> // Unknown_<crc32 checksum of first block>
// Where the checksum is only that of the first block.
sumStr := strconv.FormatInt(int64(crc32.ChecksumIEEE(musicData.Bytes())), 10) sumStr := strconv.FormatInt(int64(crc32.ChecksumIEEE(musicData.Bytes())), 10)
d.streamTitle = "Unknown_" + sumStr d.streamTitle = "Unknown_" + sumStr
} else { } else {