Changeset View
Changeset View
Standalone View
Standalone View
src/extractors/taglibextractor.cpp
Show All 18 Lines | |||||
19 | 19 | | |||
20 | 20 | | |||
21 | #include "taglibextractor.h" | 21 | #include "taglibextractor.h" | ||
22 | 22 | | |||
23 | // Taglib includes | 23 | // Taglib includes | ||
24 | #include <fileref.h> | 24 | #include <fileref.h> | ||
25 | #include <tfilestream.h> | 25 | #include <tfilestream.h> | ||
26 | #include <flacfile.h> | 26 | #include <flacfile.h> | ||
27 | #include <asftag.h> | ||||
28 | #include <asfattribute.h> | ||||
27 | #include <apetag.h> | 29 | #include <apetag.h> | ||
28 | #include <mpcfile.h> | 30 | #include <mpcfile.h> | ||
29 | #include <id3v2tag.h> | 31 | #include <id3v2tag.h> | ||
30 | #include <id3v1genres.h> | 32 | #include <id3v1genres.h> | ||
31 | #include <mpegfile.h> | 33 | #include <mpegfile.h> | ||
32 | #include <oggfile.h> | 34 | #include <oggfile.h> | ||
33 | #include <mp4file.h> | 35 | #include <mp4file.h> | ||
34 | #include <mp4tag.h> | 36 | #include <mp4tag.h> | ||
▲ Show 20 Lines • Show All 665 Lines • ▼ Show 20 Line(s) | 520 | { | |||
700 | } | 702 | } | ||
701 | 703 | | |||
702 | itOgg = lstOgg.find("REPLAYGAIN_ALBUM_PEAK"); | 704 | itOgg = lstOgg.find("REPLAYGAIN_ALBUM_PEAK"); | ||
703 | if (itOgg != lstOgg.end()) { | 705 | if (itOgg != lstOgg.end()) { | ||
704 | data.replayGainAlbumPeak = TStringToQString((*itOgg).second.toString("")); | 706 | data.replayGainAlbumPeak = TStringToQString((*itOgg).second.toString("")); | ||
705 | } | 707 | } | ||
706 | } | 708 | } | ||
707 | 709 | | |||
710 | void TagLibExtractor::extractAsfTags(TagLib::ASF::Tag* asfTags, ExtractedData& data) | ||||
711 | { | ||||
712 | if (asfTags->isEmpty()) { | ||||
713 | return; | ||||
714 | } | ||||
715 | | ||||
716 | if (!asfTags->copyright().isEmpty()) { | ||||
717 | data.copyright = asfTags->copyright(); | ||||
718 | } | ||||
719 | | ||||
bruns: `// 0->0, 1->2, 25->4, 50->6, 75->8, 99->10` | |||||
720 | TagLib::ASF::AttributeList lstASF = asfTags->attribute("WM/SharedUserRating"); | ||||
721 | if (!lstASF.isEmpty()) { | ||||
722 | int rating = lstASF.front().toString().toInt(); | ||||
723 | //map the rating values of WMP to Baloo rating | ||||
724 | //0->0, 1->2, 25->4, 50->6, 75->8, 99->10 | ||||
725 | if (rating == 0) { | ||||
726 | data.rating = 0; | ||||
727 | } else if (rating == 1) { | ||||
728 | data.rating = 2; | ||||
729 | } else { | ||||
730 | data.rating = static_cast<uint>(0.09 * rating + 2); | ||||
731 | } | ||||
732 | } | ||||
733 | | ||||
734 | lstASF = asfTags->attribute("WM/PartOfSet"); | ||||
735 | if (!lstASF.isEmpty()) { | ||||
bruns: you don't need the `isEmpty()` here, as you iterate over it. | |||||
736 | data.discNumber = lstASF.front().toString().toInt(); | ||||
I think you can write instead: bruns: I think you can write instead:
`for (const auto& attribute : qAsConst(lstAsf)) { ... }`,
as… | |||||
737 | } | ||||
738 | | ||||
this makes me always wonder why we don't do: // decltype(data.albumArtists) == QStringList for (attribute : lstAsf) { QString t = TStringToQString(attribute.toString()); data.albumArtists << contactsFromString(t); } bruns: this makes me always wonder why we don't do:
```
// decltype(data.albumArtists) == QStringList… | |||||
Yeah, there is a lot of unneccesary stuff in there that must be cleaned up. But before I get to that, I would like to add tests for multiple entries, and before that we have to agree how the output of mutliple entries shall look like, which brings me to D12950 :) astippich: Yeah, there is a lot of unneccesary stuff in there that must be cleaned up. But before I get to… | |||||
739 | lstASF = asfTags->attribute("WM/AlbumArtist"); | ||||
740 | for (const auto& attribute : qAsConst(lstASF)) { | ||||
741 | if (!data.albumArtists.isEmpty()) { | ||||
742 | data.albumArtists += ", "; | ||||
743 | } | ||||
744 | data.albumArtists += attribute.toString(); | ||||
745 | } | ||||
746 | | ||||
747 | lstASF = asfTags->attribute("WM/Composer"); | ||||
748 | for (const auto& attribute : qAsConst(lstASF)) { | ||||
749 | if (!data.composers.isEmpty()) { | ||||
750 | data.composers += ", "; | ||||
751 | } | ||||
752 | data.composers += attribute.toString(); | ||||
753 | } | ||||
754 | | ||||
755 | lstASF = asfTags->attribute("WM/Conductor"); | ||||
756 | for (const auto& attribute : qAsConst(lstASF)) { | ||||
757 | if (!data.conductor.isEmpty()) { | ||||
758 | data.conductor += ", "; | ||||
759 | } | ||||
760 | data.conductor += attribute.toString(); | ||||
761 | } | ||||
762 | | ||||
763 | lstASF = asfTags->attribute("WM/Writer"); | ||||
764 | for (const auto& attribute : qAsConst(lstASF)) { | ||||
765 | if (!data.lyricists.isEmpty()) { | ||||
766 | data.lyricists += ", "; | ||||
767 | } | ||||
768 | data.lyricists += attribute.toString(); | ||||
769 | } | ||||
770 | | ||||
771 | lstASF = asfTags->attribute("WM/Publisher"); | ||||
772 | for (const auto& attribute : qAsConst(lstASF)) { | ||||
773 | if (!data.publisher.isEmpty()) { | ||||
774 | data.publisher += ", "; | ||||
775 | } | ||||
776 | data.publisher += attribute.toString(); | ||||
777 | } | ||||
778 | | ||||
779 | lstASF = asfTags->attribute("Author"); | ||||
780 | for (const auto& attribute : qAsConst(lstASF)) { | ||||
781 | if (!data.author.isEmpty()) { | ||||
782 | data.author += ", "; | ||||
783 | } | ||||
784 | data.author += attribute.toString(); | ||||
785 | } | ||||
786 | } | ||||
787 | | ||||
708 | void TagLibExtractor::extract(ExtractionResult* result) | 788 | void TagLibExtractor::extract(ExtractionResult* result) | ||
709 | { | 789 | { | ||
710 | const QString fileUrl = result->inputUrl(); | 790 | const QString fileUrl = result->inputUrl(); | ||
711 | const QString mimeType = result->inputMimetype(); | 791 | const QString mimeType = result->inputMimetype(); | ||
712 | 792 | | |||
713 | // Open the file readonly. Important if we're sandboxed. | 793 | // Open the file readonly. Important if we're sandboxed. | ||
714 | TagLib::FileStream stream(fileUrl.toUtf8().constData(), true); | 794 | TagLib::FileStream stream(fileUrl.toUtf8().constData(), true); | ||
715 | if (!stream.isOpen()) { | 795 | if (!stream.isOpen()) { | ||
Show All 38 Lines | 832 | } else if (mimeType == QLatin1String("audio/ogg") || mimeType == QLatin1String("audio/x-vorbis+ogg")) { | |||
754 | if (oggFile.tag()) { | 834 | if (oggFile.tag()) { | ||
755 | extractVorbisTags(oggFile.tag(), data); | 835 | extractVorbisTags(oggFile.tag(), data); | ||
756 | } | 836 | } | ||
757 | } else if (mimeType == QLatin1String("audio/opus") || mimeType == QLatin1String("audio/x-opus+ogg")) { | 837 | } else if (mimeType == QLatin1String("audio/opus") || mimeType == QLatin1String("audio/x-opus+ogg")) { | ||
758 | TagLib::Ogg::Opus::File opusFile(&stream, true); | 838 | TagLib::Ogg::Opus::File opusFile(&stream, true); | ||
759 | if (opusFile.tag()) { | 839 | if (opusFile.tag()) { | ||
760 | extractVorbisTags(opusFile.tag(), data); | 840 | extractVorbisTags(opusFile.tag(), data); | ||
761 | } | 841 | } | ||
842 | } else if (mimeType == QLatin1String("audio/x-ms-wma")) { | ||||
843 | TagLib::ASF::Tag* asfTags = dynamic_cast<TagLib::ASF::Tag*>(tags); | ||||
bruns: Can you add a comment here for why the dynamic_cast is used here? | |||||
844 | if (asfTags) { | ||||
845 | extractAsfTags(asfTags, data); | ||||
846 | } | ||||
762 | } | 847 | } | ||
763 | 848 | | |||
764 | if (!tags->isEmpty()) { | 849 | if (!tags->isEmpty()) { | ||
765 | QString title = TStringToQString(tags->title()); | 850 | QString title = TStringToQString(tags->title()); | ||
766 | if (!title.isEmpty()) { | 851 | if (!title.isEmpty()) { | ||
767 | result->add(Property::Title, title); | 852 | result->add(Property::Title, title); | ||
768 | } | 853 | } | ||
769 | 854 | | |||
▲ Show 20 Lines • Show All 240 Lines • Show Last 20 Lines |
// 0->0, 1->2, 25->4, 50->6, 75->8, 99->10