Xhack

Un forum dedicato all'hacking
 
IndiceIndice  PortalePortale  CalendarioCalendario  FAQFAQ  CercaCerca  RegistrareRegistrare  Lista utentiLista utenti  GruppiGruppi  Connessione  

Condividere | 
 

 [C++] Rinominare mp3 in base ai tag

Vedere l'argomento precedente Vedere l'argomento seguente Andare in basso 
AutoreMessaggio
BlackLight
Moderatore
Moderatore


Numero di messaggi: 277
Età: 25
Data d'iscrizione: 22.08.07

MessaggioOggetto: [C++] Rinominare mp3 in base ai tag   Sab Ott 27, 2007 7:52 pm

Questa richiesta mi era stata fatta su Hacker Journal...sperando che possa tornare utile a qualcuno posto il codice qui. Quello che segue è un codice C++ per sistemi Unix che prende come parametro una directory in cui sono collocati dei file mp3, legge i tag di ogni file e rinomina il file in questione nel formato 'Artista - Titolo.mp3'. È molto comodo per tutti quelli che si ritrovano a scaricare musica da un lettore mp3 al proprio computer e si ritrovano tutti i nomi di file sballati mentre invece i tag sono a posto. Ancora una volta ho utilizzato le librerie id3lib nel codice.

Codice:
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <id3/tag.h>
#include <dirent.h>
using namespace std;

void get_tag (ID3_FrameID f, ID3_Tag &myTag, char *field, int size)  {
        ID3_Frame *myFrame=NULL;

        if (myFrame = myTag.Find(f))
                myFrame->Field(ID3FN_TEXT).Get(field,size);
}

main(int argc, char **argv)  {
        if (argc==1)  {
                cout << "Usage: " << argv[0] << "<dir>" << endl;
                exit(1);
        }

        DIR *dir;
        struct dirent *info;

        if (!(dir=opendir(argv[1])))  {
                cout << "Invalid directory " << argv[1] << endl;
                exit(2);
        }

        while (info=readdir(dir))  {
                if (strstr(info->d_name,".mp3"))  {
                        char band[1024],title[1024];

                        ID3_Tag myTag(info->d_name);
                        get_tag(ID3FID_BAND,myTag,band,sizeof(band));
                        get_tag(ID3FID_TITLE,myTag,title,sizeof(title));

                        cout << band << endl;

                        string name(band);
                        name.append(" - ");
                        name.append(title);
                        name.append(".mp3");
                        rename (info->d_name,name.c_str());
                }
        }
}

_________________
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/CM/CC/E/IT/LS/M d-(--) s:- a-- C+++$ UBL++++$ P+++ L+++++$ E- W+++ N+ o? K? w-- !O !M>+ !V PS+++ PE-- Y++ PGP+ !t !5 !X R+ tv-- b++>+++ DI? D+ G>+++ e++>++++ h r++ y+++
------END GEEK CODE BLOCK------

Codice:
blacklight@nightmare:/$ touch figa
touch: cannot touch `figa': Permission denied
Tornare in alto Andare in basso
Vedere il profilo dell'utente http://blacklight.gotdns.org
 

[C++] Rinominare mp3 in base ai tag

Vedere l'argomento precedente Vedere l'argomento seguente Tornare in alto 
Pagina 1 su1

 Argomenti simili

-
» Base Targhetta By Zampto
» [Screen] Nabbo CMS base Wake [Screen]
» R6 GOLD
» Cracker ruba il database
» Armi Warrock

Permesso del forum:Non puoi rispondere agli argomenti in questo forum
Xhack :: Programmazione :: C/C++-