Esempio n. 1
0
 /**
  * insert
  * Insert a new tv show episode and related entities.
  */
 public static function insert(array $data, $gtypes = array(), $options = array())
 {
     if (empty($data['tvshow'])) {
         $data['tvshow'] = T_('Unknown');
     }
     $tags = $data['genre'];
     $tvshow = TVShow::check($data['tvshow'], $data['year']);
     if ($options['gather_art'] && $tvshow && $data['tvshow_art'] && !Art::has_db($tvshow, 'tvshow')) {
         $art = new Art($tvshow, 'tvshow');
         $art->insert_url($data['tvshow_art']);
     }
     $tvshow_season = TVShow_Season::check($tvshow, $data['tvshow_season']);
     if ($options['gather_art'] && $tvshow_season && $data['tvshow_season_art'] && !Art::has_db($tvshow_season, 'tvshow_season')) {
         $art = new Art($tvshow_season, 'tvshow_season');
         $art->insert_url($data['tvshow_season_art']);
     }
     if (is_array($tags)) {
         foreach ($tags as $tag) {
             $tag = trim($tag);
             if (!empty($tag)) {
                 Tag::add('tvshow_season', $tvshow_season, $tag, false);
                 Tag::add('tvshow', $tvshow, $tag, false);
             }
         }
     }
     $sdata = $data;
     // Replace relation name with db ids
     $sdata['tvshow'] = $tvshow;
     $sdata['tvshow_season'] = $tvshow_season;
     return self::create($sdata);
 }
Esempio n. 2
0
 public static function create(array $data)
 {
     $feed = $data['feed'];
     // Feed must be http/https
     if (strpos($feed, "http://") !== 0 && strpos($feed, "https://") !== 0) {
         AmpError::add('feed', T_('Wrong feed url'));
     }
     $catalog_id = intval($data['catalog']);
     if ($catalog_id <= 0) {
         AmpError::add('catalog', T_('Target catalog required'));
     } else {
         $catalog = Catalog::create_from_id($catalog_id);
         if ($catalog->gather_types !== "podcast") {
             AmpError::add('catalog', T_('Wrong target catalog type'));
         }
     }
     if (AmpError::occurred()) {
         return false;
     }
     $title = T_('Unknown');
     $website = null;
     $description = null;
     $language = null;
     $copyright = null;
     $generator = null;
     $lastbuilddate = 0;
     $episodes = array();
     $arturl = '';
     $xmlstr = file_get_contents($feed);
     if ($xmlstr === false) {
         AmpError::add('feed', T_('Cannot access the feed.'));
     } else {
         $xml = simplexml_load_string($xmlstr);
         if ($xml === false) {
             AmpError::add('feed', T_('Cannot read the feed.'));
         } else {
             $title = html_entity_decode($xml->channel->title);
             $website = $xml->channel->link;
             $description = html_entity_decode($xml->channel->description);
             $language = $xml->channel->language;
             $copyright = html_entity_decode($xml->channel->copyright);
             $generator = html_entity_decode($xml->channel->generator);
             $lastbuilddatestr = $xml->channel->lastBuildDate;
             if ($lastbuilddatestr) {
                 $lastbuilddate = strtotime($lastbuilddatestr);
             }
             if ($xml->channel->image) {
                 $arturl = $xml->channel->image->url;
             }
             $episodes = $xml->channel->item;
         }
     }
     if (AmpError::occurred()) {
         return false;
     }
     $sql = "INSERT INTO `podcast` (`feed`, `catalog`, `title`, `website`, `description`, `language`, `copyright`, `generator`, `lastbuilddate`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
     $db_results = Dba::write($sql, array($feed, $catalog_id, $title, $website, $description, $language, $copyright, $generator, $lastbuilddate));
     if ($db_results) {
         $id = Dba::insert_id();
         $podcast = new Podcast($id);
         $dirpath = $podcast->get_root_path();
         if (!is_dir($dirpath)) {
             if (mkdir($dirpath) === false) {
                 debug_event('podcast', 'Cannot create directory ' . $dirpath, 1);
             }
         }
         if (!empty($arturl)) {
             $art = new Art($id, 'podcast');
             $art->insert_url($arturl);
         }
         if (count($episodes) > 0) {
             $podcast->add_episodes($episodes);
         }
     }
     return $db_results;
 }
Esempio n. 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;
 }
Esempio n. 4
0
 /**
  * Insert new video.
  * @param array $data
  * @param array $gtypes
  * @param array $options
  * @return int
  */
 public static function insert(array $data, $gtypes = array(), $options = array())
 {
     $bitrate = intval($data['bitrate']);
     $mode = $data['mode'];
     $rezx = intval($data['resolution_x']);
     $rezy = intval($data['resolution_y']);
     $release_date = intval($data['release_date']);
     // No release date, then release date = production year
     if (!$release_date && $data['year']) {
         $release_date = strtotime(strval($data['year']) . '-01-01');
     }
     $tags = $data['genre'];
     $channels = intval($data['channels']);
     $disx = intval($data['display_x']);
     $disy = intval($data['display_y']);
     $frame_rate = floatval($data['frame_rate']);
     $video_bitrate = intval($data['video_bitrate']);
     $sql = "INSERT INTO `video` (`file`,`catalog`,`title`,`video_codec`,`audio_codec`,`resolution_x`,`resolution_y`,`size`,`time`,`mime`,`release_date`,`addition_time`, `bitrate`, `mode`, `channels`, `display_x`, `display_y`, `frame_rate`, `video_bitrate`) " . " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
     $params = array($data['file'], $data['catalog'], $data['title'], $data['video_codec'], $data['audio_codec'], $rezx, $rezy, $data['size'], $data['time'], $data['mime'], $release_date, time(), $bitrate, $mode, $channels, $disx, $disy, $frame_rate, $video_bitrate);
     Dba::write($sql, $params);
     $vid = Dba::insert_id();
     if (is_array($tags)) {
         foreach ($tags as $tag) {
             $tag = trim($tag);
             if (!empty($tag)) {
                 Tag::add('video', $vid, $tag, false);
             }
         }
     }
     if ($data['art'] && $options['gather_art']) {
         $art = new Art($vid, 'video');
         $art->insert_url($data['art']);
     }
     $data['id'] = $vid;
     return self::insert_video_type($data, $gtypes, $options);
 }