Exemple #1
0
Fichier : art.c Projet : IAPark/vlc
static char *ArtCachePath( input_item_t *p_item )
{
    char* psz_path = NULL;
    const char *psz_artist;
    const char *psz_album;
    const char *psz_arturl;
    const char *psz_title;

    vlc_mutex_lock( &p_item->lock );

    if( !p_item->p_meta )
        p_item->p_meta = vlc_meta_New();
    if( !p_item->p_meta )
        goto end;

    psz_artist = vlc_meta_Get( p_item->p_meta, vlc_meta_Artist );
    psz_album = vlc_meta_Get( p_item->p_meta, vlc_meta_Album );
    psz_arturl = vlc_meta_Get( p_item->p_meta, vlc_meta_ArtworkURL );
    psz_title = vlc_meta_Get( p_item->p_meta, vlc_meta_Title );
    if( !psz_title )
        psz_title = p_item->psz_name;


    if( (EMPTY_STR(psz_artist) || EMPTY_STR(psz_album) ) && !psz_arturl )
        goto end;

    psz_path = ArtCacheGetDirPath( psz_arturl, psz_artist, psz_album, psz_title );

end:
    vlc_mutex_unlock( &p_item->lock );
    return psz_path;
}
Exemple #2
0
/**
 * This function ask the fetcher object to fetch the art when needed
 */
static void Art( playlist_preparser_t *p_preparser, input_item_t *p_item )
{
    playlist_t *p_playlist = p_preparser->p_playlist;
    playlist_fetcher_t *p_fetcher = p_preparser->p_fetcher;

    bool b_fetch = false;
    /* If we haven't retrieved enough meta, add to secondary queue
     * which will run the "meta fetchers".
     * This only checks for meta, not for art
     * \todo don't do this for things we won't get meta for, like vids
     */

    vlc_mutex_lock( &p_item->lock );
    if( p_item->p_meta )
    {
        const char *psz_arturl = vlc_meta_Get( p_item->p_meta, vlc_meta_ArtworkURL );
        const char *psz_name = vlc_meta_Get( p_item->p_meta, vlc_meta_Title );

        if( p_preparser->i_art_policy == ALBUM_ART_ALL &&
            ( !psz_arturl || strncmp( psz_arturl, "file://", 7 ) ) )
        {
            msg_Dbg( p_playlist, "meta ok for %s, need to fetch art", psz_name );
            b_fetch = true;
        }
        else
        {
            msg_Dbg( p_playlist, "no fetch required for %s (art currently %s)",
                     psz_name, psz_arturl );
        }
    }
    vlc_mutex_unlock( &p_item->lock );

    if( b_fetch && p_fetcher )
        playlist_fetcher_Push( p_fetcher, p_item );
}
Exemple #3
0
static char *ArtCachePath( input_item_t *p_item )
{
    char psz_path[PATH_MAX+1]; /* FIXME */

    vlc_mutex_lock( &p_item->lock );

    if( !p_item->p_meta )
        p_item->p_meta = vlc_meta_New();
    if( !p_item->p_meta )
    {
        vlc_mutex_unlock( &p_item->lock );
        return NULL;
    }

    const char *psz_artist = vlc_meta_Get( p_item->p_meta, vlc_meta_Artist );
    const char *psz_album = vlc_meta_Get( p_item->p_meta, vlc_meta_Album );
    const char *psz_title = vlc_meta_Get( p_item->p_meta, vlc_meta_Title );

    if( !psz_title )
        psz_title = p_item->psz_name;

    if( (!psz_artist || !psz_album ) && !psz_title )
    {
        vlc_mutex_unlock( &p_item->lock );
        return NULL;
    }

    ArtCacheGetDirPath( psz_path, psz_title, psz_artist, psz_album );

    vlc_mutex_unlock( &p_item->lock );

    return strdup( psz_path );
}
Exemple #4
0
char *input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type )
{
    vlc_mutex_lock( &p_i->lock );

    if( !p_i->p_meta )
    {
        vlc_mutex_unlock( &p_i->lock );
        return NULL;
    }

    char *psz = NULL;
    if( vlc_meta_Get( p_i->p_meta, meta_type ) )
        psz = strdup( vlc_meta_Get( p_i->p_meta, meta_type ) );

    vlc_mutex_unlock( &p_i->lock );
    return psz;
}
Exemple #5
0
/**
 * Enable/Disable items in the playlist according to the search argument
 * @param p_root: the current root item
 * @param psz_string: the string to search
 * @return true if an item match
 */
static bool playlist_LiveSearchUpdateInternal( playlist_item_t *p_root,
                                               const char *psz_string, bool b_recursive )
{
    int i;
    bool b_match = false;
    for( i = 0 ; i < p_root->i_children ; i ++ )
    {
        bool b_enable = false;
        playlist_item_t *p_item = p_root->pp_children[i];
        // Go recurssively if their is some children
        if( b_recursive && p_item->i_children >= 0 &&
            playlist_LiveSearchUpdateInternal( p_item, psz_string, true ) )
        {
            b_enable = true;
        }

        if( !b_enable )
        {
            vlc_mutex_lock( &p_item->p_input->lock );
            // Do we have some meta ?
            if( p_item->p_input->p_meta )
            {
                // Use Title or fall back to psz_name
                const char *psz_title = vlc_meta_Get( p_item->p_input->p_meta, vlc_meta_Title );
                if( !psz_title )
                    psz_title = p_item->p_input->psz_name;
                const char *psz_album = vlc_meta_Get( p_item->p_input->p_meta, vlc_meta_Album );
                const char *psz_artist = vlc_meta_Get( p_item->p_input->p_meta, vlc_meta_Artist );
                b_enable = ( psz_title && vlc_strcasestr( psz_title, psz_string ) ) ||
                           ( psz_album && vlc_strcasestr( psz_album, psz_string ) ) ||
                           ( psz_artist && vlc_strcasestr( psz_artist, psz_string ) );
            }
            else
                b_enable = p_item->p_input->psz_name && vlc_strcasestr( p_item->p_input->psz_name, psz_string );
            vlc_mutex_unlock( &p_item->p_input->lock );
        }

        if( b_enable )
            p_item->i_flags &= ~PLAYLIST_DBL_FLAG;
        else
            p_item->i_flags |= PLAYLIST_DBL_FLAG;

        b_match |= b_enable;
   }
   return b_match;
}
Exemple #6
0
void FingerprintDialog::handleResults()
{
    p_r = t->fetchResults();

    if ( ! p_r )
    {
        ui->stackedWidget->setCurrentWidget( ui->error );
        return;
    }

    if ( vlc_array_count( & p_r->results.metas_array ) == 0 )
    {
        fingerprint_request_Delete( p_r );
        p_r = NULL;
        ui->stackedWidget->setCurrentWidget( ui->error );
        return;
    }

    ui->stackedWidget->setCurrentWidget( ui->results );

    for ( int i=0; i< vlc_array_count( & p_r->results.metas_array ) ; i++ )
    {
        vlc_meta_t *p_meta =
                (vlc_meta_t *) vlc_array_item_at_index( & p_r->results.metas_array, i );
        QListWidgetItem *item = new QListWidgetItem();
        ui->recordsList->addItem( item );
        QString mb_id( vlc_meta_GetExtra( p_meta, "musicbrainz-id" ) );
        QLabel *label = new QLabel(
                    QString( "<h3 style=\"margin: 0\"><a style=\"text-decoration:none\" href=\"%1\">%2</a></h3>"
                             "<span style=\"padding-left:20px\">%3</span>" )
                    .arg( QString( "http://mb.videolan.org/recording/%1" ).arg( mb_id ) )
                    .arg( qfu( vlc_meta_Get( p_meta, vlc_meta_Title ) ) )
                    .arg( qfu( vlc_meta_Get( p_meta, vlc_meta_Artist ) ) )
        );
        label->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
        label->setOpenExternalLinks( true );
        item->setSizeHint( label->sizeHint() );
        ui->recordsList->setItemWidget( item, label );
    }
    ui->recordsList->setCurrentIndex( ui->recordsList->model()->index( 0, 0 ) );
}
Exemple #7
0
/**
 * This function ask the fetcher object to fetch the art when needed
 */
static void Art( playlist_preparser_t *p_preparser, input_item_t *p_item )
{
    vlc_object_t *obj = p_preparser->object;
    playlist_fetcher_t *p_fetcher = p_preparser->p_fetcher;

    bool b_fetch = false;
    /* If we haven't retrieved enough meta, add to secondary queue
     * which will run the "meta fetchers".
     * This only checks for meta, not for art
     * \todo don't do this for things we won't get meta for, like vids
     */

    vlc_mutex_lock( &p_item->lock );
    if( p_item->p_meta )
    {
        const char *psz_arturl = vlc_meta_Get( p_item->p_meta, vlc_meta_ArtworkURL );
        const char *psz_name = vlc_meta_Get( p_item->p_meta, vlc_meta_Title );

        if( !psz_arturl || ( strncmp( psz_arturl, "file://", 7 ) &&
                             strncmp( psz_arturl, "attachment://", 13 ) ) )
        {
            msg_Dbg( obj, "meta ok for %s, need to fetch art",
                     psz_name ? psz_name : "(null)" );
            b_fetch = true;
        }
        else
        {
            msg_Dbg( obj, "no fetch required for %s (art currently %s)",
                     psz_name ? psz_name : "(null)",
                     psz_arturl ? psz_arturl : "(null)" );
        }
    }
    vlc_mutex_unlock( &p_item->lock );

    if( b_fetch && p_fetcher )
        playlist_fetcher_Push( p_fetcher, p_item, 0 );
}
Exemple #8
0
bool input_item_MetaMatch( input_item_t *p_i,
                           vlc_meta_type_t meta_type, const char *psz )
{
    vlc_mutex_lock( &p_i->lock );

    if( !p_i->p_meta )
    {
        vlc_mutex_unlock( &p_i->lock );
        return false;
    }
    const char *psz_meta = vlc_meta_Get( p_i->p_meta, meta_type );
    bool b_ret = psz_meta && strcasestr( psz_meta, psz );

    vlc_mutex_unlock( &p_i->lock );

    return b_ret;
}
Exemple #9
0
/**
 * Update the Extra Metadata from p_meta->i_extras
 **/
void ExtraMetaPanel::update( input_item_t *p_item )
{
    if( !p_item )
    {
        clear();
        return;
    }

    QList<QTreeWidgetItem *> items;

    extraMetaTree->clear();

    vlc_mutex_lock( &p_item->lock );
    vlc_meta_t *p_meta = p_item->p_meta;
    if( !p_meta )
    {
        vlc_mutex_unlock( &p_item->lock );
        return;
    }

    const char *psz_disc_number = vlc_meta_Get( p_meta, vlc_meta_DiscNumber);
    if( psz_disc_number )
    {
        QStringList tempItem;
        tempItem.append( VLC_META_DISCNUMBER );
        tempItem.append( qfu( psz_disc_number ) );
        items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
    }

    char ** ppsz_allkey = vlc_meta_CopyExtraNames( p_meta);

    for( int i = 0; ppsz_allkey[i] ; i++ )
    {
        const char * psz_value = vlc_meta_GetExtra( p_meta, ppsz_allkey[i] );
        QStringList tempItem;
        tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
        tempItem.append( qfu( psz_value ) );
        items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
        free( ppsz_allkey[i] );
    }
    vlc_mutex_unlock( &p_item->lock );
    free( ppsz_allkey );

    extraMetaTree->addTopLevelItems( items );
    extraMetaTree->resizeColumnToContents( 0 );
}
Exemple #10
0
/* Get the title of a given item or fallback to the name if the title is empty */
char *input_item_GetTitleFbName( input_item_t *p_item )
{
    char *psz_ret;
    vlc_mutex_lock( &p_item->lock );

    if( !p_item->p_meta )
    {
        psz_ret = p_item->psz_name ? strdup( p_item->psz_name ) : NULL;
        vlc_mutex_unlock( &p_item->lock );
        return psz_ret;
    }

    const char *psz_title = vlc_meta_Get( p_item->p_meta, vlc_meta_Title );
    if( !EMPTY_STR( psz_title ) )
        psz_ret = strdup( psz_title );
    else
        psz_ret = p_item->psz_name ? strdup( p_item->psz_name ) : NULL;

    vlc_mutex_unlock( &p_item->lock );
    return psz_ret;
}
static int GetTracks( access_t *p_access, input_item_t *p_current )
{
    access_sys_t *p_sys = p_access->p_sys;

    const int i_titles = ioctl_GetTracksMap( VLC_OBJECT(p_access),
                                             p_sys->vcddev, &p_sys->p_sectors );
    if( i_titles <= 0 )
    {
        if( i_titles < 0 )
            msg_Err( p_access, "unable to count tracks" );
        else if( i_titles <= 0 )
            msg_Err( p_access, "no audio tracks found" );
        return VLC_EGENERIC;;
    }

    /* */
    input_item_SetName( p_current, "Audio CD" );

    const char *psz_album = NULL;
    const char *psz_year = NULL;
    const char *psz_genre = NULL;
    const char *psz_artist = NULL;
    const char *psz_description = NULL;

/* Return true if the given string is not NULL and not empty */
#define NONEMPTY( psz ) ( (psz) && *(psz) )
/* If the given string is NULL or empty, fill it by the return value of 'code' */
#define ON_EMPTY( psz, code ) do { if( !NONEMPTY( psz) ) { (psz) = code; } } while(0)

    /* Retreive CDDB information */
#ifdef HAVE_LIBCDDB
    char psz_year_buffer[4+1];
    msg_Dbg( p_access, "fetching infos with CDDB" );
    cddb_disc_t *p_disc = GetCDDBInfo( p_access, i_titles, p_sys->p_sectors );
    if( p_disc )
    {
        psz_album = cddb_disc_get_title( p_disc );
        psz_genre = cddb_disc_get_genre( p_disc );

        /* */
        const unsigned i_year = cddb_disc_get_year( p_disc );
        if( i_year > 0 )
        {
            psz_year = psz_year_buffer;
            snprintf( psz_year_buffer, sizeof(psz_year_buffer), "%u", i_year );
        }

        /* Set artist only if unique */
        for( int i = 0; i < i_titles; i++ )
        {
            cddb_track_t *t = cddb_disc_get_track( p_disc, i );
            if( !t )
                continue;
            const char *psz_track_artist = cddb_track_get_artist( t );
            if( psz_artist && psz_track_artist &&
                strcmp( psz_artist, psz_track_artist ) )
            {
                psz_artist = NULL;
                break;
            }
            psz_artist = psz_track_artist;
        }
    }
#endif

    /* CD-Text */
    vlc_meta_t **pp_cd_text;
    int        i_cd_text;

    if( ioctl_GetCdText( VLC_OBJECT(p_access), p_sys->vcddev, &pp_cd_text, &i_cd_text ) )
    {
        msg_Dbg( p_access, "CD-TEXT information missing" );
        i_cd_text = 0;
        pp_cd_text = NULL;
    }

    /* Retrieve CD-TEXT information but prefer CDDB */
    if( i_cd_text > 0 && pp_cd_text[0] )
    {
        const vlc_meta_t *p_disc = pp_cd_text[0];
        ON_EMPTY( psz_album,       vlc_meta_Get( p_disc, vlc_meta_Album ) );
        ON_EMPTY( psz_genre,       vlc_meta_Get( p_disc, vlc_meta_Genre ) );
        ON_EMPTY( psz_artist,      vlc_meta_Get( p_disc, vlc_meta_Artist ) );
        ON_EMPTY( psz_description, vlc_meta_Get( p_disc, vlc_meta_Description ) );
    }

    if( NONEMPTY( psz_album ) )
    {
        input_item_SetName( p_current, psz_album );
        input_item_SetAlbum( p_current, psz_album );
    }

    if( NONEMPTY( psz_genre ) )
        input_item_SetGenre( p_current, psz_genre );

    if( NONEMPTY( psz_artist ) )
        input_item_SetArtist( p_current, psz_artist );

    if( NONEMPTY( psz_year ) )
        input_item_SetDate( p_current, psz_year );

    if( NONEMPTY( psz_description ) )
        input_item_SetDescription( p_current, psz_description );

    const mtime_t i_duration = (int64_t)( p_sys->p_sectors[i_titles] - p_sys->p_sectors[0] ) *
                               CDDA_DATA_SIZE * 1000000 / 44100 / 2 / 2;
    input_item_SetDuration( p_current, i_duration );

    input_item_node_t *p_root = input_item_node_Create( p_current );

    /* Build title table */
    for( int i = 0; i < i_titles; i++ )
    {
        input_item_t *p_input_item;

        char *psz_uri, *psz_opt, *psz_first, *psz_last;
        char *psz_name;

        msg_Dbg( p_access, "track[%d] start=%d", i, p_sys->p_sectors[i] );

        /* */
        if( asprintf( &psz_uri, "cdda://%s", p_access->psz_location ) == -1 )
            psz_uri = NULL;
        if( asprintf( &psz_opt, "cdda-track=%i", i+1 ) == -1 )
            psz_opt = NULL;
        if( asprintf( &psz_first, "cdda-first-sector=%i",p_sys->p_sectors[i] ) == -1 )
            psz_first = NULL;
        if( asprintf( &psz_last, "cdda-last-sector=%i", p_sys->p_sectors[i+1] ) == -1 )
            psz_last = NULL;

        /* Define a "default name" */
        if( asprintf( &psz_name, _("Audio CD - Track %02i"), (i+1) ) == -1 )
            psz_name = NULL;

        /* Create playlist items */
        const mtime_t i_duration = (int64_t)( p_sys->p_sectors[i+1] - p_sys->p_sectors[i] ) *
                                   CDDA_DATA_SIZE * 1000000 / 44100 / 2 / 2;
        p_input_item = input_item_NewWithType( psz_uri, psz_name, 0, NULL, 0,
                                               i_duration, ITEM_TYPE_DISC );
        input_item_CopyOptions( p_current, p_input_item );
        input_item_AddOption( p_input_item, psz_first, VLC_INPUT_OPTION_TRUSTED );
        input_item_AddOption( p_input_item, psz_last, VLC_INPUT_OPTION_TRUSTED );
        input_item_AddOption( p_input_item, psz_opt, VLC_INPUT_OPTION_TRUSTED );

        const char *psz_track_title = NULL;
        const char *psz_track_artist = NULL;
        const char *psz_track_genre = NULL;
        const char *psz_track_description = NULL;

#ifdef HAVE_LIBCDDB
        /* Retreive CDDB information */
        if( p_disc )
        {
            cddb_track_t *t = cddb_disc_get_track( p_disc, i );
            if( t != NULL )
            {
                psz_track_title = cddb_track_get_title( t );
                psz_track_artist = cddb_track_get_artist( t );
            }
        }
#endif

        /* Retreive CD-TEXT information but prefer CDDB */
        if( i+1 < i_cd_text && pp_cd_text[i+1] )
        {
            const vlc_meta_t *t = pp_cd_text[i+1];

            ON_EMPTY( psz_track_title,       vlc_meta_Get( t, vlc_meta_Title ) );
            ON_EMPTY( psz_track_artist,      vlc_meta_Get( t, vlc_meta_Artist ) );
            ON_EMPTY( psz_track_genre,       vlc_meta_Get( t, vlc_meta_Genre ) );
            ON_EMPTY( psz_track_description, vlc_meta_Get( t, vlc_meta_Description ) );
        }

        /* */
        ON_EMPTY( psz_track_artist,       psz_artist );
        ON_EMPTY( psz_track_genre,        psz_genre );
        ON_EMPTY( psz_track_description,  psz_description );

        /* */
        if( NONEMPTY( psz_track_title ) )
        {
            input_item_SetName( p_input_item, psz_track_title );
            input_item_SetTitle( p_input_item, psz_track_title );
        }

        if( NONEMPTY( psz_track_artist ) )
            input_item_SetArtist( p_input_item, psz_track_artist );

        if( NONEMPTY( psz_track_genre ) )
            input_item_SetGenre( p_input_item, psz_track_genre );

        if( NONEMPTY( psz_track_description ) )
            input_item_SetDescription( p_input_item, psz_track_description );

        if( NONEMPTY( psz_album ) )
            input_item_SetAlbum( p_input_item, psz_album );

        if( NONEMPTY( psz_year ) )
            input_item_SetDate( p_input_item, psz_year );

        char psz_num[3+1];
        snprintf( psz_num, sizeof(psz_num), "%d", 1+i );
        input_item_SetTrackNum( p_input_item, psz_num );

        input_item_node_AppendItem( p_root, p_input_item );
        vlc_gc_decref( p_input_item );
        free( psz_uri ); free( psz_opt ); free( psz_name );
        free( psz_first ); free( psz_last );
    }
#undef ON_EMPTY
#undef NONEMPTY

    input_item_node_PostAndDelete( p_root );

    /* */
    for( int i = 0; i < i_cd_text; i++ )
    {
        vlc_meta_t *p_meta = pp_cd_text[i];
        if( !p_meta )
            continue;
        vlc_meta_Delete( p_meta );
    }
    free( pp_cd_text );

#ifdef HAVE_LIBCDDB
    if( p_disc )
        cddb_disc_destroy( p_disc );
#endif
    return VLC_SUCCESS;
}