Update of /cvsroot/freevo/freevo/WIP/Dischi/mediainfo
In directory sc8-pr-cvs1:/tmp/cvs-serv14747

Added Files:
        Makefile.pre.in ifomodule.c setup.py test.py 
Log Message:
First version of a mediainfo lib, right now first steps of an ifo parser


--- NEW FILE: Makefile.pre.in ---
# Universal Unix Makefile for Python extensions
# =============================================

# Short Instructions
# ------------------

# 1. Build and install Python (1.5 or newer).
# 2. "make -f Makefile.pre.in boot"
# 3. "make"
# You should now have a shared library.

# Long Instructions
# -----------------

# Build *and install* the basic Python 1.5 distribution.  See the
# Python README for instructions.  (This version of Makefile.pre.in
# only withs with Python 1.5, alpha 3 or newer.)

# Create a file Setup.in for your extension.  This file follows the
# format of the Modules/Setup.in file; see the instructions there.
# For a simple module called "spam" on file "spammodule.c", it can
# contain a single line:
#   spam spammodule.c
# You can build as many modules as you want in the same directory --
# just have a separate line for each of them in the Setup.in file.

# If you want to build your extension as a shared library, insert a
# line containing just the string
#   *shared*
# at the top of your Setup.in file.

# Note that the build process copies Setup.in to Setup, and then works
# with Setup.  It doesn't overwrite Setup when Setup.in is changed, so
# while you're in the process of debugging your Setup.in file, you may
# want to edit Setup instead, and copy it back to Setup.in later.
# (All this is done so you can distribute your extension easily and
# someone else can select the modules they actually want to build by
# commenting out lines in the Setup file, without editing the
# original.  Editing Setup is also used to specify nonstandard
# locations for include or library files.)

# Copy this file (Misc/Makefile.pre.in) to the directory containing
# your extension.

# Run "make -f Makefile.pre.in boot".  This creates Makefile
# (producing Makefile.pre and sedscript as intermediate files) and
# config.c, incorporating the values for sys.prefix, sys.exec_prefix
# and sys.version from the installed Python binary.  For this to work,
# the python binary must be on your path.  If this fails, try
#   make -f Makefile.pre.in Makefile VERSION=1.5 installdir=<prefix>
# where <prefix> is the prefix used to install Python for installdir
# (and possibly similar for exec_installdir=<exec_prefix>).

# Note: "make boot" implies "make clobber" -- it assumes that when you
# bootstrap you may have changed platforms so it removes all previous
# output files.

# If you are building your extension as a shared library (your
# Setup.in file starts with *shared*), run "make" or "make sharedmods"
# to build the shared library files.  If you are building a statically
# linked Python binary (the only solution of your platform doesn't
# support shared libraries, and sometimes handy if you want to
# distribute or install the resulting Python binary), run "make
# python".

# Note: Each time you edit Makefile.pre.in or Setup, you must run
# "make Makefile" before running "make".

# Hint: if you want to use VPATH, you can start in an empty
# subdirectory and say (e.g.):
#   make -f ../Makefile.pre.in boot srcdir=.. VPATH=..


# === Bootstrap variables (edited through "make boot") ===

# The prefix used by "make inclinstall libainstall" of core python
installdir=     /usr/local

# The exec_prefix used by the same
exec_installdir=$(installdir)

# Source directory and VPATH in case you want to use VPATH.
# (You will have to edit these two lines yourself -- there is no
# automatic support as the Makefile is not generated by
# config.status.)
srcdir=         .
VPATH=          .

# === Variables that you may want to customize (rarely) ===

# (Static) build target
TARGET=         python

# Installed python binary (used only by boot target)
PYTHON=         python

# Add more -I and -D options here
CFLAGS=         $(OPT) -I$(INCLUDEPY) -I$(EXECINCLUDEPY) $(DEFS)

# These two variables can be set in Setup to merge extensions.
# See example[23].
BASELIB=        
BASESETUP=      

# === Variables set by makesetup ===

MODOBJS=        _MODOBJS_
MODLIBS=        _MODLIBS_

# === Definitions added by makesetup ===

# === Variables from configure (through sedscript) ===

VERSION=        @VERSION@
CC=             @CC@
LINKCC=         @LINKCC@
SGI_ABI=        @SGI_ABI@
OPT=            @OPT@
LDFLAGS=        @LDFLAGS@
LDLAST=         @LDLAST@
DEFS=           @DEFS@
LIBS=           @LIBS@
LIBM=           @LIBM@
LIBC=           @LIBC@
RANLIB=         @RANLIB@
MACHDEP=        @MACHDEP@
SO=             @SO@
LDSHARED=       @LDSHARED@
CCSHARED=       @CCSHARED@
LINKFORSHARED=  @LINKFORSHARED@
[EMAIL PROTECTED]@

# Install prefix for architecture-independent files
prefix=         /usr/local

# Install prefix for architecture-dependent files
exec_prefix=    $(prefix)

# === Fixed definitions ===

# Shell used by make (some versions default to the login shell, which is bad)
SHELL=          /bin/sh

# Expanded directories
BINDIR=         $(exec_installdir)/bin
LIBDIR=         $(exec_prefix)/lib
MANDIR=         $(installdir)/man
INCLUDEDIR=     $(installdir)/include
SCRIPTDIR=      $(prefix)/lib

# Detailed destination directories
BINLIBDEST=     $(LIBDIR)/python$(VERSION)
LIBDEST=        $(SCRIPTDIR)/python$(VERSION)
INCLUDEPY=      $(INCLUDEDIR)/python$(VERSION)
EXECINCLUDEPY=  $(exec_installdir)/include/python$(VERSION)
LIBP=           $(exec_installdir)/lib/python$(VERSION)
DESTSHARED=     $(BINLIBDEST)/site-packages

LIBPL=          $(LIBP)/config

PYTHONLIBS=     $(LIBPL)/libpython$(VERSION).a

MAKESETUP=      $(LIBPL)/makesetup
MAKEFILE=       $(LIBPL)/Makefile
CONFIGC=        $(LIBPL)/config.c
CONFIGCIN=      $(LIBPL)/config.c.in
SETUP=          $(LIBPL)/Setup

SYSLIBS=        $(LIBM) $(LIBC)

ADDOBJS=        $(LIBPL)/python.o config.o

# Portable install script (configure doesn't always guess right)
INSTALL=        $(LIBPL)/install-sh -c
# Shared libraries must be installed with executable mode on some systems;
# rather than figuring out exactly which, we always give them executable mode.
# Also, making them read-only seems to be a good idea...
INSTALL_SHARED= ${INSTALL} -m 555

# === Fixed rules ===

# Default target.  This builds shared libraries only
default:        sharedmods

# Build everything
all:            static sharedmods

# Build shared libraries from our extension modules
sharedmods:     $(SHAREDMODS)

# Build a static Python binary containing our extension modules
static:         $(TARGET)
$(TARGET):      $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB)
                $(LINKCC) $(LDFLAGS) $(LINKFORSHARED) \
                 $(ADDOBJS) lib.a $(PYTHONLIBS) \
                 $(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \
                 -o $(TARGET) $(LDLAST)

install:        sharedmods
                if test ! -d $(DESTSHARED) ; then \
                        mkdir $(DESTSHARED) ; else true ; fi
                -for i in X $(SHAREDMODS); do \
                        if test $$i != X; \
                        then $(INSTALL_SHARED) $$i $(DESTSHARED)/$$i; \
                        fi; \
                done

# Build the library containing our extension modules
lib.a:          $(MODOBJS)
                -rm -f lib.a
                ar cr lib.a $(MODOBJS)
                -$(RANLIB) lib.a 

# This runs makesetup *twice* to use the BASESETUP definition from Setup
config.c Makefile:      Makefile.pre Setup $(BASESETUP) $(MAKESETUP)
                $(MAKESETUP) \
                 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
                $(MAKE) -f Makefile do-it-again

# Internal target to run makesetup for the second time
do-it-again:
                $(MAKESETUP) \
                 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)

# Make config.o from the config.c created by makesetup
config.o:       config.c
                $(CC) $(CFLAGS) -c config.c

# Setup is copied from Setup.in *only* if it doesn't yet exist
Setup:
                cp $(srcdir)/Setup.in Setup

# Make the intermediate Makefile.pre from Makefile.pre.in
Makefile.pre: Makefile.pre.in sedscript
                sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre

# Shortcuts to make the sed arguments on one line
P=prefix
E=exec_prefix
H=Generated automatically from Makefile.pre.in by sedscript.
L=LINKFORSHARED

# Make the sed script used to create Makefile.pre from Makefile.pre.in
sedscript:      $(MAKEFILE)
        sed -n \
         -e '1s/.*/1i\\/p' \
         -e '2s%.*%# $H%p' \
         -e '/^VERSION=/s/^VERSION=[    ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^CC=/s/^CC=[      ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^CCC=/s/^CCC=[    ]*\(.*\)/[EMAIL PROTECTED]@]%CCC=\1%/p' \
         -e '/^LINKCC=/s/^LINKCC=[      ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^OPT=/s/^OPT=[    ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^LDFLAGS=/s/^LDFLAGS=[    ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^DEFS=/s/^DEFS=[  ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^LIBS=/s/^LIBS=[  ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^LIBM=/s/^LIBM=[  ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^LIBC=/s/^LIBC=[  ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^RANLIB=/s/^RANLIB=[      ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^MACHDEP=/s/^MACHDEP=[    ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^SO=/s/^SO=[      ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^LDSHARED=/s/^LDSHARED=[  ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^CCSHARED=/s/^CCSHARED=[  ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^$L=/s/^$L=[      ]*\(.*\)/[EMAIL PROTECTED]@]%\1%/p' \
         -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \
         -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \
         $(MAKEFILE) >sedscript
        echo "/[EMAIL PROTECTED]@/d" >>sedscript
        echo "/^installdir=/s%=.*%=     $(installdir)%" >>sedscript
        echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript
        echo "/^srcdir=/s%=.*%=         $(srcdir)%" >>sedscript
        echo "/^VPATH=/s%=.*%=          $(VPATH)%" >>sedscript
        echo "/^LINKPATH=/s%=.*%=       $(LINKPATH)%" >>sedscript
        echo "/^BASELIB=/s%=.*%=        $(BASELIB)%" >>sedscript
        echo "/^BASESETUP=/s%=.*%=      $(BASESETUP)%" >>sedscript

# Bootstrap target
boot:   clobber
        VERSION=`$(PYTHON) -c "import sys; print sys.version[:3]"`; \
        installdir=`$(PYTHON) -c "import sys; print sys.prefix"`; \
        exec_installdir=`$(PYTHON) -c "import sys; print sys.exec_prefix"`; \
        $(MAKE) -f $(srcdir)/Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \
                VERSION=$$VERSION \
                installdir=$$installdir \
                exec_installdir=$$exec_installdir \
                Makefile

# Handy target to remove intermediate files and backups
clean:
                -rm -f *.o *~

# Handy target to remove everything that is easily regenerated
clobber:        clean
                -rm -f *.a tags TAGS config.c Makefile.pre $(TARGET) sedscript
                -rm -f *.so *.sl so_locations


# Handy target to remove everything you don't want to distribute
distclean:      clobber
                -rm -f Makefile Setup

--- NEW FILE: ifomodule.c ---
//based on http://arnfast.net/projects/ifoinfo.php by Jens Arnfast 

#include <Python.h>

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>

#include <dvdread/dvd_reader.h>
#include <dvdread/ifo_types.h>
#include <dvdread/ifo_read.h>

//static PyObject * get_audio_tracks (output_t style, int trackno, audio_attr_t *attr);

static PyObject *ifoinfo_open(PyObject *self, PyObject *args);
static PyObject *ifoinfo_read_title(PyObject *self, PyObject *args);

static PyMethodDef IfoMethods[] = {
  {"open",  ifoinfo_open, METH_VARARGS},
  {"title", ifoinfo_read_title, METH_VARARGS},
  {NULL, NULL}
};


void initifoinfo() {
   (void) Py_InitModule("ifoinfo", IfoMethods);
}




dvd_reader_t *dvd;
ifo_handle_t *ifofile;

static PyObject *ifoinfo_open(PyObject *self, PyObject *args) {
  tt_srpt_t *tt_srpt;
  int i, ch, gotopt = -1, dochapters = -1;
  char *dvddevice;

  if (!PyArg_ParseTuple(args, "s", &dvddevice))
    return Py_BuildValue("i", 0);

  dvd = DVDOpen(dvddevice);

  if (!dvd)
    return Py_BuildValue("i", 0);
  
  ifofile = ifoOpen(dvd, 0);
  if (!ifofile) {
    DVDClose(dvd);
    return Py_BuildValue("i", 0);
  }

  tt_srpt = ifofile->tt_srpt;
  return Py_BuildValue("i", tt_srpt->nr_of_srpts);
}


static PyObject *ifoinfo_close(PyObject *self, PyObject *args) {
  ifoClose(ifofile);
  DVDClose(dvd);
  return Py_BuildValue("i", 0);
}


static PyObject *ifoinfo_read_title(PyObject *self, PyObject *args) {
  int i;

  tt_srpt_t *tt_srpt;
  ifo_handle_t *vtsfile;
  int vtsnum, ttnnum, j;
  long playtime;

  if (!PyArg_ParseTuple(args, "i", &i))
    return Py_BuildValue("i", 0);

  i--;
  
  tt_srpt = ifofile->tt_srpt;
  vtsnum = tt_srpt->title[i].title_set_nr;
  ttnnum = tt_srpt->title[i].vts_ttn;
     
  vtsfile = ifoOpen(dvd, vtsnum);
    
  playtime = 0;
  
  if (vtsfile->vts_pgcit) {
    dvd_time_t *ttime;
    ttime = &vtsfile->vts_pgcit->pgci_srp[0].pgc->playback_time;
    playtime = ((ttime->hour * 60) + ttime->minute) * 60 + ttime->second;
  }

  // Number of Chapters, Number of Angles, Playback time, Num Audio tracks
  return Py_BuildValue("(iiii)", tt_srpt->title[i].nr_of_ptts,
                       tt_srpt->title[i].nr_of_angles, playtime,                       
                       vtsfile->vtsi_mat->nr_of_vts_audio_streams);
}



/*     if (vtsfile->vtsi_mat) { */
/*       for (j = 0; j < vtsfile->vtsi_mat->nr_of_vts_audio_streams; j++) { */
/*      get_audio_tracks(outputstyle, j, &vtsfile->vtsi_mat->vts_audio_attr[j]); */
/*       } */

/*       /\* subtitle tracks *\/ */
/*       printf(", subtitles %2d\n", vtsfile->vtsi_mat->nr_of_vts_subp_streams); */

/*       for (j = 0; j < vtsfile->vtsi_mat->nr_of_vts_subp_streams; j++) { */
/*      print_subpicture_tracks(outputstyle, j, &vtsfile->vtsi_mat->vts_subp_attr[j]); 
*/
/*       } */
/*     } */

/*     if (vtsfile->vts_pgcit) { */
      
/*       /\* chapter information *\/ */
/*       if (dochapters != -1) { */
/*      for (j = 0; j < vtsfile->vts_pgcit->pgci_srp[0].pgc->nr_of_cells; j++) { */
/*        print_chapter_info(outputstyle, j,  */
/*                           &vtsfile->vts_pgcit->pgci_srp[0].pgc->cell_playback[j]); 
*/
/*      } */
/*       } */
/*     } */

/*   } */

/*   ifoClose(ifofile); */
/*   DVDClose(dvd); */

/* /\*   return ret; *\/ */
  



/* void print_chapter_info (output_t style, int chapterno, cell_playback_t *cell) */
/* { */
/*   char playtime[12]; */
/*   dvd_time_t *ttime; */
/*   ttime = &cell->playback_time; */
/*   snprintf(playtime, 12, "%02x:%02x:%02x:%02x", ttime->hour, ttime->minute, 
ttime->second, ttime->frame_u & 0x3f); */

/*   switch (style) { */
/*   case OUTPUT_NORMAL: */
/*     printf("CHAPTER: ID=%d; PLAYBACKTIME=%s;\n", chapterno+1, playtime); */
/*     break; */
/*   case OUTPUT_HUMAN: */
/*     printf("Chapter(%2d): %s\n", chapterno+1, playtime); */
/*     break; */
/*   case OUTPUT_HUMAN_SHORT: */
/*     break; */
/*   case OUTPUT_XML: */
/*     printf("<chapter id=\"%d\"><playbacktime>%s</playbacktime></chapter>\n", 
chapterno+1, playtime); */
/*     break; */
/*   case OUTPUT_PERL: */
/*     printf("  { 'id' => %d, 'playbacktime' => '%s' },\n", chapterno+1, playtime); */
/*     break; */
/*   default: */
/*     return; */
/*   } */


/* } */

/* void print_subpicture_tracks (output_t style, int trackno, subp_attr_t *attr) */
/* { */
/*   char language[5]; */

/*   if ( attr->type == 0 */
/*        && attr->lang_code == 0 */
/*        && attr->zero1 == 0 */
/*        && attr->zero2 == 0 */
/*        && attr->lang_extension == 0 ) { */
/*     snprintf(language, 5, "N/A"); */
/*     return; */
/*   } */

/*   /\* language code *\/ */
/*   if (isalpha((int)(attr->lang_code >> 8)) && isalpha((int)(attr->lang_code & 
0xff))) { */
/*     snprintf(language, 5, "%c%c", attr->lang_code >> 8, attr->lang_code & 0xff); */
/*   } else { */
/*     snprintf(language, 5, "%02x%02x", 0xff & (unsigned)(attr->lang_code >> 8), 0xff 
& (unsigned)(attr->lang_code & 0xff)); */
/*   } */

/*   switch (style) { */
/*   case OUTPUT_NORMAL: */
/*     printf("SUBTITLE: ID=%i; LANG=%s;\n", trackno, language); */
/*     break; */
/*   case OUTPUT_HUMAN: */
/*     printf("Subtitle: %s (sid: %d)\n", language, trackno); */
/*     break; */
/*   case OUTPUT_HUMAN_SHORT: */
/*     break; */
/*   case OUTPUT_XML: */
/*     printf("<subtitle id=\"%i\"><language>%s</language></subtitle>\n", trackno, 
language); */
/*     break; */
/*   case OUTPUT_PERL: */
/*     printf("  { 'sid' => %d, 'language' => '%s' },\n", trackno, language); */
/*     break; */
/*   default: */
/*     return; */
/*   } */

/* } */


static PyObject * get_audio_tracks(int trackno, audio_attr_t *attr) {
  char audioformat[10];
  char audiolang[5];
  int audiochannels;
  int audioid;
  int audiofreq;

  audioid = trackno + 128;

  if ( attr->audio_format == 0
       && attr->multichannel_extension == 0
       && attr->lang_type == 0
       && attr->application_mode == 0
       && attr->quantization == 0
       && attr->sample_frequency == 0
       && attr->channels == 0
       && attr->lang_extension == 0
       && attr->unknown1 == 0
       && attr->unknown1 == 0) {
    snprintf(audioformat, 10, "Unknown");
    return;
  }

  /* audio format */
  switch (attr->audio_format) {
  case 0:
    snprintf(audioformat, 10, "ac3");
    break;
  case 1:
    snprintf(audioformat, 10, "N/A");
    break;
  case 2:
    snprintf(audioformat, 10, "mpeg1");
    break;
  case 3:
    snprintf(audioformat, 10, "mpeg2ext");
    break;
  case 4:
    snprintf(audioformat, 10, "lpcm");
    break;
  case 5:
    snprintf(audioformat, 10, "N/A");
    break;
  case 6:
    snprintf(audioformat, 10, "dts");
    break;
  default:
    snprintf(audioformat, 10, "N/A");
  }

  switch (attr->lang_type) {
  case 0:
    assert(attr->lang_code == 0 || attr->lang_code == 0xffff);
    snprintf(audiolang, 5, "N/A");
    break;
  case 1:
    snprintf(audiolang, 5, "%c%c", attr->lang_code>>8, attr->lang_code & 0xff);
    break;
  default:
    snprintf(audiolang, 5, "N/A");
  }

  switch(attr->sample_frequency) {
  case 0:
    audiofreq = 48;
    break;
  case 1:
    audiofreq = -1;
    break;
  default:
    audiofreq = -1;
  }

  audiochannels = attr->channels + 1;

  //AUDIOTRACK: ID=%i; LANG=%s; FORMAT=%s; CHANNELS=%i; FREQ=%ikHz
  return Py_BuildValue("(issii)", audioid, audiolang, audioformat, audiochannels,
                       audiofreq);
}

--- NEW FILE: setup.py ---
#!/usr/bin/env python

"""Setup script for the ifoinfo module distribution."""

__revision__ = "$Id: setup.py,v 1.1 2003/06/04 18:58:40 dischi Exp $"

from distutils.core import setup, Extension

setup (# Distribution meta-data
       name = "ifoinfo",
       version = "0.1",
       description = "Module for retrieving information about a DVD",
       author = "Dirk Meyer, based on ifoinfo by Ben Gertzfield",
       author_email = "[EMAIL PROTECTED]",
       url = "",

       # Description of the modules and packages in the distribution
       # py_modules = ['CDDB', 'DiscID'],
       ext_modules = [ Extension('ifoinfo', ['ifomodule.c'], libraries=[ 'dvdread' ]) ]
      )

--- NEW FILE: test.py ---
import ifoinfo

t = ifoinfo.open('/dev/dvd')

if t:
    print 'num of titles %s' % t
    for n in range(1, t+1):
        print 'title %s' % n
        print 'chapters: %s, angles: %s, playback time: %s, audio tracks: %s' % \
              ifoinfo.title(n)
        print
    





-------------------------------------------------------
This SF.net email is sponsored by:  Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to