Modify wma tags in batches [original code-Modify from wmfsdk]

Source: Internet
Author: User

Modify wma tags in batches [original code-Modify from wmfsdk]
The Code was written when I made my own music site. I did not check it carefully and used it to modify the wma of nearly 70 thousand. No error was found in mp3. You can modify the parameters by yourself.
Efficiency: it takes more than three hours for 70 Gbit/s of 50 thousand music data to be optimized.
Compiling environment: vc6.0 + WMFSDK9 (http://msdn.microsoft.com/library/default.asp? Url =/library/en-us/wmform95/htm/aboutthewindowsmediaformatsdk. asp)
Note: before using it, please do the experiment first. I am not responsible for breaking your music data ~~~
Tip: in fact, the program itself is not very well written. You can embed the lyrics including dynamic lyrics in wma, and adding scripts to wma can prevent connection theft, give it to the person you need!
Contains three files: wmatag. cpp, config.txt, and input.txt.
Config.txt (for details, see the MSDN http://msdn.microsoft.com/library/default.asp? Url =/library/en-us/wmform95/htm/attributelist. asp) Copy codeThe Code is as follows: FileName
Title
Author
Copyright
CopyrightURL
Description
WM/AlbumTitle
WM/Composer
WM/Lyrics

Input.txt (this file is your batch modification information and needs to be generated from the database)Copy codeThe Code is as follows: j: \ music \ abc \ xxxyyy.wma | 16th Cash pop music contest-Lazy | miscellaneous collection | copyright belongs to the original author, and all music is collected from the Internet. | Http://www.yoursite.com | yoursite... | 16th Cash pop music contest | yoursite | lyrics
J: \ music \ abd \ yyyyy.wma | I'm worried about it _ pre-purchased Limited Edition-right-on the left shoes-preemptive trial version | Lu Yi | copyright belongs to the original author, and all music is collected from the Internet. | Http://www.yoursite.com | xxxyy | Yi do not do _ pre-purchase limited edition | yoursite | lyrics
...

Wmatag. cppCopy codeThe Code is as follows: # include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Include <tchar. h>
# Include <stdio. h>
# Include <string. h>
# Include <wmsdk. h>
# Pragma comment (lib, "wmvcore. lib ")
# Pragma comment (lib, "Rpcrt4.lib ")
# Define FIELD_NUM 9
# Define FIELD_LEN 1024
Char _ sFileName [MAX_PATH];
# Ifndef SAFE_RELEASE
# Define SAFE_RELEASE (x )\
If (NULL! = X )\
{\
X-> Release ();\
X = NULL ;\
}
# Endif // SAFE_RELEASE
# Ifndef SAFE_DELETE
# Define SAFE_DELETE (x )\
If (NULL! = X )\
{\
Delete x ;\
X = NULL ;\
}
# Endif // SAFE_DELETE
# Ifndef SAFE_ARRAYDELETE
# Define SAFE_ARRAYDELETE (x )\
If (NULL! = X )\
{\
Delete [] x ;\
X = NULL ;\
}
# Endif // SAFE_ARRAYDELETE
# Ifndef UNICODE
HRESULT ConvertMBtoWC (LPCTSTR ptszInString, LPWSTR * ppwszOutString)
{
If (ptszInString = NULL | ppwszOutString = NULL ){
Return (E_INVALIDARG );
}
HRESULT hr = S_ OK;
Int nSizeCount = 0;
* PpwszOutString = NULL;
Do
{
//
// Get the memory reqd for this string
//
NSizeCount = MultiByteToWideChar (CP_ACP, 0, ptszInString,-1, NULL, 0 );
If (0 = nSizeCount)
{
Hr = HRESULT_FROM_WIN32 (GetLastError ());
Break;
}
* PpwszOutString = new WCHAR [nSizeCount];
If (NULL = * ppwszOutString)
{
Hr = HRESULT_FROM_WIN32 (GetLastError ());
Break;
}
If (0 = MultiByteToWideChar (CP_ACP, 0, ptszInString,-1, * ppwszOutString, nSizeCount ))
{
Hr = HRESULT_FROM_WIN32 (GetLastError ());
Break;
}
}
While (FALSE );
If (FAILED (hr ))
{
SAFE_ARRAYDELETE (* ppwszOutString );
_ Tprintf (_ T ("Internal error (hr = 0x % 08x) \ n"), hr );
}
Return (hr );
}
# Endif // UNICODE
HRESULT editorOpen (WCHAR * _ wma_file, iwdeskadataeditor ** ppEditor, IWMHeaderInfo ** ppHeaderInfo)
{
If (NULL = _ wma_file) | (NULL = ppEditor )){
Return (E_INVALIDARG );
}
HRESULT hr = S_ OK;
Do
{
Hr = WMCreateEditor (ppEditor );
If (FAILED (hr )){
_ Tprintf (_ T ("cocould not create Metadata Editor (hr = 0x % 08x). \ n"), hr );
Break;
}
Hr = (* ppEditor)-> Open (_ wma_file );
If (FAILED (hr )){
_ Tprintf (_ T ("cocould not open the file % ws (hr = 0x % 08x). \ n "),
_ Wma_file, hr );
Break;
}
If (NULL! = PpHeaderInfo ){
Hr = (* ppEditor)-> QueryInterface (IID_IWMHeaderInfo,
(Void **) ppHeaderInfo );
If (FAILED (hr )){
_ Tprintf (_ T ("cocould not QI for IWMHeaderInfo (hr = 0x % 08x). \ n"), hr );
Break;
}
}
}
While (FALSE );
Return (hr );
}
HRESULT SetAttrib (WCHAR * _ wma_file, WCHAR * pName, WCHAR * pValue)
{
WORD wStreamNum = 0;
WORD wAttribType = WMT_TYPE_STRING;
If (NULL = _ wma_file) | (NULL = pName) | (NULL = pValue )){
Return (E_INVALIDARG );
}
HRESULT hr = S_ OK;
IWMMetadataEditor * pEditor = NULL;
IWMHeaderInfo * pHeaderInfo = NULL;
BYTE * pbAttribValue = NULL;
WORD wAttribValueLen = 0;
WMT_ATTR_DATATYPE AttribDataType = (WMT_ATTR_DATATYPE) wAttribType;
DWORD dwAttribValue = 0;
WORD wAttribValue = 0;
QWORD qwAttribValue = 0;
BOOL fAttribValue = 0;
Do
{
Hr = editorOpen (_ wma_file, & pEditor, & pHeaderInfo );
If (FAILED (hr )){
Break;
}
/*
Attrib type = string...
*/
WAttribValueLen = (wcslen (pValue) + 1) * sizeof (WCHAR );
PbAttribValue = (BYTE *) pValue;
Hr = pHeaderInfo-> SetAttribute (wStreamNum,
PName,
AttribDataType,
PbAttribValue,
WAttribValueLen );
If (FAILED (hr )){
_ Tprintf (_ T ("SetAttribute failed for Attribute name % ws (hr = 0x % 08x). \ n "),
PName, hr );
Break;
}
Hr = pEditor-> Flush ();
If (FAILED (hr )){
_ Tprintf (_ T ("cocould not flush the file % ws (hr = 0x % 08x). \ n "),
_ Wma_file, hr );
Break;
}
Hr = pEditor-> Close ();
If (FAILED (hr )){
_ Tprintf (_ T ("cocould not close the file % ws (hr = 0x % 08x). \ n "),
_ Wma_file, hr );
Break;
}
}
While (FALSE );
SAFE_RELEASE (pHeaderInfo );
SAFE_RELEASE (pEditor );
Return (hr );
}
HRESULT _ SetAttrib (WCHAR * _ wma_file, WCHAR ** pName, WCHAR ** pValue)
{
WORD wStreamNum = 0;
WORD wAttribType = WMT_TYPE_STRING;
Int I;
If (NULL = _ wma_file) | (NULL = pName) | (NULL = pValue )){
Return (E_INVALIDARG );
}
HRESULT hr = S_ OK;
IWMMetadataEditor * pEditor = NULL;
IWMHeaderInfo * pHeaderInfo = NULL;
BYTE * pbAttribValue = NULL;
WORD wAttribValueLen = 0;
WMT_ATTR_DATATYPE AttribDataType = (WMT_ATTR_DATATYPE) wAttribType;
DWORD dwAttribValue = 0;
WORD wAttribValue = 0;
QWORD qwAttribValue = 0;
BOOL fAttribValue = 0;
Do
{
Hr = editorOpen (_ wma_file, & pEditor, & pHeaderInfo );
If (FAILED (hr )){
Break;
}
For (I = 1; I <FIELD_NUM; I ++ ){
// SetAttrib (_ wma_file, attribNames [I], fields [I]);
// Printf ("% d: % s \ n", I, fields [I]);
/*
Attrib type = string...
*/
WAttribValueLen = (wcslen (pValue [I]) + 1) * sizeof (WCHAR );
PbAttribValue = (BYTE *) pValue [I];
Hr = pHeaderInfo-> SetAttribute (wStreamNum,
PName [I],
AttribDataType,
PbAttribValue,
WAttribValueLen );
If (FAILED (hr )){
_ Tprintf (_ T ("SetAttribute failed for Attribute name % ws (hr = 0x % 08x). \ n"), pName [I], hr );
Break;
}
}
Hr = pEditor-> Flush ();
If (FAILED (hr )){
_ Tprintf (_ T ("cocould not flush the file % ws (hr = 0x % 08x). \ n "),
_ Wma_file, hr );
Break;
}
Hr = pEditor-> Close ();
If (FAILED (hr )){
_ Tprintf (_ T ("cocould not close the file % ws (hr = 0x % 08x). \ n "),
_ Wma_file, hr );
Break;
}
}
While (FALSE );
SAFE_RELEASE (pHeaderInfo );
SAFE_RELEASE (pEditor );
Return (hr );
}
Bool get_info (WCHAR ** fields, int num, char * input ){
Int seg = 0;
Char * s = input;
Char buffer [1024*4] = {0x00 };
_ SFileName [0] = 0x00;
For (char * p = input; * p! = 0x00; p ++ ){
If (* p = '| '){
* P = 0x00;
Strcpy (buffer, s );
If (_ sFileName [0] = 0x00)
Strcpy (_ sFileName, s );
HRESULT hr = ConvertMBtoWC (buffer, & fields [seg]);
If (FAILED (hr )){
Break;
}
Buffer [0] = 0x00;
// Strcpy (fields [seg], s );
S = p + 1;
Seg ++;
If (seg = num-1 ){
If (* s! = 0x00 ){
Strcpy (buffer, s );
Hr = ConvertMBtoWC (buffer, & fields [seg]);
// Strcpy (fields [seg], s );
}
Break;
}
}
}
If (seg = num-1)
Return true;
Else
Return false;
}
Int loadConfig (WCHAR ** attribNames ){
Char buffer [1024];
FILE * fp;
Int I = 0;
HRESULT hr = S_ OK;
Fp = fopen ("config.txt", "rb ");
If (! Fp ){
Perror ("fopen (config.txt )");
Return-1;
}
While (! Feof (fp )){
If (fgets (buffer, sizeof (buffer), fp )){
If (strlen (buffer) <3)
Continue;
For (int j = 0; j <(int) strlen (buffer); j ++ ){
If (buffer [j] = 0x0a | buffer [j] = 0x0d)
Buffer [j] = 0x00;
}
Hr = ConvertMBtoWC (buffer, & attribNames [I]);
If (FAILED (hr ))
Break;
Else
I ++;
}
}
Fclose (fp );
If (FAILED (hr ))
Return-1;
Else
Return I;
}

Copy codeThe Code is as follows: int main (void ){
WCHAR * fields [FIELD_NUM];
WCHAR * attribNames [128] = {0x00 };
Int I;
Int j = 0;
Int fieldNum = loadConfig (attribNames );
Printf ("% d \ n", fieldNum );
For (I = 0; I <128; I ++ ){
If (attribNames [I])
_ Tprintf (_ T ("% ws \ n"), attribNames [I], _ T ("hello go ...."));
}
Char input [1024*4];
FILE * fp = fopen ("input.txt", "rb ");
If (! Fp ){
Perror ("fopen ()");
Return-1;
}
While (! Feof (fp )){
Input [0] = 0x00;
If (fgets (input, sizeof (input), fp )){
For (I = 0; I <FIELD_NUM; I ++)
Fields [I] = NULL;
J ++;
If (j % 100 = 0)
Printf ("files: % d \ n", j );
Bool st = get_info (fields, FIELD_NUM, input );
If (st = false)
Printf ("status: % s \ n", st? "True": "false ");
// Printf ("status: % s \ n", st? "True": "false ");
If (st ){
WCHAR * _ wma_file = fields [0];
FILE * fp = fopen (_ sFileName, "rb ");
If (fp ){
Fclose (fp );
// Puts (_ sFileName );
_ SetAttrib (_ wma_file, attribNames, fields );
/*
For (I = 1; I <FIELD_NUM; I ++ ){

SetAttrib (_ wma_file, attribNames [I], fields [I]);
// Printf ("% d: % s \ n", I, fields [I]);
}
*/
}
}
For (I = 0; I <FIELD_NUM; I ++)
SAFE_ARRAYDELETE (fields [I]);
}
}
Fclose (fp );
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.