import GENRES from '../constants/genres' ; import { IBytes , IID3V1Tag } from '../interface' ; import { readBytesToUTF8 } from '../utils' ; const V1_MIN_LENGTH = 128 ; description param bytes export default function parseV1Data ( bytes ) { if ( ! bytes || bytes . length < V1_MIN_LENGTH ) { return false ; } bytes = bytes . slice ( bytes . length - V1_MIN_LENGTH ) ; const tags = { version : { major : 1 , minor : 0 , } , } ; const flag = readBytesToUTF8 ( bytes , 3 ) ; if ( flag !== 'TAG' ) { return false ; } const reWhiteSpace = /(^[\s0]+|[\s0]+$)/ ; tags . title = readBytesToUTF8 ( bytes . slice ( 3 ) , 30 ) . replace ( reWhiteSpace , '' ) ; tags . artist = readBytesToUTF8 ( bytes . slice ( 33 ) , 30 ) . replace ( reWhiteSpace , '' ) ; tags . album = readBytesToUTF8 ( bytes . slice ( 63 ) , 30 ) . replace ( reWhiteSpace , '' ) ; tags . year = readBytesToUTF8 ( bytes . slice ( 93 ) , 4 ) . replace ( reWhiteSpace , '' ) ; if ( bytes [ 125 ] === 0 ) { tags . comments = readBytesToUTF8 ( bytes . slice ( 97 ) , 28 ) . replace ( reWhiteSpace , '' ) ; tags . version . minor = 1 ; tags . track = bytes [ 126 ] ; } else { tags . comments = readBytesToUTF8 ( bytes . slice ( 97 ) , 30 ) . replace ( reWhiteSpace , '' ) ; } tags . genre = GENRES [ bytes [ 127 ] ] || '' ; return tags ; }