2009-04-05 03:51:40 -04:00
|
|
|
/*
|
2011-06-02 15:25:13 -04:00
|
|
|
* Copyright (C) 2009-2011 Julien BLACHE <jb@jblache.org>
|
2009-04-05 03:51:40 -04:00
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2010-02-02 15:00:47 -05:00
|
|
|
# include <config.h>
|
2009-04-05 03:51:40 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_STDINT_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#include <libavformat/avformat.h>
|
2014-06-01 18:00:52 -04:00
|
|
|
#include <libavutil/opt.h>
|
2009-04-05 03:51:40 -04:00
|
|
|
|
2009-05-08 11:46:32 -04:00
|
|
|
#include "logger.h"
|
2009-04-20 10:53:47 -04:00
|
|
|
#include "filescanner.h"
|
2010-03-28 08:19:36 -04:00
|
|
|
#include "misc.h"
|
2009-04-05 03:51:40 -04:00
|
|
|
|
|
|
|
|
2009-04-05 07:22:47 -04:00
|
|
|
/* Legacy format-specific scanners */
|
2009-06-07 12:58:02 -04:00
|
|
|
extern int scan_get_wmainfo(char *filename, struct media_file_info *pmp3);
|
2009-04-05 07:22:47 -04:00
|
|
|
#ifdef FLAC
|
2009-06-07 12:58:02 -04:00
|
|
|
extern int scan_get_flacinfo(char *filename, struct media_file_info *pmp3);
|
2009-04-05 07:22:47 -04:00
|
|
|
#endif
|
|
|
|
#ifdef MUSEPACK
|
2009-06-07 12:58:02 -04:00
|
|
|
extern int scan_get_mpcinfo(char *filename, struct media_file_info *pmp3);
|
2009-04-05 07:22:47 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-04-05 03:51:40 -04:00
|
|
|
/* Mapping between the metadata name(s) and the offset
|
|
|
|
* of the equivalent metadata field in struct media_file_info */
|
|
|
|
struct metadata_map {
|
|
|
|
char *key;
|
|
|
|
int as_int;
|
|
|
|
size_t offset;
|
2010-04-10 04:59:29 -04:00
|
|
|
int (*handler_function)(struct media_file_info *, char *);
|
2009-04-05 03:51:40 -04:00
|
|
|
};
|
|
|
|
|
2011-06-02 15:25:13 -04:00
|
|
|
static int
|
|
|
|
parse_slash_separated_ints(char *string, uint32_t *firstval, uint32_t *secondval)
|
|
|
|
{
|
|
|
|
int numvals = 0;
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
ptr = strchr(string, '/');
|
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
*ptr = '\0';
|
|
|
|
if (safe_atou32(ptr + 1, secondval) == 0)
|
|
|
|
numvals++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (safe_atou32(string, firstval) == 0)
|
|
|
|
numvals++;
|
|
|
|
|
|
|
|
return numvals;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
parse_track(struct media_file_info *mfi, char *track_string)
|
|
|
|
{
|
|
|
|
uint32_t *track = (uint32_t *) ((char *) mfi + mfi_offsetof(track));
|
|
|
|
uint32_t *total_tracks = (uint32_t *) ((char *) mfi + mfi_offsetof(total_tracks));
|
|
|
|
|
|
|
|
return parse_slash_separated_ints(track_string, track, total_tracks);
|
|
|
|
}
|
|
|
|
|
2011-06-04 06:08:50 -04:00
|
|
|
static int
|
|
|
|
parse_disc(struct media_file_info *mfi, char *disc_string)
|
|
|
|
{
|
|
|
|
uint32_t *disc = (uint32_t *) ((char *) mfi + mfi_offsetof(disc));
|
|
|
|
uint32_t *total_discs = (uint32_t *) ((char *) mfi + mfi_offsetof(total_discs));
|
|
|
|
|
|
|
|
return parse_slash_separated_ints(disc_string, disc, total_discs);
|
|
|
|
}
|
|
|
|
|
2009-04-05 03:51:40 -04:00
|
|
|
/* Lookup is case-insensitive, first occurrence takes precedence */
|
2010-03-23 13:55:39 -04:00
|
|
|
static const struct metadata_map md_map_generic[] =
|
2009-04-05 03:51:40 -04:00
|
|
|
{
|
2010-04-10 04:59:29 -04:00
|
|
|
{ "title", 0, mfi_offsetof(title), NULL },
|
|
|
|
{ "artist", 0, mfi_offsetof(artist), NULL },
|
|
|
|
{ "author", 0, mfi_offsetof(artist), NULL },
|
|
|
|
{ "album_artist", 0, mfi_offsetof(album_artist), NULL },
|
|
|
|
{ "album", 0, mfi_offsetof(album), NULL },
|
|
|
|
{ "genre", 0, mfi_offsetof(genre), NULL },
|
|
|
|
{ "composer", 0, mfi_offsetof(composer), NULL },
|
|
|
|
{ "grouping", 0, mfi_offsetof(grouping), NULL },
|
|
|
|
{ "orchestra", 0, mfi_offsetof(orchestra), NULL },
|
|
|
|
{ "conductor", 0, mfi_offsetof(conductor), NULL },
|
|
|
|
{ "comment", 0, mfi_offsetof(comment), NULL },
|
|
|
|
{ "description", 0, mfi_offsetof(comment), NULL },
|
2011-06-02 16:12:28 -04:00
|
|
|
{ "track", 1, mfi_offsetof(track), parse_track },
|
2011-06-04 06:09:38 -04:00
|
|
|
{ "disc", 1, mfi_offsetof(disc), parse_disc },
|
2010-04-10 04:59:29 -04:00
|
|
|
{ "year", 1, mfi_offsetof(year), NULL },
|
|
|
|
{ "date", 1, mfi_offsetof(year), NULL },
|
2011-06-02 15:24:23 -04:00
|
|
|
{ "title-sort", 0, mfi_offsetof(title_sort), NULL },
|
|
|
|
{ "artist-sort", 0, mfi_offsetof(artist_sort), NULL },
|
|
|
|
{ "album-sort", 0, mfi_offsetof(album_sort), NULL },
|
2010-04-10 04:59:29 -04:00
|
|
|
|
|
|
|
{ NULL, 0, 0, NULL }
|
2010-03-22 13:22:39 -04:00
|
|
|
};
|
|
|
|
|
2010-03-23 13:55:39 -04:00
|
|
|
static const struct metadata_map md_map_tv[] =
|
2010-03-22 13:22:39 -04:00
|
|
|
{
|
2010-04-10 04:59:29 -04:00
|
|
|
{ "stik", 1, mfi_offsetof(media_kind), NULL },
|
|
|
|
{ "show", 0, mfi_offsetof(tv_series_name), NULL },
|
|
|
|
{ "episode_id", 0, mfi_offsetof(tv_episode_num_str), NULL },
|
|
|
|
{ "network", 0, mfi_offsetof(tv_network_name), NULL },
|
|
|
|
{ "episode_sort", 1, mfi_offsetof(tv_episode_sort), NULL },
|
|
|
|
{ "season_number",1, mfi_offsetof(tv_season_num), NULL },
|
|
|
|
|
|
|
|
{ NULL, 0, 0, NULL }
|
2009-04-05 03:51:40 -04:00
|
|
|
};
|
|
|
|
|
2010-03-28 07:24:05 -04:00
|
|
|
/* NOTE about VORBIS comments:
|
|
|
|
* Only a small set of VORBIS comment fields are officially designated. Most
|
|
|
|
* common tags are at best de facto standards. Currently, metadata conversion
|
|
|
|
* functionality in ffmpeg only adds support for a couple of tags. Specifically,
|
|
|
|
* ALBUMARTIST and TRACKNUMBER are handled as of Feb 1, 2010 (rev 21587). Tags
|
|
|
|
* with names that already match the generic ffmpeg scheme--TITLE and ARTIST,
|
|
|
|
* for example--are of course handled. The rest of these tags are reported to
|
|
|
|
* have been used by various programs in the wild.
|
|
|
|
*/
|
|
|
|
static const struct metadata_map md_map_vorbis[] =
|
|
|
|
{
|
2010-04-10 04:59:29 -04:00
|
|
|
{ "albumartist", 0, mfi_offsetof(album_artist), NULL },
|
|
|
|
{ "album artist", 0, mfi_offsetof(album_artist), NULL },
|
|
|
|
{ "tracknumber", 1, mfi_offsetof(track), NULL },
|
|
|
|
{ "tracktotal", 1, mfi_offsetof(total_tracks), NULL },
|
|
|
|
{ "totaltracks", 1, mfi_offsetof(total_tracks), NULL },
|
|
|
|
{ "discnumber", 1, mfi_offsetof(disc), NULL },
|
|
|
|
{ "disctotal", 1, mfi_offsetof(total_discs), NULL },
|
|
|
|
{ "totaldiscs", 1, mfi_offsetof(total_discs), NULL },
|
|
|
|
|
|
|
|
{ NULL, 0, 0, NULL }
|
2010-03-28 07:24:05 -04:00
|
|
|
};
|
|
|
|
|
2010-03-22 13:22:39 -04:00
|
|
|
/* NOTE about ID3 tag names:
|
|
|
|
* metadata conversion for ID3v2 tags was added in ffmpeg in september 2009
|
|
|
|
* (rev 20073) for ID3v2.3; support for ID3v2.2 tag names was added in december
|
|
|
|
* 2009 (rev 20839).
|
|
|
|
*
|
|
|
|
* ID3v2.x tags will be removed from the map once a version of ffmpeg containing
|
|
|
|
* the changes listed above will be generally available. The more entries in the
|
|
|
|
* map, the slower the filescanner gets.
|
|
|
|
*/
|
2010-03-23 13:55:39 -04:00
|
|
|
static const struct metadata_map md_map_id3[] =
|
2010-03-22 13:22:39 -04:00
|
|
|
{
|
2010-10-07 14:36:59 -04:00
|
|
|
{ "TT2", 0, mfi_offsetof(title), NULL }, /* ID3v2.2 */
|
|
|
|
{ "TIT2", 0, mfi_offsetof(title), NULL }, /* ID3v2.3 */
|
|
|
|
{ "TP1", 0, mfi_offsetof(artist), NULL }, /* ID3v2.2 */
|
|
|
|
{ "TPE1", 0, mfi_offsetof(artist), NULL }, /* ID3v2.3 */
|
|
|
|
{ "TP2", 0, mfi_offsetof(album_artist), NULL }, /* ID3v2.2 */
|
|
|
|
{ "TPE2", 0, mfi_offsetof(album_artist), NULL }, /* ID3v2.3 */
|
|
|
|
{ "TAL", 0, mfi_offsetof(album), NULL }, /* ID3v2.2 */
|
|
|
|
{ "TALB", 0, mfi_offsetof(album), NULL }, /* ID3v2.3 */
|
|
|
|
{ "TCO", 0, mfi_offsetof(genre), NULL }, /* ID3v2.2 */
|
|
|
|
{ "TCON", 0, mfi_offsetof(genre), NULL }, /* ID3v2.3 */
|
|
|
|
{ "TCM", 0, mfi_offsetof(composer), NULL }, /* ID3v2.2 */
|
|
|
|
{ "TCOM", 0, mfi_offsetof(composer), NULL }, /* ID3v2.3 */
|
2011-06-02 15:25:13 -04:00
|
|
|
{ "TRK", 1, mfi_offsetof(track), parse_track }, /* ID3v2.2 */
|
|
|
|
{ "TRCK", 1, mfi_offsetof(track), parse_track }, /* ID3v2.3 */
|
2011-06-04 06:08:50 -04:00
|
|
|
{ "TPA", 1, mfi_offsetof(disc), parse_disc }, /* ID3v2.2 */
|
|
|
|
{ "TPOS", 1, mfi_offsetof(disc), parse_disc }, /* ID3v2.3 */
|
2010-10-07 14:36:59 -04:00
|
|
|
{ "TYE", 1, mfi_offsetof(year), NULL }, /* ID3v2.2 */
|
|
|
|
{ "TYER", 1, mfi_offsetof(year), NULL }, /* ID3v2.3 */
|
|
|
|
{ "TDRC", 1, mfi_offsetof(year), NULL }, /* ID3v2.4 */
|
|
|
|
{ "TSOA", 0, mfi_offsetof(album_sort), NULL }, /* ID3v2.4 */
|
|
|
|
{ "XSOA", 0, mfi_offsetof(album_sort), NULL }, /* ID3v2.3 */
|
|
|
|
{ "TSOP", 0, mfi_offsetof(artist_sort), NULL }, /* ID3v2.4 */
|
|
|
|
{ "XSOP", 0, mfi_offsetof(artist_sort), NULL }, /* ID3v2.3 */
|
|
|
|
{ "TSOT", 0, mfi_offsetof(title_sort), NULL }, /* ID3v2.4 */
|
|
|
|
{ "XSOT", 0, mfi_offsetof(title_sort), NULL }, /* ID3v2.3 */
|
|
|
|
{ "TS2", 0, mfi_offsetof(album_artist_sort), NULL }, /* ID3v2.2 */
|
|
|
|
{ "TSO2", 0, mfi_offsetof(album_artist_sort), NULL }, /* ID3v2.3 */
|
2010-09-21 13:43:05 -04:00
|
|
|
{ "ALBUMARTISTSORT", 0, mfi_offsetof(album_artist_sort), NULL }, /* ID3v2.x */
|
2010-10-07 14:36:59 -04:00
|
|
|
{ "TSC", 0, mfi_offsetof(composer_sort), NULL }, /* ID3v2.2 */
|
|
|
|
{ "TSOC", 0, mfi_offsetof(composer_sort), NULL }, /* ID3v2.3 */
|
2010-04-10 04:59:29 -04:00
|
|
|
|
2010-10-07 14:36:59 -04:00
|
|
|
{ NULL, 0, 0, NULL }
|
2010-03-22 13:22:39 -04:00
|
|
|
};
|
|
|
|
|
2009-04-05 03:51:40 -04:00
|
|
|
|
2010-03-22 13:22:39 -04:00
|
|
|
static int
|
2013-11-25 13:43:17 -05:00
|
|
|
#if LIBAVUTIL_VERSION_MAJOR >= 52 || (LIBAVUTIL_VERSION_MAJOR == 51 && LIBAVUTIL_VERSION_MINOR >= 5)
|
2011-09-10 06:31:43 -04:00
|
|
|
extract_metadata_core(struct media_file_info *mfi, AVDictionary *md, const struct metadata_map *md_map)
|
|
|
|
#else
|
2010-03-23 13:55:39 -04:00
|
|
|
extract_metadata_core(struct media_file_info *mfi, AVMetadata *md, const struct metadata_map *md_map)
|
2011-09-10 06:31:43 -04:00
|
|
|
#endif
|
2010-03-22 13:22:39 -04:00
|
|
|
{
|
2013-11-25 13:43:17 -05:00
|
|
|
#if LIBAVUTIL_VERSION_MAJOR >= 52 || (LIBAVUTIL_VERSION_MAJOR == 51 && LIBAVUTIL_VERSION_MINOR >= 5)
|
2011-09-10 06:31:43 -04:00
|
|
|
AVDictionaryEntry *mdt;
|
|
|
|
#else
|
2010-03-22 13:22:39 -04:00
|
|
|
AVMetadataTag *mdt;
|
2011-09-10 06:31:43 -04:00
|
|
|
#endif
|
2010-03-22 13:22:39 -04:00
|
|
|
char **strval;
|
|
|
|
uint32_t *intval;
|
|
|
|
int mdcount;
|
|
|
|
int i;
|
2010-05-09 02:54:06 -04:00
|
|
|
int ret;
|
2010-03-22 13:22:39 -04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Dump all the metadata reported by ffmpeg */
|
|
|
|
mdt = NULL;
|
2013-11-25 13:43:17 -05:00
|
|
|
#if LIBAVUTIL_VERSION_MAJOR >= 52 || (LIBAVUTIL_VERSION_MAJOR == 51 && LIBAVUTIL_VERSION_MINOR >= 5)
|
2011-09-10 06:31:43 -04:00
|
|
|
while ((mdt = av_dict_get(md, "", mdt, AV_DICT_IGNORE_SUFFIX)) != NULL)
|
|
|
|
#else
|
2010-03-22 13:22:39 -04:00
|
|
|
while ((mdt = av_metadata_get(md, "", mdt, AV_METADATA_IGNORE_SUFFIX)) != NULL)
|
2011-09-10 06:31:43 -04:00
|
|
|
#endif
|
2010-03-22 13:22:39 -04:00
|
|
|
fprintf(stderr, " -> %s = %s\n", mdt->key, mdt->value);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mdcount = 0;
|
|
|
|
|
|
|
|
/* Extract actual metadata */
|
|
|
|
for (i = 0; md_map[i].key != NULL; i++)
|
|
|
|
{
|
2013-11-25 13:43:17 -05:00
|
|
|
#if LIBAVUTIL_VERSION_MAJOR >= 52 || (LIBAVUTIL_VERSION_MAJOR == 51 && LIBAVUTIL_VERSION_MINOR >= 5)
|
2011-09-10 06:31:43 -04:00
|
|
|
mdt = av_dict_get(md, md_map[i].key, NULL, 0);
|
|
|
|
#else
|
2010-03-22 13:22:39 -04:00
|
|
|
mdt = av_metadata_get(md, md_map[i].key, NULL, 0);
|
2011-09-10 06:31:43 -04:00
|
|
|
#endif
|
2010-03-22 13:22:39 -04:00
|
|
|
if (mdt == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((mdt->value == NULL) || (strlen(mdt->value) == 0))
|
|
|
|
continue;
|
|
|
|
|
2010-03-28 08:19:36 -04:00
|
|
|
if (md_map[i].handler_function)
|
|
|
|
{
|
|
|
|
mdcount += md_map[i].handler_function(mfi, mdt->value);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-03-22 13:22:39 -04:00
|
|
|
mdcount++;
|
|
|
|
|
|
|
|
if (!md_map[i].as_int)
|
|
|
|
{
|
|
|
|
strval = (char **) ((char *) mfi + md_map[i].offset);
|
|
|
|
|
|
|
|
if (*strval == NULL)
|
|
|
|
*strval = strdup(mdt->value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
intval = (uint32_t *) ((char *) mfi + md_map[i].offset);
|
|
|
|
|
|
|
|
if (*intval == 0)
|
|
|
|
{
|
2010-05-09 02:54:06 -04:00
|
|
|
ret = safe_atou32(mdt->value, intval);
|
|
|
|
if (ret < 0)
|
2010-03-22 13:22:39 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mdcount;
|
|
|
|
}
|
|
|
|
|
2010-03-22 13:22:39 -04:00
|
|
|
static int
|
2010-04-08 11:10:15 -04:00
|
|
|
extract_metadata(struct media_file_info *mfi, AVFormatContext *ctx, AVStream *audio_stream, AVStream *video_stream, const struct metadata_map *md_map)
|
2010-03-22 13:22:39 -04:00
|
|
|
{
|
|
|
|
int mdcount;
|
2010-04-08 11:10:15 -04:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
mdcount = 0;
|
2010-03-22 13:22:39 -04:00
|
|
|
|
2010-04-08 11:10:15 -04:00
|
|
|
if (ctx->metadata)
|
|
|
|
{
|
|
|
|
ret = extract_metadata_core(mfi, ctx->metadata, md_map);
|
|
|
|
mdcount += ret;
|
2010-03-22 13:22:39 -04:00
|
|
|
|
2010-04-08 11:10:15 -04:00
|
|
|
DPRINTF(E_DBG, L_SCAN, "Picked up %d tags from file metadata\n", ret);
|
|
|
|
}
|
2010-03-22 13:22:39 -04:00
|
|
|
|
2010-04-08 11:10:15 -04:00
|
|
|
if (audio_stream->metadata)
|
2010-03-22 13:22:39 -04:00
|
|
|
{
|
2010-04-08 11:10:15 -04:00
|
|
|
ret = extract_metadata_core(mfi, audio_stream->metadata, md_map);
|
|
|
|
mdcount += ret;
|
2010-03-22 13:22:39 -04:00
|
|
|
|
2010-04-08 11:10:15 -04:00
|
|
|
DPRINTF(E_DBG, L_SCAN, "Picked up %d tags from audio stream metadata\n", ret);
|
|
|
|
}
|
2010-03-22 13:22:39 -04:00
|
|
|
|
2010-04-08 11:10:15 -04:00
|
|
|
if (video_stream && video_stream->metadata)
|
|
|
|
{
|
|
|
|
ret = extract_metadata_core(mfi, video_stream->metadata, md_map);
|
|
|
|
mdcount += ret;
|
|
|
|
|
|
|
|
DPRINTF(E_DBG, L_SCAN, "Picked up %d tags from video stream metadata\n", ret);
|
2010-03-22 13:22:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return mdcount;
|
|
|
|
}
|
|
|
|
|
2014-06-16 17:46:30 -04:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR >= 56 || (LIBAVFORMAT_VERSION_MAJOR == 55 && LIBAVFORMAT_VERSION_MINOR >= 13)
|
|
|
|
/* Extracts ICY metadata (requires libav 10) */
|
2014-06-01 18:00:52 -04:00
|
|
|
static void
|
|
|
|
extract_metadata_icy(struct media_file_info *mfi, AVFormatContext *ctx)
|
|
|
|
{
|
|
|
|
uint8_t *icy_meta;
|
|
|
|
char *icy_token;
|
|
|
|
char *icy_str;
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
icy_meta = NULL;
|
|
|
|
// TODO Also get icy_metadata_packet to show current track
|
|
|
|
av_opt_get(ctx, "icy_metadata_headers", AV_OPT_SEARCH_CHILDREN, &icy_meta);
|
|
|
|
|
|
|
|
if (!icy_meta)
|
|
|
|
return;
|
|
|
|
|
|
|
|
icy_str = strdup((char *)icy_meta);
|
|
|
|
icy_token = strtok(icy_str, "\r\n");
|
|
|
|
|
|
|
|
while (icy_token != NULL)
|
|
|
|
{
|
|
|
|
ptr = strchr(icy_token, ':');
|
2014-06-02 15:51:50 -04:00
|
|
|
if (!ptr || (strlen(ptr) < 4))
|
|
|
|
{
|
|
|
|
icy_token = strtok(NULL, "\r\n");
|
|
|
|
continue;
|
|
|
|
}
|
2014-06-01 18:00:52 -04:00
|
|
|
|
|
|
|
ptr++;
|
|
|
|
if (ptr[0] == ' ')
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if (strstr(icy_token, "icy-name"))
|
|
|
|
{
|
|
|
|
DPRINTF(E_DBG, L_SCAN, "Libav/ffmpeg found ICY metadata, name is '%s'\n", ptr);
|
|
|
|
|
|
|
|
if (mfi->title)
|
|
|
|
free(mfi->title);
|
|
|
|
if (mfi->artist)
|
|
|
|
free(mfi->artist);
|
|
|
|
if (mfi->album_artist)
|
|
|
|
free(mfi->album_artist);
|
|
|
|
|
|
|
|
mfi->title = strdup(ptr);
|
|
|
|
mfi->artist = strdup(ptr);
|
|
|
|
mfi->album_artist = strdup(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr(icy_token, "icy-description"))
|
|
|
|
{
|
|
|
|
DPRINTF(E_DBG, L_SCAN, "Libav/ffmpeg found ICY metadata, description is '%s'\n", ptr);
|
|
|
|
|
|
|
|
if (mfi->album)
|
|
|
|
free(mfi->album);
|
|
|
|
|
|
|
|
mfi->album = strdup(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr(icy_token, "icy-genre"))
|
|
|
|
{
|
|
|
|
DPRINTF(E_DBG, L_SCAN, "Libav/ffmpeg found ICY metadata, genre is '%s'\n", ptr);
|
|
|
|
|
|
|
|
if (mfi->genre)
|
|
|
|
free(mfi->genre);
|
|
|
|
|
|
|
|
mfi->genre = strdup(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
icy_token = strtok(NULL, "\r\n");
|
|
|
|
}
|
|
|
|
av_free(icy_meta);
|
|
|
|
free(icy_str);
|
|
|
|
}
|
2014-06-16 17:46:30 -04:00
|
|
|
#endif
|
2014-06-01 18:00:52 -04:00
|
|
|
|
2009-04-20 11:34:39 -04:00
|
|
|
int
|
|
|
|
scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
|
2009-04-05 03:51:40 -04:00
|
|
|
{
|
|
|
|
AVFormatContext *ctx;
|
2014-06-01 18:00:52 -04:00
|
|
|
AVDictionary *options;
|
2010-03-23 13:55:39 -04:00
|
|
|
const struct metadata_map *extra_md_map;
|
2014-01-27 15:24:08 -05:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
|
|
|
|
enum AVCodecID codec_id;
|
|
|
|
enum AVCodecID video_codec_id;
|
|
|
|
enum AVCodecID audio_codec_id;
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
enum CodecID codec_id;
|
|
|
|
enum CodecID video_codec_id;
|
|
|
|
enum CodecID audio_codec_id;
|
2014-01-27 15:24:08 -05:00
|
|
|
#endif
|
2010-03-23 13:48:32 -04:00
|
|
|
AVStream *video_stream;
|
|
|
|
AVStream *audio_stream;
|
2009-04-05 03:51:40 -04:00
|
|
|
int mdcount;
|
|
|
|
int i;
|
|
|
|
int ret;
|
|
|
|
|
2011-09-10 06:04:01 -04:00
|
|
|
ctx = NULL;
|
2014-06-01 18:00:52 -04:00
|
|
|
options = NULL;
|
2011-09-10 06:04:01 -04:00
|
|
|
|
2013-11-25 13:43:17 -05:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 3)
|
2014-06-01 18:00:52 -04:00
|
|
|
if (mfi->data_kind == 1)
|
|
|
|
av_dict_set(&options, "icy", "1", 0);
|
|
|
|
|
|
|
|
ret = avformat_open_input(&ctx, file, NULL, &options);
|
2011-09-10 06:04:01 -04:00
|
|
|
#else
|
2009-04-20 11:34:39 -04:00
|
|
|
ret = av_open_input_file(&ctx, file, NULL, 0, NULL);
|
2011-09-10 06:04:01 -04:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
2009-04-20 11:34:39 -04:00
|
|
|
DPRINTF(E_WARN, L_SCAN, "Cannot open media file '%s': %s\n", file, strerror(AVUNERROR(ret)));
|
2009-04-05 03:51:40 -04:00
|
|
|
|
2009-04-20 11:34:39 -04:00
|
|
|
return -1;
|
2009-04-05 03:51:40 -04:00
|
|
|
}
|
|
|
|
|
2013-11-25 13:43:17 -05:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 3)
|
2013-09-07 17:39:22 -04:00
|
|
|
ret = avformat_find_stream_info(ctx, NULL);
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
ret = av_find_stream_info(ctx);
|
2013-09-07 17:39:22 -04:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_WARN, L_SCAN, "Cannot get stream info: %s\n", strerror(AVUNERROR(ret)));
|
|
|
|
|
2013-09-07 17:39:22 -04:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
|
|
|
avformat_close_input(&ctx);
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
av_close_input_file(ctx);
|
2013-09-07 17:39:22 -04:00
|
|
|
#endif
|
2009-04-20 11:34:39 -04:00
|
|
|
return -1;
|
2009-04-05 03:51:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Dump input format as determined by ffmpeg */
|
2013-11-25 13:43:17 -05:00
|
|
|
# if LIBAVFORMAT_VERSION_MAJOR >= 53 || (LIBAVFORMAT_VERSION_MAJOR == 52 && LIBAVFORMAT_VERSION_MINOR >= 101)
|
2011-09-10 06:25:52 -04:00
|
|
|
av_dump_format(ctx, 0, file, 0);
|
|
|
|
# else
|
2009-04-20 11:34:39 -04:00
|
|
|
dump_format(ctx, 0, file, FALSE);
|
2011-09-10 06:25:52 -04:00
|
|
|
# endif
|
2009-04-05 03:51:40 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
DPRINTF(E_DBG, L_SCAN, "File has %d streams\n", ctx->nb_streams);
|
|
|
|
|
|
|
|
/* Extract codec IDs, check for video */
|
2014-02-17 17:05:24 -05:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
|
|
|
|
video_codec_id = AV_CODEC_ID_NONE;
|
|
|
|
video_stream = NULL;
|
|
|
|
|
|
|
|
audio_codec_id = AV_CODEC_ID_NONE;
|
|
|
|
audio_stream = NULL;
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
video_codec_id = CODEC_ID_NONE;
|
2010-03-23 13:48:32 -04:00
|
|
|
video_stream = NULL;
|
2009-04-05 03:51:40 -04:00
|
|
|
|
|
|
|
audio_codec_id = CODEC_ID_NONE;
|
2010-03-23 13:48:32 -04:00
|
|
|
audio_stream = NULL;
|
2014-02-17 17:05:24 -05:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
|
|
|
|
for (i = 0; i < ctx->nb_streams; i++)
|
|
|
|
{
|
|
|
|
switch (ctx->streams[i]->codec->codec_type)
|
|
|
|
{
|
2011-06-02 11:06:20 -04:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 53 || (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR >= 64)
|
|
|
|
case AVMEDIA_TYPE_VIDEO:
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
case CODEC_TYPE_VIDEO:
|
2011-06-02 11:06:20 -04:00
|
|
|
#endif
|
2014-01-11 17:37:04 -05:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR >= 55 || (LIBAVFORMAT_VERSION_MAJOR == 54 && LIBAVFORMAT_VERSION_MINOR >= 6)
|
2013-12-29 14:44:32 -05:00
|
|
|
if (ctx->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC)
|
|
|
|
{
|
|
|
|
DPRINTF(E_DBG, L_SCAN, "Found embedded artwork (stream %d)\n", i);
|
2014-01-11 17:05:29 -05:00
|
|
|
mfi->artwork = ARTWORK_EMBEDDED;
|
2013-12-29 14:44:32 -05:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2014-01-06 15:41:30 -05:00
|
|
|
#endif
|
2010-03-23 13:48:32 -04:00
|
|
|
if (!video_stream)
|
2009-04-05 03:51:40 -04:00
|
|
|
{
|
|
|
|
DPRINTF(E_DBG, L_SCAN, "File has video (stream %d)\n", i);
|
|
|
|
|
|
|
|
mfi->has_video = 1;
|
2010-03-23 13:48:32 -04:00
|
|
|
video_stream = ctx->streams[i];
|
|
|
|
video_codec_id = video_stream->codec->codec_id;
|
2009-04-05 03:51:40 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-06-02 11:06:20 -04:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 53 || (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR >= 64)
|
|
|
|
case AVMEDIA_TYPE_AUDIO:
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
case CODEC_TYPE_AUDIO:
|
2011-06-02 11:06:20 -04:00
|
|
|
#endif
|
2010-03-23 13:48:32 -04:00
|
|
|
if (!audio_stream)
|
2009-04-05 03:51:40 -04:00
|
|
|
{
|
2010-03-23 13:48:32 -04:00
|
|
|
audio_stream = ctx->streams[i];
|
|
|
|
audio_codec_id = audio_stream->codec->codec_id;
|
2009-04-05 03:51:40 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-17 17:05:24 -05:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
|
|
|
|
if (audio_codec_id == AV_CODEC_ID_NONE)
|
|
|
|
#else
|
2009-11-01 06:52:30 -05:00
|
|
|
if (audio_codec_id == CODEC_ID_NONE)
|
2014-02-17 17:05:24 -05:00
|
|
|
#endif
|
2009-11-01 06:52:30 -05:00
|
|
|
{
|
|
|
|
DPRINTF(E_DBG, L_SCAN, "File has no audio streams, discarding\n");
|
|
|
|
|
2013-09-07 17:39:22 -04:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
|
|
|
avformat_close_input(&ctx);
|
|
|
|
#else
|
2009-11-01 06:52:30 -05:00
|
|
|
av_close_input_file(ctx);
|
2013-09-07 17:39:22 -04:00
|
|
|
#endif
|
2009-11-01 06:52:30 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-04-05 03:51:40 -04:00
|
|
|
/* Common media information */
|
|
|
|
if (ctx->duration > 0)
|
|
|
|
mfi->song_length = ctx->duration / (AV_TIME_BASE / 1000); /* ms */
|
|
|
|
|
|
|
|
if (ctx->bit_rate > 0)
|
|
|
|
mfi->bitrate = ctx->bit_rate / 1000;
|
2009-11-01 06:51:50 -05:00
|
|
|
else if (ctx->duration > AV_TIME_BASE) /* guesstimate */
|
2009-04-05 03:51:40 -04:00
|
|
|
mfi->bitrate = ((mfi->file_size * 8) / (ctx->duration / AV_TIME_BASE)) / 1000;
|
|
|
|
|
|
|
|
DPRINTF(E_DBG, L_SCAN, "Duration %d ms, bitrate %d kbps\n", mfi->song_length, mfi->bitrate);
|
|
|
|
|
2014-06-16 17:46:30 -04:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR >= 56 || (LIBAVFORMAT_VERSION_MAJOR == 55 && LIBAVFORMAT_VERSION_MINOR >= 13)
|
2014-06-01 18:00:52 -04:00
|
|
|
/* Try to extract ICY metadata if url/stream */
|
|
|
|
if (mfi->data_kind == 1)
|
|
|
|
extract_metadata_icy(mfi, ctx);
|
2014-06-16 17:46:30 -04:00
|
|
|
#endif
|
2014-06-01 18:00:52 -04:00
|
|
|
|
2009-04-05 03:51:40 -04:00
|
|
|
/* Get some more information on the audio stream */
|
2010-03-23 13:48:32 -04:00
|
|
|
if (audio_stream)
|
2009-04-05 03:51:40 -04:00
|
|
|
{
|
2010-03-23 13:48:32 -04:00
|
|
|
if (audio_stream->codec->sample_rate != 0)
|
|
|
|
mfi->samplerate = audio_stream->codec->sample_rate;
|
2009-04-05 03:51:40 -04:00
|
|
|
|
|
|
|
/* Try sample format first */
|
2013-11-25 13:43:17 -05:00
|
|
|
#if LIBAVUTIL_VERSION_MAJOR >= 52 || (LIBAVUTIL_VERSION_MAJOR == 51 && LIBAVUTIL_VERSION_MINOR >= 4)
|
2011-09-10 06:20:15 -04:00
|
|
|
mfi->bits_per_sample = 8 * av_get_bytes_per_sample(audio_stream->codec->sample_fmt);
|
|
|
|
#elif LIBAVCODEC_VERSION_MAJOR >= 53
|
2011-06-02 11:42:30 -04:00
|
|
|
mfi->bits_per_sample = av_get_bits_per_sample_fmt(audio_stream->codec->sample_fmt);
|
|
|
|
#else
|
2010-03-23 13:48:32 -04:00
|
|
|
mfi->bits_per_sample = av_get_bits_per_sample_format(audio_stream->codec->sample_fmt);
|
2011-06-02 11:42:30 -04:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
if (mfi->bits_per_sample == 0)
|
|
|
|
{
|
|
|
|
/* Try codec */
|
|
|
|
mfi->bits_per_sample = av_get_bits_per_sample(audio_codec_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(E_DBG, L_SCAN, "samplerate %d, bps %d\n", mfi->samplerate, mfi->bits_per_sample);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check codec */
|
2010-03-22 13:22:39 -04:00
|
|
|
extra_md_map = NULL;
|
2009-04-05 03:51:40 -04:00
|
|
|
codec_id = (mfi->has_video) ? video_codec_id : audio_codec_id;
|
|
|
|
switch (codec_id)
|
|
|
|
{
|
2014-02-17 17:05:24 -05:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
|
|
|
|
case AV_CODEC_ID_AAC:
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
case CODEC_ID_AAC:
|
2014-02-17 17:05:24 -05:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
DPRINTF(E_DBG, L_SCAN, "AAC\n");
|
|
|
|
mfi->type = strdup("m4a");
|
|
|
|
mfi->codectype = strdup("mp4a");
|
|
|
|
mfi->description = strdup("AAC audio file");
|
|
|
|
break;
|
|
|
|
|
2014-02-17 17:05:24 -05:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
|
|
|
|
case AV_CODEC_ID_ALAC:
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
case CODEC_ID_ALAC:
|
2014-02-17 17:05:24 -05:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
DPRINTF(E_DBG, L_SCAN, "ALAC\n");
|
|
|
|
mfi->type = strdup("m4a");
|
|
|
|
mfi->codectype = strdup("alac");
|
2013-09-07 17:39:22 -04:00
|
|
|
mfi->description = strdup("Apple Lossless audio file");
|
2009-04-05 03:51:40 -04:00
|
|
|
break;
|
|
|
|
|
2014-02-17 17:05:24 -05:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
|
|
|
|
case AV_CODEC_ID_FLAC:
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
case CODEC_ID_FLAC:
|
2014-02-17 17:05:24 -05:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
DPRINTF(E_DBG, L_SCAN, "FLAC\n");
|
|
|
|
mfi->type = strdup("flac");
|
|
|
|
mfi->codectype = strdup("flac");
|
|
|
|
mfi->description = strdup("FLAC audio file");
|
2010-03-28 07:24:05 -04:00
|
|
|
|
|
|
|
extra_md_map = md_map_vorbis;
|
2009-04-05 03:51:40 -04:00
|
|
|
break;
|
|
|
|
|
2014-02-17 17:05:24 -05:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
|
|
|
|
case AV_CODEC_ID_MUSEPACK7:
|
|
|
|
case AV_CODEC_ID_MUSEPACK8:
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
case CODEC_ID_MUSEPACK7:
|
|
|
|
case CODEC_ID_MUSEPACK8:
|
2014-02-17 17:05:24 -05:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
DPRINTF(E_DBG, L_SCAN, "Musepack\n");
|
|
|
|
mfi->type = strdup("mpc");
|
|
|
|
mfi->codectype = strdup("mpc");
|
|
|
|
mfi->description = strdup("Musepack audio file");
|
|
|
|
break;
|
|
|
|
|
2014-02-17 17:05:24 -05:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
|
|
|
|
case AV_CODEC_ID_MPEG4: /* Video */
|
|
|
|
case AV_CODEC_ID_H264:
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
case CODEC_ID_MPEG4: /* Video */
|
|
|
|
case CODEC_ID_H264:
|
2014-02-17 17:05:24 -05:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
DPRINTF(E_DBG, L_SCAN, "MPEG4 video\n");
|
|
|
|
mfi->type = strdup("m4v");
|
|
|
|
mfi->codectype = strdup("mp4v");
|
|
|
|
mfi->description = strdup("MPEG-4 video file");
|
2010-03-22 13:22:39 -04:00
|
|
|
|
|
|
|
extra_md_map = md_map_tv;
|
2009-04-05 03:51:40 -04:00
|
|
|
break;
|
|
|
|
|
2014-02-17 17:05:24 -05:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
|
|
|
|
case AV_CODEC_ID_MP3:
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
case CODEC_ID_MP3:
|
2014-02-17 17:05:24 -05:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
DPRINTF(E_DBG, L_SCAN, "MP3\n");
|
|
|
|
mfi->type = strdup("mp3");
|
|
|
|
mfi->codectype = strdup("mpeg");
|
|
|
|
mfi->description = strdup("MPEG audio file");
|
2010-03-22 13:22:39 -04:00
|
|
|
|
|
|
|
extra_md_map = md_map_id3;
|
2009-04-05 03:51:40 -04:00
|
|
|
break;
|
|
|
|
|
2014-02-17 17:05:24 -05:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
|
|
|
|
case AV_CODEC_ID_VORBIS:
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
case CODEC_ID_VORBIS:
|
2014-02-17 17:05:24 -05:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
DPRINTF(E_DBG, L_SCAN, "VORBIS\n");
|
|
|
|
mfi->type = strdup("ogg");
|
|
|
|
mfi->codectype = strdup("ogg");
|
|
|
|
mfi->description = strdup("Ogg Vorbis audio file");
|
2010-03-28 07:24:05 -04:00
|
|
|
|
|
|
|
extra_md_map = md_map_vorbis;
|
2009-04-05 03:51:40 -04:00
|
|
|
break;
|
|
|
|
|
2014-02-17 17:05:24 -05:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
|
|
|
|
case AV_CODEC_ID_WMAV1:
|
|
|
|
case AV_CODEC_ID_WMAV2:
|
|
|
|
case AV_CODEC_ID_WMAVOICE:
|
|
|
|
#else
|
2014-02-05 20:44:01 -05:00
|
|
|
case CODEC_ID_WMAV1:
|
|
|
|
case CODEC_ID_WMAV2:
|
2009-04-05 03:51:40 -04:00
|
|
|
case CODEC_ID_WMAVOICE:
|
2014-02-17 17:05:24 -05:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
DPRINTF(E_DBG, L_SCAN, "WMA Voice\n");
|
|
|
|
mfi->type = strdup("wma");
|
|
|
|
mfi->codectype = strdup("wmav");
|
|
|
|
mfi->description = strdup("WMA audio file");
|
|
|
|
break;
|
|
|
|
|
2014-02-17 17:05:24 -05:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
|
|
|
|
case AV_CODEC_ID_WMAPRO:
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
case CODEC_ID_WMAPRO:
|
2014-02-17 17:05:24 -05:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
DPRINTF(E_DBG, L_SCAN, "WMA Pro\n");
|
|
|
|
mfi->type = strdup("wmap");
|
|
|
|
mfi->codectype = strdup("wma");
|
|
|
|
mfi->description = strdup("WMA audio file");
|
|
|
|
break;
|
|
|
|
|
2014-02-17 17:05:24 -05:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
|
|
|
|
case AV_CODEC_ID_WMALOSSLESS:
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
case CODEC_ID_WMALOSSLESS:
|
2014-02-17 17:05:24 -05:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
DPRINTF(E_DBG, L_SCAN, "WMA Lossless\n");
|
|
|
|
mfi->type = strdup("wma");
|
|
|
|
mfi->codectype = strdup("wmal");
|
|
|
|
mfi->description = strdup("WMA audio file");
|
|
|
|
break;
|
|
|
|
|
2014-02-17 17:05:24 -05:00
|
|
|
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
|
|
|
|
case AV_CODEC_ID_PCM_S16LE ... AV_CODEC_ID_PCM_F64LE:
|
|
|
|
#else
|
2009-04-05 03:51:40 -04:00
|
|
|
case CODEC_ID_PCM_S16LE ... CODEC_ID_PCM_F64LE:
|
2014-02-17 17:05:24 -05:00
|
|
|
#endif
|
2009-04-05 03:51:40 -04:00
|
|
|
if (strcmp(ctx->iformat->name, "aiff") == 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_DBG, L_SCAN, "AIFF\n");
|
|
|
|
mfi->type = strdup("aif");
|
|
|
|
mfi->codectype = strdup("aif");
|
|
|
|
mfi->description = strdup("AIFF audio file");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (strcmp(ctx->iformat->name, "wav") == 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_DBG, L_SCAN, "WAV\n");
|
|
|
|
mfi->type = strdup("wav");
|
|
|
|
mfi->codectype = strdup("wav");
|
|
|
|
mfi->description = strdup("WAV audio file");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* WARNING: will fallthrough to default case, don't move */
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
default:
|
|
|
|
DPRINTF(E_DBG, L_SCAN, "Unknown codec 0x%x (video: %s), format %s (%s)\n",
|
|
|
|
codec_id, (mfi->has_video) ? "yes" : "no", ctx->iformat->name, ctx->iformat->long_name);
|
|
|
|
mfi->type = strdup("unkn");
|
|
|
|
mfi->codectype = strdup("unkn");
|
|
|
|
if (mfi->has_video)
|
2010-03-22 13:22:39 -04:00
|
|
|
{
|
|
|
|
mfi->description = strdup("Unknown video file format");
|
|
|
|
extra_md_map = md_map_tv;
|
|
|
|
}
|
2009-04-05 03:51:40 -04:00
|
|
|
else
|
|
|
|
mfi->description = strdup("Unknown audio file format");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mdcount = 0;
|
|
|
|
|
2010-03-23 13:48:32 -04:00
|
|
|
if ((!ctx->metadata) && (!audio_stream->metadata)
|
|
|
|
&& (video_stream && !video_stream->metadata))
|
2009-04-05 03:51:40 -04:00
|
|
|
{
|
|
|
|
DPRINTF(E_WARN, L_SCAN, "ffmpeg reports no metadata\n");
|
|
|
|
|
|
|
|
goto skip_extract;
|
|
|
|
}
|
|
|
|
|
2010-04-08 11:10:15 -04:00
|
|
|
if (extra_md_map)
|
2010-03-22 13:22:39 -04:00
|
|
|
{
|
2010-04-08 11:10:15 -04:00
|
|
|
ret = extract_metadata(mfi, ctx, audio_stream, video_stream, extra_md_map);
|
2010-03-22 13:22:39 -04:00
|
|
|
mdcount += ret;
|
|
|
|
|
2010-04-08 11:10:15 -04:00
|
|
|
DPRINTF(E_DBG, L_SCAN, "Picked up %d tags with extra md_map\n", ret);
|
2010-03-22 13:22:39 -04:00
|
|
|
}
|
|
|
|
|
2011-06-02 12:10:49 -04:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR < 53
|
2010-04-08 11:10:15 -04:00
|
|
|
av_metadata_conv(ctx, NULL, ctx->iformat->metadata_conv);
|
2011-06-02 12:10:49 -04:00
|
|
|
#endif
|
2010-03-22 13:22:39 -04:00
|
|
|
|
2010-04-08 11:10:15 -04:00
|
|
|
ret = extract_metadata(mfi, ctx, audio_stream, video_stream, md_map_generic);
|
|
|
|
mdcount += ret;
|
2010-03-22 13:22:39 -04:00
|
|
|
|
2010-04-08 11:10:15 -04:00
|
|
|
DPRINTF(E_DBG, L_SCAN, "Picked up %d tags with generic md_map, %d tags total\n", ret, mdcount);
|
2009-04-05 03:51:40 -04:00
|
|
|
|
2009-12-26 02:31:12 -05:00
|
|
|
/* fix up TV metadata */
|
|
|
|
if (mfi->media_kind == 10)
|
|
|
|
{
|
|
|
|
/* I have no idea why this is, but iTunes reports a media kind of 64 for stik==10 (?!) */
|
|
|
|
mfi->media_kind = 64;
|
|
|
|
}
|
2010-01-24 05:08:04 -05:00
|
|
|
/* Unspecified video files are "Movies", media_kind 2 */
|
|
|
|
else if (mfi->has_video == 1)
|
|
|
|
{
|
|
|
|
mfi->media_kind = 2;
|
|
|
|
}
|
2009-12-26 02:31:12 -05:00
|
|
|
|
2009-04-05 03:51:40 -04:00
|
|
|
skip_extract:
|
2014-03-12 17:54:30 -04:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
|
|
|
avformat_close_input(&ctx);
|
|
|
|
#else
|
|
|
|
av_close_input_file(ctx);
|
|
|
|
#endif
|
|
|
|
|
2009-04-05 03:51:40 -04:00
|
|
|
if (mdcount == 0)
|
2009-04-05 07:22:47 -04:00
|
|
|
{
|
2014-03-12 17:54:30 -04:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR < 54 || (LIBAVFORMAT_VERSION_MAJOR == 54 && LIBAVFORMAT_VERSION_MINOR < 35)
|
2009-04-05 07:22:47 -04:00
|
|
|
/* ffmpeg doesn't support FLAC nor Musepack metadata,
|
|
|
|
* and is buggy for some WMA variants, so fall back to the
|
|
|
|
* legacy format-specific parsers until it gets fixed */
|
|
|
|
if ((codec_id == CODEC_ID_WMAPRO)
|
|
|
|
|| (codec_id == CODEC_ID_WMAVOICE)
|
|
|
|
|| (codec_id == CODEC_ID_WMALOSSLESS))
|
|
|
|
{
|
|
|
|
DPRINTF(E_WARN, L_SCAN, "Falling back to legacy WMA scanner\n");
|
2009-04-20 11:34:39 -04:00
|
|
|
return (scan_get_wmainfo(file, mfi) ? 0 : -1);
|
2009-04-05 07:22:47 -04:00
|
|
|
}
|
|
|
|
#ifdef FLAC
|
|
|
|
else if (codec_id == CODEC_ID_FLAC)
|
|
|
|
{
|
|
|
|
DPRINTF(E_WARN, L_SCAN, "Falling back to legacy FLAC scanner\n");
|
2009-04-20 11:34:39 -04:00
|
|
|
return (scan_get_flacinfo(file, mfi) ? 0 : -1);
|
2009-04-05 07:22:47 -04:00
|
|
|
}
|
|
|
|
#endif /* FLAC */
|
|
|
|
#ifdef MUSEPACK
|
|
|
|
else if ((codec_id == CODEC_ID_MUSEPACK7)
|
|
|
|
|| (codec_id == CODEC_ID_MUSEPACK8))
|
|
|
|
{
|
|
|
|
DPRINTF(E_WARN, L_SCAN, "Falling back to legacy Musepack scanner\n");
|
2009-04-20 11:34:39 -04:00
|
|
|
return (scan_get_mpcinfo(file, mfi) ? 0 : -1);
|
2009-04-05 07:22:47 -04:00
|
|
|
}
|
|
|
|
#endif /* MUSEPACK */
|
|
|
|
else
|
2014-02-17 17:05:24 -05:00
|
|
|
#endif /* LIBAVFORMAT */
|
2013-10-16 16:07:30 -04:00
|
|
|
DPRINTF(E_WARN, L_SCAN, "ffmpeg/libav could not extract any metadata\n");
|
2009-04-05 07:22:47 -04:00
|
|
|
}
|
2009-04-05 03:51:40 -04:00
|
|
|
|
|
|
|
/* Just in case there's no title set ... */
|
|
|
|
if (mfi->title == NULL)
|
|
|
|
mfi->title = strdup(mfi->fname);
|
|
|
|
|
|
|
|
/* All done */
|
|
|
|
|
2009-04-20 11:34:39 -04:00
|
|
|
return 0;
|
2009-04-05 03:51:40 -04:00
|
|
|
}
|