MetadataParser.h 3.05 KB
Newer Older
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
/*****************************************************************************
 * Media Library
 *****************************************************************************
 * Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
 *
 * Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#pragma once

#include "MediaLibrary.h"
26
#include "medialibrary/parser/IParserService.h"
27

28 29 30
namespace medialibrary
{

31 32
class AlbumTrack;

33 34 35 36
namespace parser
{

class MetadataAnalyzer : public IParserService
37
{
38
public:
39
    MetadataAnalyzer();
40

41
protected:
42
    bool cacheUnknownArtist();
43
    virtual bool initialize( IMediaLibrary* ml ) override;
44
    virtual Status run( IItem& item ) override;
45
    virtual const char* name() const override;
46
    virtual uint8_t nbThreads() const override;
47 48
    virtual void onFlushing() override;
    virtual void onRestarted() override;
49
    virtual Step targetedStep() const override;
50

51 52 53 54 55
    bool addPlaylistMedias( IItem& item ) const;
    void addPlaylistElement( IItem& item, std::shared_ptr<Playlist> playlistPtr,
                             const IItem& subitem ) const;
    bool parseAudioFile( IItem& task );
    bool parseVideoFile( IItem& task ) const;
56 57
    std::tuple<Status, bool> createFileAndMedia( IItem& item ) const;
    void createTracks( Media& m, const std::vector<IItem::Track>& tracks ) const;
58 59
    std::pair<std::shared_ptr<Artist>, std::shared_ptr<Artist>> findOrCreateArtist( IItem& item ) const;
    std::shared_ptr<AlbumTrack> handleTrack( std::shared_ptr<Album> album, IItem& item,
60
                                             std::shared_ptr<Artist> artist, Genre* genre ) const;
61
    bool link(Media& media, std::shared_ptr<Album> album, std::shared_ptr<Artist> albumArtist, std::shared_ptr<Artist> artist );
62
    std::shared_ptr<Album> findAlbum( IItem& item, std::shared_ptr<Artist> albumArtist,
63
                                        std::shared_ptr<Artist> artist );
64
    std::shared_ptr<Genre> handleGenre( IItem& item ) const;
65

66
private:
67
    static int toInt( IItem& item, IItem::Metadata meta );
68

69
private:
70 71 72
    MediaLibrary* m_ml;
    std::shared_ptr<ModificationNotifier> m_notifier;

73
    std::shared_ptr<Artist> m_unknownArtist;
74
    std::shared_ptr<Artist> m_variousArtists;
75 76
    std::shared_ptr<Album> m_previousAlbum;
    int64_t m_previousFolderId;
77
};
78 79

}
80
}