<commit_before>// Filename: photo.cxx
// Created by:  drose (03Apr02)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license.  You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// <EMAIL> .
//
////////////////////////////////////////////////////////////////////

#include "photo.h"
#include "indexParameters.h"
#include "rollDirectory.h"


////////////////////////////////////////////////////////////////////
//     Function: Photo::Constructor
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
Photo::
Photo(RollDirectory *dir, const Filename &basename, 
      const string &movie_extension, const string &sound_extension) :
  _dir(dir),
  _basename(basename)
{
  _name = _basename.get_basename_wo_extension();
  _frame_number = _name;
  if (caption_frame_numbers) {
    const string &dirname = _dir->get_basename();

    // If the initial prefix of the filename is the same as the roll
    // directory, lop it off when caption_frame_numbers is in effect.
    if (_frame_number.substr(0, dirname.length()) == dirname) {
      _frame_number = _frame_number.substr(dirname.length());
      while (_frame_number.length() > 1 && _frame_number[0] == '0') {
        _frame_number = _frame_number.substr(1);
      }
    }
  }
  
  _full_x_size = 0;
  _full_y_size = 0;
  _reduced_x_size = 0;
  _reduced_y_size = 0;
  _has_reduced = false;

  _has_movie = false;
  Filename movie_filename(_dir->get_dir(), _basename);
  movie_filename.set_extension(movie_extension);
  if (movie_filename.exists()) {
    _movie = movie_filename.get_basename();
    _has_movie = true;
  }

  _has_sound = false;
  Filename sound_filename(_dir->get_dir(), _basename);
  sound_filename.set_extension(sound_extension);
  if (sound_filename.exists()) {
    _sound = sound_filename.get_basename();
    _has_sound = true;
  }

  _has_cm = false;
  Filename cm_filename(_dir->get_dir(), _basename);
  cm_filename.set_extension("cm");
  if (cm_filename.exists()) {
    _cm = cm_filename.get_basename();
    _has_cm = true;
  }
}

////////////////////////////////////////////////////////////////////
//     Function: Photo::get_basename
//       Access: Public
//  Description: Returns the filename of the photo within its roll
//               directory.
////////////////////////////////////////////////////////////////////<commit_msg>also look up standard extensions<commit_after>// Filename: photo.cxx
// Created by:  drose (03Apr02)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license.  You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// <EMAIL> .
//
////////////////////////////////////////////////////////////////////

#include "photo.h"
#include "indexParameters.h"
#include "rollDirectory.h"

static const char * const standard_movie_extensions[] = {
  "mov", "avi", "mpg", NULL
};

static const char * const standard_sound_extensions[] = {
  "jpg", "wav", "ogg", NULL
};
                                                


////////////////////////////////////////////////////////////////////
//     Function: Photo::Constructor
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
Photo::
Photo(RollDirectory *dir, const Filename &basename, 
      const string &movie_extension, const string &sound_extension) :
  _dir(dir),
  _basename(basename)
{
  _name = _basename.get_basename_wo_extension();
  _frame_number = _name;
  if (caption_frame_numbers) {
    const string &dirname = _dir->get_basename();

    // If the initial prefix of the filename is the same as the roll
    // directory, lop it off when caption_frame_numbers is in effect.
    if (_frame_number.substr(0, dirname.length()) == dirname) {
      _frame_number = _frame_number.substr(dirname.length());
      while (_frame_number.length() > 1 && _frame_number[0] == '0') {
        _frame_number = _frame_number.substr(1);
      }
    }
  }
  
  _full_x_size = 0;
  _full_y_size = 0;
  _reduced_x_size = 0;
  _reduced_y_size = 0;
  _has_reduced = false;

  _has_movie = false;
  Filename movie_filename(_dir->get_dir(), _basename);
  movie_filename.set_extension(movie_extension);
  if (movie_filename.exists()) {
    _movie = movie_filename.get_basename();
    _has_movie = true;

  } else {
    const char * const *ext;
    for (ext = standard_movie_extensions; *ext != NULL; ++ext) {
      movie_filename.set_extension(*ext);
      if (movie_filename.exists()) {
        _movie = movie_filename.get_basename();
        _has_movie = true;
      }
    }
  }

  _has_sound = false;
  Filename sound_filename(_dir->get_dir(), _basename);
  sound_filename.set_extension(sound_extension);
  if (sound_filename.exists()) {
    _sound = sound_filename.get_basename();
    _has_sound = true;

  } else {
    const char * const *ext;
    for (ext = standard_sound_extensions; *ext != NULL; ++ext) {
      sound_filename.set_extension(*ext);
      if (sound_filename.exists()) {
        _sound = sound_filename.get_basename();
        _has_sound = true;
      }
    }
  }

  _has_cm = false;
  Filename cm_filename(_dir->get_dir(), _basename);
  cm_filename.set_extension("cm");
  if (cm_filename.exists()) {
    _cm = cm_filename.get_basename();
    _has_cm = true;
  }
}

////////////////////////////////////////////////////////////////////
//     Function: Photo::get_basename
//       Access: Public
//  Description: Returns the filename of the photo within its roll
//               directory.
////////////////////////////////////////////////////////////////////
{'fraction_non_alphanumeric': 0.2335974643423138, 'fraction_numerical': 0.007606973058637084, 'mean_word_length': 1.9490654205607476, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6791988', 'n_tokens_mistral': 1870, 'n_tokens_neox': 1781, 'n_words': 464}