📄 id3.c
字号:
unsigned long ulValueLength){ unsigned long ulFlags, ulValid, ulTagLength, ulTemp, ulIdx; // // First, see if we have an ID3v2 tag. Seek to the beginning of the file. // FSSeek(pFile, ulStart & ~511); // // Read 1K of data from the file. // ulValid = FSRead(pFile, pucBuffer, 1024); // // Is there an ID3v2 tag at the beginning of the file? // if(ID3IsV2Tag(pucBuffer + (ulStart & 511))) { // // Move to the first byte of the tag header. // ulStart &= 511; // // Get the flags from the ID3v2 tag header. // ulFlags = pucBuffer[ulStart + 5]; // // Get the length of the ID3v2 tag. // ulTagLength = (pucBuffer[ulStart + 6] << 21) | (pucBuffer[ulStart + 7] << 14) | (pucBuffer[ulStart + 8] << 7) | pucBuffer[ulStart + 9]; // // Move to the first byte after the tag header. // ulStart += 10; // // Decrement the tag length by the number of bytes that have already // been read into the buffer. // if(ulTagLength > (ulValid - ulStart)) { ulTagLength -= ulValid - ulStart; } else { ulValid = ulStart + ulTagLength; ulTagLength = 0; } // // If we have unsynchronization in the tag, then unsynchronize the // current portion of the tag. // if(ulFlags & 0x80) { ID3UnsynchronizeTag(pucBuffer, ulStart, &ulValid); } // // Start looking for the specified tag. // while(ulTagLength || (ulStart < ulValid)) { // // See if there is enough data in the buffer. // if(((ulStart + 10) > ulValid) && ulTagLength) { // // Get more data from the file. // ID3GetMoreTagData(pFile, pucBuffer, &ulStart, &ulValid, &ulTagLength, ulFlags); } // // If the name of this frame is all zeros, then we have reached // the padding at the end of the tag. // if((pucBuffer[ulStart] == 0) && (pucBuffer[ulStart + 1] == 0) && (pucBuffer[ulStart + 2] == 0) && (pucBuffer[ulStart + 3] == 0)) { break; } // // See if the name of this frame matches the frame we are looking // for. // if((pucBuffer[ulStart] == pcTag[0]) && (pucBuffer[ulStart + 1] == pcTag[1]) && (pucBuffer[ulStart + 2] == pcTag[2]) && (pucBuffer[ulStart + 3] == pcTag[3])) { // // If this frame contains compression or encryption, then we // do can not handle it. // if(!(pucBuffer[ulStart + 9] & 0xc0)) { // // Is this a text frame (Txxx)? // if(pcTag[0] == 'T') { // // Get the length of this frame. // ulTemp = ((pucBuffer[ulStart + 4] << 24) | (pucBuffer[ulStart + 5] << 16) | (pucBuffer[ulStart + 6] << 8) | pucBuffer[ulStart + 7]) - 1; // // If this frame has a grouping identity, then we need // to skip the grouping id byte. // if(pucBuffer[ulStart + 9] & 0x20) { ulStart += 11; ulTemp--; } else { ulStart += 10; } // // Get more data from the file. // ID3GetMoreTagData(pFile, pucBuffer, &ulStart, &ulValid, &ulTagLength, ulFlags); // // Extract the string if the text encoding is ASCII. // if(pucBuffer[ulStart] == 0) { // // Loop through the characters in the string, // converting each to Unicode as it is copied into // the output buffer. // for(ulIdx = 0; (ulIdx < (ulValueLength - 1)) && (ulIdx < ulTemp); ulIdx++) { pusValue[ulIdx] = pucBuffer[ulStart + ulIdx + 1]; } // // Null terminate the string. // pusValue[ulIdx] = 0; // // Success. // return(1); } // // Extract the string if the text encoding is Unicode. // if(pucBuffer[ulStart] == 1) { // // Copy the string from the tag frame. // memcpy(pusValue, pucBuffer + ulStart + 3, ulValueLength * 2); // // See if the string is encoded in little-endian // or big-endian format. // if((pucBuffer[ulStart + 1] == 0xfe) && (pucBuffer[ulStart + 2] == 0xff)) { // // The string is encoded in big-endian format, // so we must byte swap each character in the // string. // for(ulIdx = 0; ulIdx < ulValueLength; ulIdx++) { pusValue[ulIdx] = (pusValue[ulIdx] >> 8) | (pusValue[ulIdx] << 8); } } // // Null terminate that string at the appropriate // place, either at the end of the string, or at // the end of the buffer used to hold the string, // whichever is less. // if((ulTemp / 2) < ulValueLength) { pusValue[(ulTemp / 2) - 1] = 0; } else { pusValue[ulValueLength - 1] = 0; } // // Success. // return(1); } } } } // // Get the length of this frame. // ulTemp = ((pucBuffer[ulStart + 4] << 24) | (pucBuffer[ulStart + 5] << 16) | (pucBuffer[ulStart + 6] << 8) | pucBuffer[ulStart + 7]) + 10; // // Skip this frame. // ulStart += ulTemp; } } // // Now, see if we have an ID3v1 tag. Seek to the end of the file (the // length has already been reduced by 128 bytes if the tag is present). // FSSeek(pFile, (ulLength - 128) & ~511); // // Read 1K of data from the file. // FSRead(pFile, pucBuffer, 1024); // // Is there an ID3v1 tag at the end of the file? // if(ID3IsV1Tag(pucBuffer + ((ulLength - 128) & 511))) { // // Should we return the artist name (TPE1)? // if(memcmp(pcTag, "TPE1", 4) == 0) { // // Get the artist name from the ID3v1 tag. // ulTemp = ulValueLength < 30 ? ulValueLength : 30; for(ulIdx = 0; ulIdx < ulTemp; ulIdx++) { pusValue[ulIdx] = pucBuffer[((ulLength - 128) & 511) + ulIdx + 33]; } } // // Should we return the album name (TALB)? // else if(memcmp(pcTag, "TALB", 4) == 0) { // // Get the album name from the ID3v1 tag. // ulTemp = ulValueLength < 30 ? ulValueLength : 30; for(ulIdx = 0; ulIdx < ulTemp; ulIdx++) { pusValue[ulIdx] = pucBuffer[((ulLength - 128) & 511) + ulIdx + 63]; } } // // Should we return the song name (TIT2)? // else if(memcmp(pcTag, "TIT2", 4) == 0) { // // Get the song name from the ID3v1 tag. // ulTemp = ulValueLength < 30 ? ulValueLength : 30; for(ulIdx = 0; ulIdx < ulTemp; ulIdx++) { pusValue[ulIdx] = pucBuffer[((ulLength - 128) & 511) + ulIdx + 3]; } } // // Should we return the year (TYER)? // else if(memcmp(pcTag, "TYER", 4) == 0) { // // Get the year from the ID3v1 tag. // ulTemp = ulValueLength < 4 ? ulValueLength : 4; for(ulIdx = 0; ulIdx < ulTemp; ulIdx++) { pusValue[ulIdx] = pucBuffer[((ulLength - 128) & 511) + ulIdx + 93]; } } // // For all other frame types, they either do not exist in an ID3v1 tag // or we do not know how to handle them. // else { // // Return a failure. // return(0); } // // Null terminate the string and remove any trailing spaces that may be // in the string. // while(pusValue[ulTemp - 1] == ' ') { pusValue[--ulTemp] = '\0'; } // // Success. // return(1); } // // There are no ID3 tags, so we could not get the specified tag value. // return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -