MetadataParser.h 3.09 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
    std::tuple<bool, bool> refreshFile( IItem& item ) const;
59 60
    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,
61
                                             std::shared_ptr<Artist> artist, Genre* genre ) const;
62
    bool link( Media& media, Album& album, std::shared_ptr<Artist> albumArtist, std::shared_ptr<Artist> artist );
63
    std::shared_ptr<Album> findAlbum( IItem& item, std::shared_ptr<Artist> albumArtist,
64
                                        std::shared_ptr<Artist> artist );
65
    std::shared_ptr<Genre> handleGenre( IItem& item ) const;
66

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

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

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

}
81
}