<commit_before>/* Interface */

#include "enna.h"
#include "codecs.h"
#include <player.h>

#define ENNA_MODULE_NAME        "metadata_libplayer"
#define ENNA_GRABBER_NAME       "libplayer"
#define ENNA_GRABBER_PRIORITY   2

#define SNAPSHOTS_PATH          "snapshots"

#define URI_TYPE_FTP  "ftp://"
#define URI_TYPE_HTTP "http://"
#define URI_TYPE_MMS  "mms://"
#define URI_TYPE_RTP  "rtp://"
#define URI_TYPE_RTSP "rtsp://"
#define URI_TYPE_SMB  "smb://"
#define URI_TYPE_TCP  "tcp://"
#define URI_TYPE_UDP  "udp://"
#define URI_TYPE_UNSV "unsv://"

typedef struct _Metadata_Module_libplayer
{
    Evas *evas;
    Enna_Module *em;
    player_t *player;
    

} Metadata_Module_libplayer;

static Metadata_Module_libplayer *mod;

/*****************************************************************************/
/*                         Private Module API                                */
/*****************************************************************************/

static mrl_t *
set_network_stream (const char *uri, mrl_resource_t type)
{
    mrl_t *mrl;
    mrl_resource_network_args_t *args;

    args = calloc (1, sizeof (mrl_resource_network_args_t));
    args->url = strdup (uri);
    mrl = mrl_new (mod->player, type, args);

    return mrl;
}

static mrl_t *
set_local_stream (const char *uri)
{
    mrl_t *mrl;
    mrl_resource_local_args_t *args;

    args = calloc (1, sizeof (mrl_resource_local_args_t));
    args->location = strdup (uri);
    mrl = mrl_new (mod->player, MRL_RESOURCE_FILE, args);

    return mrl;
}

static int
set_mrl (const char *uri)
{
    mrl_t *mrl = NULL;

    /* try network streams */
    if (!strncmp (uri, URI_TYPE_FTP, strlen(URI_TYPE_FTP)))
        mrl = set_network_stream (uri, MRL_RESOURCE_FTP);
    else if (!strncmp (uri, URI_TYPE_HTTP, strlen(URI_TYPE_HTTP)))
        mrl = set_network_stream (uri, MRL_RESOURCE_HTTP);
    else if (!strncmp (uri, URI_TYPE_MMS, strlen(URI_TYPE_MMS)))
        mrl = set_network_stream (uri, MRL_RESOURCE_MMS);
    else if (!strncmp (uri, URI_TYPE_RTP, strlen(URI_TYPE_RTP)))
        mrl = set_network_stream (uri, MRL_RESOURCE_RTP);
    else if (!strncmp (uri, URI_TYPE_RTSP, strlen(URI_TYPE_RTSP)))
        mrl = set_network_stream (uri, MRL_RESOURCE_RTSP);
    else if (!strncmp (uri, URI_TYPE_SMB, strlen(URI_TYPE_SMB)))
        mrl = set_network_stream (uri, MRL_RESOURCE_SMB);
    else if (!strncmp (uri, URI_TYPE_TCP, strlen(URI_TYPE_TCP)))
        mrl = set_network_stream (uri, MRL_RESOURCE_TCP);
    else if (!strncmp (uri, URI_TYPE_UDP, strlen(URI_TYPE_UDP)))
        mrl = set_network_stream (uri, MRL_RESOURCE_UDP);
    else if (!strncmp (uri, URI_TYPE_UNSV, strlen(URI_TYPE_UNSV)))
        mrl = set_network_stream (uri, MRL_RESOURCE_UNSV);

    /* default is local files */
    if (!mrl)
        mrl = set_local_stream (uri);

    if (!mrl)
        return 1;

    player_mrl_set (mod->player, mrl);
    return 0;
}

static char *
get_movie_name (const char *filename)
{
    char *it, *movie;
    char *path = strdup (filename);
    char *file = (char *) ecore_file_file_get (path);

    it = strrchr(file, '.');
    if (it) /* remove suffix? */
        *it = '\0';

    movie = strdup (file);
    free (path);

    return movie;
}

static void
libplayer_grab (Enna_Metadata *meta, int caps)
{
    char *track_nb;
    int frameduration = 0;
    char *codec_id;

    if (!meta || !meta->uri)
        return;

    enna_log (ENNA_MSG_EVENT, ENNA_MODULE_NAME,
              "Grabbing info from %s", meta->uri);
    
    set_mrl (meta->uri);

    if (!meta->size)
        meta->size = mrl_get_size (mod->player, NULL);

    if (!meta->length)
        meta->length =
            mrl_get_property (mod->player, NULL, MRL_PROPERTY_LENGTH);

    if (!meta->title)
        meta->title = mrl_get_metadata (mod->player, NULL, MRL_METADATA_TITLE);

    if (caps & ENNA_GRABBER_CAP_AUDIO)
    {
        if (!meta->music->artist)
        {
            meta->music->artist = mrl_get_metadata (mod->player, NULL,
                                                    MRL_METADATA_ARTIST);
            enna_metadata_add_keywords (meta, meta->music->artist);
        }
        <commit_msg>use libplayer metadata module to set metadata type<commit_after>/* Interface */

#include "enna.h"
#include "codecs.h"
#include <player.h>

#define ENNA_MODULE_NAME        "metadata_libplayer"
#define ENNA_GRABBER_NAME       "libplayer"
#define ENNA_GRABBER_PRIORITY   2

#define SNAPSHOTS_PATH          "snapshots"

#define URI_TYPE_FTP  "ftp://"
#define URI_TYPE_HTTP "http://"
#define URI_TYPE_MMS  "mms://"
#define URI_TYPE_RTP  "rtp://"
#define URI_TYPE_RTSP "rtsp://"
#define URI_TYPE_SMB  "smb://"
#define URI_TYPE_TCP  "tcp://"
#define URI_TYPE_UDP  "udp://"
#define URI_TYPE_UNSV "unsv://"

typedef struct _Metadata_Module_libplayer
{
    Evas *evas;
    Enna_Module *em;
    player_t *player;
    

} Metadata_Module_libplayer;

static Metadata_Module_libplayer *mod;

/*****************************************************************************/
/*                         Private Module API                                */
/*****************************************************************************/

static mrl_t *
set_network_stream (const char *uri, mrl_resource_t type)
{
    mrl_t *mrl;
    mrl_resource_network_args_t *args;

    args = calloc (1, sizeof (mrl_resource_network_args_t));
    args->url = strdup (uri);
    mrl = mrl_new (mod->player, type, args);

    return mrl;
}

static mrl_t *
set_local_stream (const char *uri)
{
    mrl_t *mrl;
    mrl_resource_local_args_t *args;

    args = calloc (1, sizeof (mrl_resource_local_args_t));
    args->location = strdup (uri);
    mrl = mrl_new (mod->player, MRL_RESOURCE_FILE, args);

    return mrl;
}

static int
set_mrl (const char *uri)
{
    mrl_t *mrl = NULL;

    /* try network streams */
    if (!strncmp (uri, URI_TYPE_FTP, strlen(URI_TYPE_FTP)))
        mrl = set_network_stream (uri, MRL_RESOURCE_FTP);
    else if (!strncmp (uri, URI_TYPE_HTTP, strlen(URI_TYPE_HTTP)))
        mrl = set_network_stream (uri, MRL_RESOURCE_HTTP);
    else if (!strncmp (uri, URI_TYPE_MMS, strlen(URI_TYPE_MMS)))
        mrl = set_network_stream (uri, MRL_RESOURCE_MMS);
    else if (!strncmp (uri, URI_TYPE_RTP, strlen(URI_TYPE_RTP)))
        mrl = set_network_stream (uri, MRL_RESOURCE_RTP);
    else if (!strncmp (uri, URI_TYPE_RTSP, strlen(URI_TYPE_RTSP)))
        mrl = set_network_stream (uri, MRL_RESOURCE_RTSP);
    else if (!strncmp (uri, URI_TYPE_SMB, strlen(URI_TYPE_SMB)))
        mrl = set_network_stream (uri, MRL_RESOURCE_SMB);
    else if (!strncmp (uri, URI_TYPE_TCP, strlen(URI_TYPE_TCP)))
        mrl = set_network_stream (uri, MRL_RESOURCE_TCP);
    else if (!strncmp (uri, URI_TYPE_UDP, strlen(URI_TYPE_UDP)))
        mrl = set_network_stream (uri, MRL_RESOURCE_UDP);
    else if (!strncmp (uri, URI_TYPE_UNSV, strlen(URI_TYPE_UNSV)))
        mrl = set_network_stream (uri, MRL_RESOURCE_UNSV);

    /* default is local files */
    if (!mrl)
        mrl = set_local_stream (uri);

    if (!mrl)
        return 1;

    player_mrl_set (mod->player, mrl);
    return 0;
}

static char *
get_movie_name (const char *filename)
{
    char *it, *movie;
    char *path = strdup (filename);
    char *file = (char *) ecore_file_file_get (path);

    it = strrchr(file, '.');
    if (it) /* remove suffix? */
        *it = '\0';

    movie = strdup (file);
    free (path);

    return movie;
}

static void
libplayer_grab (Enna_Metadata *meta, int caps)
{
    char *track_nb;
    int frameduration = 0;
    char *codec_id;
    mrl_type_t type;
    
    if (!meta || !meta->uri)
        return;

    enna_log (ENNA_MSG_EVENT, ENNA_MODULE_NAME,
              "Grabbing info from %s", meta->uri);
    
    set_mrl (meta->uri);

    type = mrl_get_type (mod->player, NULL);
    if (type == MRL_TYPE_AUDIO)
        meta->type = ENNA_METADATA_AUDIO;
    else if (type == MRL_TYPE_VIDEO)
        meta->type = ENNA_METADATA_VIDEO;
    
    if (!meta->size)
        meta->size = mrl_get_size (mod->player, NULL);

    if (!meta->length)
        meta->length =
            mrl_get_property (mod->player, NULL, MRL_PROPERTY_LENGTH);

    if (!meta->title)
        meta->title = mrl_get_metadata (mod->player, NULL, MRL_METADATA_TITLE);

    if (caps & ENNA_GRABBER_CAP_AUDIO)
    {
        if (!meta->music->artist)
        {
            meta->music->artist = mrl_get_metadata (mod->player, NULL,
                                                    MRL_METADATA_ARTIST);
            enna_metadata_add_keywords (meta, meta->music->artist);
        }
        
{'fraction_non_alphanumeric': 0.15304105128503315, 'fraction_numerical': 0.00162809629026631, 'mean_word_length': 3.0111940298507465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 56, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5096820', 'n_tokens_mistral': 3164, 'n_tokens_neox': 3072, 'n_words': 680}