hahahaha een spaar-kat!quote:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | void MediaProvider::scanForNewMedia(QUrl location) { QDirIterator iterator(location.toLocalFile(), QDirIterator::Subdirectories); while(iterator.hasNext())//exit the loop when we run out of files { iterator.next();//jump to first/next dir if(!iterator.fileInfo().isDir()) //skip if the file is a folder { QString fileName = iterator.fileName();//get filename //if(fileName.endsWith(".mp3") || fileName.endsWith(".flac" || fileName.endsWith(".ogg")))//check if we have a sound file //{ QByteArray filePathBA = iterator.filePath().toLocal8Bit(); TagLib::FileRef f(filePathBA.data()); if(!f.isNull() && f.tag())//if it is a valid media file, process it. { TagLib::Tag *tag = f.tag(); //Get artist QString _artist = tag->artist().toCString(true); //the argument of toCString(bool) defines whether we want a unicode string or not. //since QString is a unicode string, choosing 'true' is the most obvious choice. if(_artist == "") _artist = "unknown"; //if we don't know the artist, we'll set it to unknown. //we are going to edit the properties of the artist, so we'll grab a pointer to that item. ListItem* _currentArtist = _artistModel->find(_artist); //check if the artist we are processing is already in the model if(_currentArtist == 0) //Null pointer, thus it doesn't exist. { _artistModel->appendRow(new artistListItem(_artist, _artistID));//append to model _currentArtist = _artistModel->find(_artist);//get the item so we can edit it. _artistID++; } //Get album QString _album = tag->album().toCString(true); //true for unicode, explained above if(_album == "") _album = "unknown";//unknown album //here we are going to do that pointer trick again ListItem* _currentAlbum = _albumModel->find(_album); if(_currentAlbum == 0) { _albumModel->appendRow(new albumListItem(_album, _albumID)); _currentAlbum = _albumModel->find(_album); _albumID++; } //if the albumlist of the current artist doesn't contain the current album, add it. if(!_currentArtist->data(artistListItem::AlbumListRole).toList().contains(_currentAlbum->data(albumListItem::IDRole))) { //we can't just append directly to the QList, we'll first have to retrieve it, edit it in here and then replace it. QList<QVariant> _currentAlbumList = _currentArtist->data(artistListItem::AlbumListRole).toList(); _currentAlbumList.append(_currentAlbum->data(albumListItem::IDRole).toULongLong()); _currentArtist->setData(_currentAlbumList, artistListItem::AlbumListRole); } //if the artistlist ofthe current album doesn't contain the current artist, add it. if(!_currentAlbum->data(albumListItem::ArtistsRole).toList().contains(_currentArtist->data(artistListItem::IDRole))) { //same QList-trick again QList<QVariant> _currentArtistList = _currentAlbum->data(albumListItem::ArtistsRole).toList(); _currentArtistList.append(_currentArtist->data(artistListItem::IDRole).toULongLong()); _currentAlbum->setData(_currentArtistList, albumListItem::ArtistsRole); } //Get title QString _title = tag->title().toCString(true); if(_title == "") _title = iterator.fileInfo().baseName();//set the name of the file as title if there isn't a title tag //Get track number int _number = tag->track(); _songModel->appendRow(new songListItem(_title, iterator.filePath(), _songID, _currentAlbum->data(albumListItem::IDRole).toULongLong(), _currentArtist->data(artistListItem::IDRole).toULongLong(), _number)); _songID++; //here we are appending the song to the album. QList<QVariant> currentSongListOfCurrentAlbum = _currentAlbum->data(albumListItem::SongsRole).toList(); ListItem* currentSong = _songModel->find(_title); currentSongListOfCurrentAlbum.append(currentSong->data(songListItem::IDRole)); _currentAlbum->setData(currentSongListOfCurrentAlbum, albumListItem::SongsRole); //now to get the cover art if(!ImageProvider::mapContains(_currentAlbum->data(albumListItem::IDRole).toULongLong())) { TagLib::MPEG::File mpegFile(filePathBA.data()); if(mpegFile.isValid() && mpegFile.ID3v2Tag()) { TagLib::ID3v2::FrameList frameList = mpegFile.ID3v2Tag()->frameList("APIC"); QImage image; if(!frameList.isEmpty()) { TagLib::ID3v2::AttachedPictureFrame* pictureFrame = static_cast<TagLib::ID3v2::AttachedPictureFrame*>(frameList.front()); image.loadFromData((const uchar*)pictureFrame->picture().data(), pictureFrame->picture().size()); ImageProvider::registerAlbumArt(_currentAlbum->data(albumListItem::IDRole).toULongLong(), image); } } //else //{ TagLib::FLAC::File flacFile(filePathBA.data()); const TagLib::List<TagLib::FLAC::Picture*>& piclist = flacFile.pictureList(); QImage image; if(!piclist.isEmpty()) { QImage image; image.loadFromData((const uchar*)piclist[0]->data().data(), piclist[0]->data().size()); ImageProvider::registerAlbumArt(_currentAlbum->data(albumListItem::IDRole).toULongLong(), image); } //} } }//if(!f.isNull) //}//if(file.endswith.....) }//if(!iterator.fileInfo.isdir()) }//while(iterator.hasnext) } |
Jaquote:Op woensdag 29 januari 2014 15:17 schreef Gutanoth het volgende:
[..]
Haha je wilde weten wat ik had getypt bij dat Barbie poppetje ? ;p
En trouwens:
PSV![]()
![]()
![]()
Godverquote:Op woensdag 29 januari 2014 15:25 schreef Kotzooi het volgende:
http://www.wakkerpedia.nl/index.php/Feit
Idd! 700g totaal woop woopquote:Op woensdag 29 januari 2014 08:27 schreef Gutanoth het volgende:
[..]
2 Tegelijk!? dat is weer 300 Gold Bro!
Forum Opties | |
---|---|
Forumhop: | |
Hop naar: |