/** * update_remote_catalog * * Pulls the data from a remote catalog and adds any missing songs to the * database. */ public function update_remote_catalog() { $songsadded = 0; try { $api = $this->createClient(); if ($api != null) { // Get all liked songs $songs = json_decode($api->get('me/favorites')); if ($songs) { foreach ($songs as $song) { if ($song->streamable == true && $song->kind == 'track') { $data = array(); $data['artist'] = $song->user->username; $data['album'] = $data['artist']; $data['title'] = $song->title; $data['year'] = $song->release_year; $data['mode'] = 'vbr'; $data['genre'] = explode(' ', $song->genre); $data['comment'] = $song->description; $data['file'] = $song->stream_url . '.mp3'; // Always stream as mp3, if evolve => $song->original_format; $data['size'] = $song->original_content_size; $data['time'] = intval($song->duration / 1000); if ($this->check_remote_song($data)) { debug_event('soundcloud_catalog', 'Skipping existing song ' . $data['file'], 5); } else { $data['catalog'] = $this->id; debug_event('soundcloud_catalog', 'Adding song ' . $data['file'], 5, 'ampache-catalog'); if (!Song::insert($data)) { debug_event('soundcloud_catalog', 'Insert failed for ' . $data['file'], 1); AmpError::add('general', T_('Unable to Insert Song - %s'), $data['file']); } else { $songsadded++; } } } } UI::update_text('', T_('Completed updating SoundCloud catalog(s).') . " " . $songsadded . " " . T_('Songs added.')); // Update the last update value $this->update_last_update(); } else { AmpError::add('general', T_('API Error: cannot get song list.')); } } else { AmpError::add('general', T_('API Error: cannot connect to SoundCloud.')); } } catch (Exception $ex) { AmpError::add('general', T_('SoundCloud exception: ') . $ex->getMessage()); } return true; }
/** * insert_local_song * * Insert a song that isn't already in the database. */ private function insert_local_song($file, $options = array()) { $vainfo = new vainfo($file, $this->get_gather_types('music'), '', '', '', $this->sort_pattern, $this->rename_pattern); $vainfo->get_info(); $key = vainfo::get_tag_type($vainfo->tags); $results = vainfo::clean_tag_info($vainfo->tags, $key, $file); $results['catalog'] = $this->id; if (isset($options['user_upload'])) { $results['user_upload'] = $options['user_upload']; } if (isset($options['license'])) { $results['license'] = $options['license']; } if (isset($options['artist_id'])) { $results['artist_id'] = $options['artist_id']; $results['albumartist_id'] = $options['artist_id']; } if (isset($options['album_id'])) { $results['album_id'] = $options['album_id']; } $id = Song::insert($results); // If song rating tag exists and is well formed (array user=>rating), add it if ($id && array_key_exists('rating', $results) && is_array($results['rating'])) { // For each user's ratings, call the function foreach ($results['rating'] as $user => $rating) { debug_event('Rating', "Setting rating for Song {$id} to {$rating} for user {$user}", 5); $o_rating = new Rating($id, 'song'); $o_rating->set_rating($rating, $user); } } // Extended metadata loading is not deferred, retrieve it now if ($id && !AmpConfig::get('deferred_ext_metadata')) { $song = new Song($id); Recommendation::get_artist_info($song->artist); } if (Song::isCustomMetadataEnabled()) { if (!$song) { $song = new Song($id); } $results = array_diff_key($results, array_flip($song->getDisabledMetadataFields())); self::add_metadata($song, $results); } $this->added_songs_to_gather[] = $id; $this->_filecache[strtolower($file)] = $id; return $id; }
/** * _insert_local_song * * Insert a song that isn't already in the database. */ private function _insert_local_song($file, $file_info) { $vainfo = new vainfo($file, '', '', '', $this->sort_pattern, $this->rename_pattern); $vainfo->get_info(); $key = vainfo::get_tag_type($vainfo->tags); $results = vainfo::clean_tag_info($vainfo->tags, $key, $file); $results['catalog'] = $this->id; return Song::insert($results); }
/** * update_remote_catalog * * Pulls the data from a remote catalog and adds any missing songs to the * database. */ public function update_remote_catalog($type = 0) { set_time_limit(0); $remote_handle = $this->connect(); if (!$remote_handle) { return false; } // Get the song count, etc. $remote_catalog_info = $remote_handle->info(); // Tell 'em what we've found, Johnny! printf(T_('%u remote catalog(s) found (%u songs)'), $remote_catalog_info['catalogs'], $remote_catalog_info['songs']); flush(); // Hardcoded for now $step = 500; $current = 0; $total = $remote_catalog_info['songs']; while ($total > $current) { $start = $current; $current += $step; try { $songs = $remote_handle->send_command('songs', array('offset' => $start, 'limit' => $step)); } catch (Exception $e) { Error::add('general', $e->getMessage()); Error::display('general'); flush(); } // Iterate over the songs we retrieved and insert them foreach ($songs as $data) { if ($this->check_remote_song($data['song'])) { debug_event('remote_catalog', 'Skipping existing song ' . $data['song']['url'], 5); } else { $data['song']['catalog'] = $this->id; $data['song']['file'] = preg_replace('/ssid=.*?&/', '', $data['song']['url']); if (!Song::insert($data['song'])) { debug_event('remote_catalog', 'Insert failed for ' . $data['song']['self']['id'], 1); Error::add('general', T_('Unable to Insert Song - %s'), $data['song']['title']); Error::display('general'); flush(); } } } } // end while echo "<p>" . T_('Completed updating remote catalog(s).') . "</p><hr />\n"; flush(); // Update the last update value $this->update_last_update(); return true; }
/** * update_remote_catalog * * Pulls the data from a remote catalog and adds any missing songs to the * database. */ public function update_remote_catalog() { debug_event('subsonic_catalog', 'Updating remote catalog...', 5); $subsonic = $this->createClient(); $songsadded = 0; // Get all artists $artists = $subsonic->getIndexes(); if ($artists['success']) { foreach ($artists['data']['indexes']['index'] as $index) { foreach ($index['artist'] as $artist) { // Get albums for artist $albums = $subsonic->getMusicDirectory(array('id' => $artist['id'])); if ($albums['success']) { foreach ($albums['data']['directory']['child'] as $album) { if (is_array($album)) { $songs = $subsonic->getMusicDirectory(array('id' => $album['id'])); if ($songs['success']) { foreach ($songs['data']['directory']['child'] as $song) { if (is_array($song)) { $data = array(); $data['artist'] = html_entity_decode($song['artist']); $data['album'] = html_entity_decode($song['album']); $data['title'] = html_entity_decode($song['title']); $data['bitrate'] = $song['bitRate'] * 1000; $data['size'] = $song['size']; $data['time'] = $song['duration']; $data['track'] = $song['track']; $data['disk'] = $song['discNumber']; $data['mode'] = 'vbr'; $data['genre'] = explode(' ', html_entity_decode($song['genre'])); $data['file'] = $this->uri . '/rest/stream.view?id=' . $song['id'] . '&filename=' . urlencode($song['path']); if ($this->check_remote_song($data)) { debug_event('subsonic_catalog', 'Skipping existing song ' . $data['path'], 5); } else { $data['catalog'] = $this->id; debug_event('subsonic_catalog', 'Adding song ' . $song['path'], 5, 'ampache-catalog'); if (!Song::insert($data)) { debug_event('subsonic_catalog', 'Insert failed for ' . $song['path'], 1); AmpError::add('general', T_('Unable to Insert Song - %s'), $song['path']); } else { $songsadded++; } } } } } else { debug_event('subsonic_catalog', 'Song error:' . $songs['error'], 3); AmpError::add('general', T_('Song Error.') . ": " . $songs['error']); } } } } else { debug_event('subsonic_catalog', 'Album error:' . $albums['error'], 3); AmpError::add('general', T_('Album Error.') . ": " . $albums['error']); } } } UI::update_text('', T_('Completed updating Subsonic catalog(s).') . " " . $songsadded . " " . T_('Songs added.')); // Update the last update value $this->update_last_update(); } else { debug_event('subsonic_catalog', 'Artist error:' . $artists['error'], 3); AmpError::add('general', T_('Artist Error.') . ": " . $artists['error']); } debug_event('subsonic_catalog', 'Catalog updated.', 5); return true; }
/** * insert_local_song * * Insert a song that isn't already in the database. */ private function insert_local_song($file, $options = array()) { $vainfo = new vainfo($file, $this->get_gather_types('music'), '', '', '', $this->sort_pattern, $this->rename_pattern); $vainfo->get_info(); $key = vainfo::get_tag_type($vainfo->tags); $results = vainfo::clean_tag_info($vainfo->tags, $key, $file); $results['catalog'] = $this->id; if (isset($options['user_upload'])) { $results['user_upload'] = $options['user_upload']; } if (isset($options['license'])) { $results['license'] = $options['license']; } if (isset($options['artist_id'])) { $results['artist_id'] = $options['artist_id']; $results['albumartist_id'] = $options['artist_id']; } if (isset($options['album_id'])) { $results['album_id'] = $options['album_id']; } $id = Song::insert($results); // Extended metadata loading is not deferred, retrieve it now if ($id && !AmpConfig::get('deferred_ext_metadata')) { $song = new Song($id); Recommendation::get_artist_info($song->artist); } $this->added_songs_to_gather[] = $id; $this->_filecache[strtolower($file)] = $id; return $id; }
/** * _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); } } }