Skip to content

Commit

Permalink
separate getArtist() from getAuthor()
Browse files Browse the repository at this point in the history
and move copy-pasted code into a function
  • Loading branch information
tony2001 committed Jun 17, 2013
1 parent 9a98d13 commit 32e90b2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 89 deletions.
116 changes: 27 additions & 89 deletions ffmpeg_movie.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ zend_function_entry ffmpeg_movie_class_methods[] = {
FFMPEG_PHP_MALIAS(ffmpeg_movie, getcomment, getComment, NULL, 0)
FFMPEG_PHP_MALIAS(ffmpeg_movie, gettitle, getTitle, NULL, 0)
FFMPEG_PHP_MALIAS(ffmpeg_movie, getauthor, getAuthor, NULL, 0)
FFMPEG_PHP_MALIAS(ffmpeg_movie, getartist, getAuthor, NULL, 0)
FFMPEG_PHP_MALIAS(ffmpeg_movie, getartist, getArtist, NULL, 0)
FFMPEG_PHP_MALIAS(ffmpeg_movie, getcopyright, getCopyright, NULL, 0)
FFMPEG_PHP_MALIAS(ffmpeg_movie, getalbum, getAlbum, NULL, 0)
FFMPEG_PHP_MALIAS(ffmpeg_movie, getgenre, getGenre, NULL, 0)
Expand Down Expand Up @@ -498,15 +498,13 @@ static AVCodecContext* _php_get_decoder_context(ff_movie_context *ffmovie_ctx,
/* }}} */


/* {{{ proto string getComment()
*/
FFMPEG_PHP_METHOD(ffmpeg_movie, getComment)
void php_get_dict_value(INTERNAL_FUNCTION_PARAMETERS, char *entry_name) /* {{{ */
{
ff_movie_context *ffmovie_ctx;

GET_MOVIE_RESOURCE(ffmovie_ctx);

AVDictionaryEntry *m_entry = av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "comment", NULL, 0);
AVDictionaryEntry *m_entry = av_dict_get(ffmovie_ctx->fmt_ctx->metadata, entry_name, NULL, 0);

if (!m_entry) {
RETURN_FALSE;
Expand All @@ -516,82 +514,55 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getComment)
}
/* }}} */

/* {{{ proto string getComment()
*/
FFMPEG_PHP_METHOD(ffmpeg_movie, getComment)
{
php_get_dict_value(INTERNAL_FUNCTION_PARAM_PASSTHRU, "comment");
}
/* }}} */

/* {{{ proto string getTitle()
* Return title field from movie or title ID3 tag from an MP3 file.
*/
FFMPEG_PHP_METHOD(ffmpeg_movie, getTitle)
{
ff_movie_context *ffmovie_ctx;

GET_MOVIE_RESOURCE(ffmovie_ctx);

AVDictionaryEntry *m_entry = av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "title", NULL, 0);

if (!m_entry) {
RETURN_FALSE;
}

RETURN_STRINGL(m_entry->value, strlen(m_entry->value), 1);
php_get_dict_value(INTERNAL_FUNCTION_PARAM_PASSTHRU, "title");
}
/* }}} */


/* {{{ proto string getAuthor() or getArtist()
* Return author field from a movie or artist ID3 tag from am MP3 files.
/* {{{ proto string getAuthor()
* Return author field from a movie.
*/
FFMPEG_PHP_METHOD(ffmpeg_movie, getAuthor)
{
ff_movie_context *ffmovie_ctx;

GET_MOVIE_RESOURCE(ffmovie_ctx);

AVDictionaryEntry *m_entry = av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "author", NULL, 0);

if (!m_entry) {
RETURN_FALSE;
}

RETURN_STRINGL(m_entry->value, strlen(m_entry->value), 1);
php_get_dict_value(INTERNAL_FUNCTION_PARAM_PASSTHRU, "author");
}
/* }}} */

/* {{{ proto string getArtist()
* Return artist field from MP3 files.
*/
FFMPEG_PHP_METHOD(ffmpeg_movie, getArtist)
{
php_get_dict_value(INTERNAL_FUNCTION_PARAM_PASSTHRU, "artist");
}
/* }}} */

/* {{{ proto string getCopyright()
*/
FFMPEG_PHP_METHOD(ffmpeg_movie, getCopyright)
{
ff_movie_context *ffmovie_ctx;

GET_MOVIE_RESOURCE(ffmovie_ctx);

AVDictionaryEntry *m_entry = av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "copyright", NULL, 0);

if (!m_entry) {
RETURN_FALSE;
}

RETURN_STRINGL(m_entry->value, strlen(m_entry->value), 1);
php_get_dict_value(INTERNAL_FUNCTION_PARAM_PASSTHRU, "copyright");
}
/* }}} */


/* {{{ proto string getAlbum()
* Return ID3 album field from an mp3 file
*/
FFMPEG_PHP_METHOD(ffmpeg_movie, getAlbum)
{
ff_movie_context *ffmovie_ctx;

GET_MOVIE_RESOURCE(ffmovie_ctx);

AVDictionaryEntry *m_entry = av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "album", NULL, 0);

if (!m_entry) {
RETURN_FALSE;
}

RETURN_STRINGL(m_entry->value, strlen(m_entry->value), 1);
php_get_dict_value(INTERNAL_FUNCTION_PARAM_PASSTHRU, "album");
}
/* }}} */

Expand All @@ -600,37 +571,16 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getAlbum)
*/
FFMPEG_PHP_METHOD(ffmpeg_movie, getGenre)
{
ff_movie_context *ffmovie_ctx;

GET_MOVIE_RESOURCE(ffmovie_ctx);

AVDictionaryEntry *m_entry = av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "genre", NULL, 0);

if (!m_entry) {
RETURN_FALSE;
}

RETURN_STRINGL(m_entry->value, strlen(m_entry->value), 1);
php_get_dict_value(INTERNAL_FUNCTION_PARAM_PASSTHRU, "genre");
}
/* }}} */


/* {{{ proto int getTrackNumber()
* Return ID3 track field from an mp3 file
*/
FFMPEG_PHP_METHOD(ffmpeg_movie, getTrackNumber)
{
ff_movie_context *ffmovie_ctx;

GET_MOVIE_RESOURCE(ffmovie_ctx);

AVDictionaryEntry *m_entry = av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "track", NULL, 0);

if (!m_entry) {
RETURN_FALSE;
}

RETURN_STRINGL(m_entry->value, strlen(m_entry->value), 1);
php_get_dict_value(INTERNAL_FUNCTION_PARAM_PASSTHRU, "track");
}
/* }}} */

Expand All @@ -639,21 +589,10 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getTrackNumber)
*/
FFMPEG_PHP_METHOD(ffmpeg_movie, getYear)
{
ff_movie_context *ffmovie_ctx;

GET_MOVIE_RESOURCE(ffmovie_ctx);

AVDictionaryEntry *m_entry = av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "year", NULL, 0);

if (!m_entry) {
RETURN_FALSE;
}

RETURN_STRINGL(m_entry->value, strlen(m_entry->value), 1);
php_get_dict_value(INTERNAL_FUNCTION_PARAM_PASSTHRU, "year");
}
/* }}} */


/* {{{ _php_get_duration()
*/
static float _php_get_duration(ff_movie_context *ffmovie_ctx)
Expand All @@ -669,7 +608,6 @@ static float _php_get_duration(ff_movie_context *ffmovie_ctx)
}
/* }}} */


/* {{{ proto int getDuration()
*/
FFMPEG_PHP_METHOD(ffmpeg_movie, getDuration)
Expand Down
1 change: 1 addition & 0 deletions ffmpeg_movie.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getFileName);
FFMPEG_PHP_METHOD(ffmpeg_movie, getComment);
FFMPEG_PHP_METHOD(ffmpeg_movie, getTitle);
FFMPEG_PHP_METHOD(ffmpeg_movie, getAuthor);
FFMPEG_PHP_METHOD(ffmpeg_movie, getArtist);
FFMPEG_PHP_METHOD(ffmpeg_movie, getCopyright);
FFMPEG_PHP_METHOD(ffmpeg_movie, getAlbum);
FFMPEG_PHP_METHOD(ffmpeg_movie, getGenre);
Expand Down

0 comments on commit 32e90b2

Please sign in to comment.