<commit_before>/*****************************************************************************
 * meta.c : Metadata handling
 *****************************************************************************
 * Copyright (C) 1998-2004 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME> <<EMAIL>>
 *          <NAME> <<EMAIL>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 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 General Public License for more details.
 *
 * You should have received a copy of the GNU 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.
 *****************************************************************************/

#include <vlc/vlc.h>
#include <vlc_input.h>
#include <vlc_stream.h>
#include <vlc_meta.h>
#include <vlc_playlist.h>
#include <vlc_charset.h>
#include "../playlist/playlist_internal.h"
#include <errno.h>

#ifdef HAVE_SYS_STAT_H
#   include <sys/stat.h>
#endif

// FIXME be sure to not touch p_meta without lock on p_item

static const char * meta_type_to_string[VLC_META_TYPE_COUNT] =
{
    [vlc_meta_Title]            = N_("Title"),
    [vlc_meta_Artist]           = N_("Artist"),
    [vlc_meta_Genre]            = N_("Genre"),
    [vlc_meta_Copyright]        = N_("Copyright"),
    [vlc_meta_Album]            = N_("Album/movie/show title"),
    [vlc_meta_TrackNumber]      = N_("Track number/position in set"),
    [vlc_meta_Description]      = N_("Description"),
    [vlc_meta_Rating]           = N_("Rating"),
    [vlc_meta_Date]             = N_("Date"),
    [vlc_meta_Setting]          = N_("Setting"),
    [vlc_meta_URL]              = N_("URL"),
    [vlc_meta_Language]         = N_("Language"),
    [vlc_meta_NowPlaying]       = N_("Language"),
    [vlc_meta_Publisher]        = N_("Publisher"),
    [vlc_meta_EncodedBy]        = N_("Encoded by"),
    [vlc_meta_ArtworkURL]       = N_("Artwork URL"),
    [vlc_meta_TrackID]          = N_("Track ID"),
};

const char *
input_MetaTypeToLocalizedString( vlc_meta_type_t meta_type )
{
    return _(meta_type_to_string[meta_type]);
}

#define input_FindArtInCache(a,b) __input_FindArtInCache(VLC_OBJECT(a),b)
static int __input_FindArtInCache( vlc_object_t *, input_item_t *p_item );

vlc_bool_t input_MetaSatisfied( playlist_t *p_playlist, input_item_t *p_item,
                                uint32_t *pi_mandatory, uint32_t *pi_optional )
{
    (void)p_playlist;
    *pi_mandatory = VLC_META_ENGINE_TITLE | VLC_META_ENGINE_ARTIST;

    uint32_t i_meta = input_CurrentMetaFlags( p_item->p_meta );
    *pi_mandatory &= ~i_meta;
    *pi_optional = 0; /// Todo
    return *pi_mandatory ? VLC_FALSE:VLC_TRUE;
}

int input_MetaFetch( playlist_t *p_playlist, input_item_t *p_item )
{
    struct meta_engine_t *p_me;
    uint32_t i_mandatory, i_optional;

    input_MetaSatisfied( p_playlist, p_item, &i_mandatory, &i_optional );
    // Meta shouldn't magically appear
    assert( i_mandatory );

    /* FIXME: object creation is overkill, use p_private */
    p_me = vlc_object_create( p_playlist, VLC_OBJECT_META_ENGINE );
    p_me->i_flags |= OBJECT_FLAGS_NOINTERACT;
    p_me->i_flags |= OBJECT_FLAGS_QUIET;
    p_me->i_mandatory = i_mandatory;
    p_me->i_optional = i_optional;

    p_me->p_item = p_item;
    p_me->p_module = module_Need( p_me, "meta fetcher", 0, VLC_FALSE );
    if( !p_me->p_module )
    {
        vlc_object_destroy( p_me );
        return VLC_EGENERIC;
    }
    module_Unneed( p_me, p_me->p_module );
    vlc_object_destroy( p_me );

    input_item_SetMetaFetched( p_item, VLC_TRUE );

    return VLC_SUCCESS;
}

/* Return codes:
 *   0 : Art is in cache
 *   1 : Art found, need to download
 *  -X : Error/not found
 */
int input_ArtFind( playlist_t *p_playlist, input_item_t *p_item )
{
    int i_ret = VLC_EGENERIC;
    module_t *p_module;
    char * psz_album = input_item_GetAlbum( p_item );
    char * psz_artist = input_item_GetArtist( p_item );
    char * psz_title = input_item_GetAlbum( p_item );<commit_msg>meta.c: Left over removal. (Should get some sleep).<commit_after>/*****************************************************************************
 * meta.c : Metadata handling
 *****************************************************************************
 * Copyright (C) 1998-2004 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME> <<EMAIL>>
 *          <NAME> <<EMAIL>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 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 General Public License for more details.
 *
 * You should have received a copy of the GNU 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.
 *****************************************************************************/

#include <vlc/vlc.h>
#include <vlc_input.h>
#include <vlc_stream.h>
#include <vlc_meta.h>
#include <vlc_playlist.h>
#include <vlc_charset.h>
#include "../playlist/playlist_internal.h"
#include <errno.h>

#ifdef HAVE_SYS_STAT_H
#   include <sys/stat.h>
#endif

// FIXME be sure to not touch p_meta without lock on p_item

static const char * meta_type_to_string[VLC_META_TYPE_COUNT] =
{
    [vlc_meta_Title]            = N_("Title"),
    [vlc_meta_Artist]           = N_("Artist"),
    [vlc_meta_Genre]            = N_("Genre"),
    [vlc_meta_Copyright]        = N_("Copyright"),
    [vlc_meta_Album]            = N_("Album/movie/show title"),
    [vlc_meta_TrackNumber]      = N_("Track number/position in set"),
    [vlc_meta_Description]      = N_("Description"),
    [vlc_meta_Rating]           = N_("Rating"),
    [vlc_meta_Date]             = N_("Date"),
    [vlc_meta_Setting]          = N_("Setting"),
    [vlc_meta_URL]              = N_("URL"),
    [vlc_meta_Language]         = N_("Language"),
    [vlc_meta_NowPlaying]       = N_("Language"),
    [vlc_meta_Publisher]        = N_("Publisher"),
    [vlc_meta_EncodedBy]        = N_("Encoded by"),
    [vlc_meta_ArtworkURL]       = N_("Artwork URL"),
    [vlc_meta_TrackID]          = N_("Track ID"),
};

const char *
input_MetaTypeToLocalizedString( vlc_meta_type_t meta_type )
{
    return _(meta_type_to_string[meta_type]);
}

#define input_FindArtInCache(a,b) __input_FindArtInCache(VLC_OBJECT(a),b)
static int __input_FindArtInCache( vlc_object_t *, input_item_t *p_item );

vlc_bool_t input_MetaSatisfied( playlist_t *p_playlist, input_item_t *p_item,
                                uint32_t *pi_mandatory, uint32_t *pi_optional )
{
    (void)p_playlist;
    *pi_mandatory = VLC_META_ENGINE_TITLE | VLC_META_ENGINE_ARTIST;

    uint32_t i_meta = input_CurrentMetaFlags( p_item->p_meta );
    *pi_mandatory &= ~i_meta;
    *pi_optional = 0; /// Todo
    return *pi_mandatory ? VLC_FALSE:VLC_TRUE;
}

int input_MetaFetch( playlist_t *p_playlist, input_item_t *p_item )
{
    struct meta_engine_t *p_me;
    uint32_t i_mandatory, i_optional;

    input_MetaSatisfied( p_playlist, p_item, &i_mandatory, &i_optional );
    // Meta shouldn't magically appear
    assert( i_mandatory );

    /* FIXME: object creation is overkill, use p_private */
    p_me = vlc_object_create( p_playlist, VLC_OBJECT_META_ENGINE );
    p_me->i_flags |= OBJECT_FLAGS_NOINTERACT;
    p_me->i_flags |= OBJECT_FLAGS_QUIET;
    p_me->i_mandatory = i_mandatory;
    p_me->i_optional = i_optional;

    p_me->p_item = p_item;
    p_me->p_module = module_Need( p_me, "meta fetcher", 0, VLC_FALSE );
    if( !p_me->p_module )
    {
        vlc_object_destroy( p_me );
        return VLC_EGENERIC;
    }
    module_Unneed( p_me, p_me->p_module );
    vlc_object_destroy( p_me );

    input_item_SetMetaFetched( p_item, VLC_TRUE );

    return VLC_SUCCESS;
}

/* Return codes:
 *   0 : Art is in cache
 *   1 : Art found, need to download
 *  -X : Error/not found
 */
int input_ArtFind( playlist_t *p_playlist, input_item_t *p_item )
{
    int i_ret = VLC_EGENERIC;
    module_t *p_module;
{'fraction_non_alphanumeric': 0.15640082739600092, 'fraction_numerical': 0.007354631119282923, 'mean_word_length': 3.5853530031612224, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5169641', 'n_tokens_mistral': 3090, 'n_tokens_neox': 2971, 'n_words': 703}