Example #1
0
 /**
  * insert
  * This takes the string representation of an image and inserts it into
  * the database. You must also pass the mime type.
  * @param string $source
  * @param string $mime
  * @return boolean
  */
 public function insert($source, $mime = '')
 {
     // Disabled in demo mode cause people suck and upload p**n
     if (AmpConfig::get('demo_mode')) {
         return false;
     }
     // Check to make sure we like this image
     if (!self::test_image($source)) {
         debug_event('Art', 'Not inserting image, invalid data passed', 1);
         return false;
     }
     // Default to image/jpeg if they don't pass anything
     $mime = $mime ? $mime : 'image/jpeg';
     // Blow it away!
     $this->reset();
     if (AmpConfig::get('write_id3_art')) {
         if ($this->type == 'album') {
             $album = new Album($this->uid);
             debug_event('Art', 'Inserting image Album ' . $album->name . ' on songs.', 5);
             $songs = $album->get_songs();
             foreach ($songs as $song_id) {
                 $song = new Song($song_id);
                 $song->format();
                 $id3 = new vainfo($song->file);
                 $data = $id3->read_id3();
                 if (isset($data['tags']['id3v2'])) {
                     $image_from_tag = '';
                     if (isset($data['id3v2']['APIC'][0]['data'])) {
                         $image_from_tag = $data['id3v2']['APIC'][0]['data'];
                     }
                     if ($image_from_tag != $source) {
                         $ndata = array();
                         $ndata['APIC']['data'] = $source;
                         $ndata['APIC']['mime'] = $mime;
                         $ndata = array_merge($ndata, $song->get_metadata());
                         $id3->write_id3($ndata);
                     }
                 }
             }
         }
     }
     $dimensions = Core::image_dimensions($source);
     $width = intval($dimensions['width']);
     $height = intval($dimensions['height']);
     $sizetext = 'original';
     if (!self::check_dimensions($dimensions)) {
         return false;
     }
     if (AmpConfig::get('album_art_store_disk')) {
         self::write_to_dir($source, $sizetext, $this->type, $this->uid, $this->kind);
         $source = null;
     }
     // Insert it!
     $sql = "INSERT INTO `image` (`image`, `mime`, `size`, `width`, `height`, `object_type`, `object_id`, `kind`) VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
     Dba::write($sql, array($source, $mime, $sizetext, $width, $height, $this->type, $this->uid, $this->kind));
     return true;
 }
Example #2
0
 /**
  * update_media_from_tags
  * This is a 'wrapper' function calls the update function for the media
  * type in question
  */
 public static function update_media_from_tags($media, $sort_pattern = '', $rename_pattern = '')
 {
     // Check for patterns
     if (!$sort_pattern or !$rename_pattern) {
         $catalog = Catalog::create_from_id($media->catalog);
         $sort_pattern = $catalog->sort_pattern;
         $rename_pattern = $catalog->rename_pattern;
     }
     debug_event('tag-read', 'Reading tags from ' . $media->file, 5);
     $vainfo = new vainfo($media->file, '', '', '', $sort_pattern, $rename_pattern);
     $vainfo->get_info();
     $key = vainfo::get_tag_type($vainfo->tags);
     $results = vainfo::clean_tag_info($vainfo->tags, $key, $media->file);
     // Figure out what type of object this is and call the right
     // function, giving it the stuff we've figured out above
     $name = get_class($media) == 'Song' ? 'song' : 'video';
     $function = 'update_' . $name . '_from_tags';
     $return = call_user_func(array('Catalog', $function), $results, $media);
     return $return;
 }
Example #3
0
 /**
  * insert_local_video
  * This inserts a video file into the video file table the tag
  * information we can get is super sketchy so it's kind of a crap shoot
  * here
  */
 public function insert_local_video($file, $options = array())
 {
     /* Create the vainfo object and get info */
     $gtypes = $this->get_gather_types('video');
     $vainfo = new vainfo($file, $gtypes, '', '', '', $this->sort_pattern, $this->rename_pattern);
     $vainfo->get_info();
     $tag_name = vainfo::get_tag_type($vainfo->tags, 'metadata_order_video');
     $results = vainfo::clean_tag_info($vainfo->tags, $tag_name, $file);
     $results['catalog'] = $this->id;
     $id = Video::insert($results, $gtypes, $options);
     if ($results['art']) {
         $art = new Art($id, 'video');
         $art->insert_url($results['art']);
         if (AmpConfig::get('generate_video_preview')) {
             Video::generate_preview($id);
         }
     } else {
         $this->added_videos_to_gather[] = $id;
     }
     $this->_filecache[strtolower($file)] = 'v_' . $id;
     return $id;
 }
Example #4
0
 /**
  * insert_local_video
  * This inserts a video file into the video file table the tag
  * information we can get is super sketchy so it's kind of a crap shoot
  * here
  */
 public function insert_local_video($file, $filesize)
 {
     /* Create the vainfo object and get info */
     $vainfo = new vainfo($file, '', '', '', $this->sort_pattern, $this->rename_pattern);
     $vainfo->get_info();
     $tag_name = vainfo::get_tag_type($vainfo->tags);
     $results = vainfo::clean_tag_info($vainfo->tags, $tag_name, $file);
     $rezx = intval($results['resolution_x']);
     $rezy = intval($results['resolution_y']);
     // UNUSED CURRENTLY
     $comment = $results['comment'];
     $year = $results['year'];
     $disk = $results['disk'];
     $sql = "INSERT INTO `video` (`file`,`catalog`,`title`,`video_codec`,`audio_codec`,`resolution_x`,`resolution_y`,`size`,`time`,`mime`) " . " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
     $params = array($file, $this->id, $results['title'], $results['video_codec'], $results['audio_codec'], $rezx, $rezy, $filesize, $results['time'], $results['mime']);
     $db_results = Dba::write($sql, $params);
     return true;
 }
Example #5
0
 public function gather()
 {
     if (!empty($this->source)) {
         $podcast = new Podcast($this->podcast);
         $file = $podcast->get_root_path();
         if (!empty($file)) {
             $pinfo = pathinfo($this->source);
             $file .= DIRECTORY_SEPARATOR . $this->id . '-' . $pinfo['basename'];
             debug_event('podcast_episode', 'Downloading ' . $this->source . ' to ' . $file . ' ...', 5);
             if (file_put_contents($file, fopen($this->source, 'r')) !== false) {
                 debug_event('podcast_episode', 'Download completed.', 5);
                 $this->file = $file;
                 $vainfo = new vainfo($this->file);
                 $vainfo->get_info();
                 $key = vainfo::get_tag_type($vainfo->tags);
                 $infos = vainfo::clean_tag_info($vainfo->tags, $key, $file);
                 // No time information, get it from file
                 if ($this->time <= 0) {
                     $this->time = $infos['time'];
                 }
                 $this->size = $infos['size'];
                 $sql = "UPDATE `podcast_episode` SET `file` = ?, `size` = ?, `time` = ?, `state` = 'completed' WHERE `id` = ?";
                 Dba::write($sql, array($this->file, $this->size, $this->time, $this->id));
             } else {
                 debug_event('podcast_episode', 'Error when downloading podcast episode.', 1);
             }
         }
     } else {
         debug_event('podcast_episode', 'Cannot download podcast episode ' . $this->id . ', empty source.', 3);
     }
 }
Example #6
0
 /**
  * _insert_local_song
  *
  * Insert a song that isn't already in the database.
  */
 private function insert_song($client, $file, $filesize)
 {
     if ($this->check_remote_song($this->get_virtual_path($file))) {
         debug_event('dropbox_catalog', 'Skipping existing song ' . $file, 5);
     } else {
         $origin = $file;
         $islocal = false;
         $fpchunk = 0;
         // Get temporary chunked file from Dropbox to (hope) read metadata
         if ($this->getchunk) {
             $fpchunk = tmpfile();
             $metadata = $client->getFile($file, $fpchunk, null, 40960);
             if ($metadata == null) {
                 debug_event('dropbox_catalog', 'Cannot get Dropbox file: ' . $file, 5);
             }
             $streammeta = stream_get_meta_data($fpchunk);
             $file = $streammeta['uri'];
             $islocal = true;
         }
         $vainfo = new vainfo($file, '', '', '', $this->sort_pattern, $this->rename_pattern, $islocal);
         $vainfo->forceSize($filesize);
         $vainfo->get_info();
         $key = vainfo::get_tag_type($vainfo->tags);
         $results = vainfo::clean_tag_info($vainfo->tags, $key, $file);
         // Remove temp file
         if ($fpchunk) {
             fclose($fpchunk);
         }
         // Set the remote path
         $results['file'] = $origin;
         $results['catalog'] = $this->id;
         if (!empty($results['artist']) && !empty($results['album'])) {
             $results['file'] = $this->get_virtual_path($results['file']);
             Song::insert($results);
             $this->count++;
         } else {
             debug_event('results', $results['file'] . " ignored because it is an orphan songs. Please check your catalog patterns.", 5);
         }
     }
 }
Example #7
0
 /**
  * write_id3
  * Write the current song id3 metadata to the file
  */
 public function write_id3()
 {
     if (AmpConfig::get('write_id3')) {
         $catalog = Catalog::create_from_id($this->catalog);
         if ($catalog->get_type() == 'local') {
             debug_event('song', 'Writing id3 metadata to file ' . $this->file, 5);
             $meta = $this->get_metadata();
             $id3 = new vainfo($this->file);
             $id3->write_id3($meta);
         }
     }
 }
Example #8
0
 /**
  * write_id3
  * Write the current song id3 metadata to the file
  */
 public function write_id3()
 {
     if (AmpConfig::get('write_id3')) {
         $catalog = Catalog::create_from_id($this->catalog);
         if ($catalog->get_type() == 'local') {
             debug_event('song', 'Writing id3 metadata to file ' . $this->file, 5);
             $meta = $this->get_metadata();
             if (self::isCustomMetadataEnabled()) {
                 foreach ($this->getMetadata() as $metadata) {
                     $meta[$metadata->getField()->getName()] = $metadata->getData();
                 }
             }
             $id3 = new vainfo($this->file);
             $id3->write_id3($meta);
             Catalog::update_media_from_tags($this);
         }
     }
 }