<commit_before><?php declare(strict_types=1);

/**
 * ownCloud - Music app
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @copyright <NAME> 2013, 2014
 * @copyright <NAME> 2016 - 2020
 */

namespace OCA\Music\Utility;

use OC\Hooks\PublicEmitter;

use \OCP\Files\File;
use \OCP\Files\Folder;
use \OCP\Files\IRootFolder;

use \OCA\Music\AppFramework\Core\Logger;
use \OCA\Music\BusinessLayer\ArtistBusinessLayer;
use \OCA\Music\BusinessLayer\AlbumBusinessLayer;
use \OCA\Music\BusinessLayer\GenreBusinessLayer;
use \OCA\Music\BusinessLayer\PlaylistBusinessLayer;
use \OCA\Music\BusinessLayer\TrackBusinessLayer;
use \OCA\Music\Db\Cache;
use \OCA\Music\Db\Maintenance;

use Symfony\Component\Console\Output\OutputInterface;

class Scanner extends PublicEmitter {
	private $extractor;
	private $artistBusinessLayer;
	private $albumBusinessLayer;
	private $trackBusinessLayer;
	private $playlistBusinessLayer;
	private $genreBusinessLayer;
	private $cache;
	private $coverHelper;
	private $logger;
	private $maintenance;
	private $userMusicFolder;
	private $rootFolder;

	public function __construct(Extractor $extractor,
								ArtistBusinessLayer $artistBusinessLayer,
								AlbumBusinessLayer $albumBusinessLayer,
								TrackBusinessLayer $trackBusinessLayer,
								PlaylistBusinessLayer $playlistBusinessLayer,
								GenreBusinessLayer $genreBusinessLayer,
								Cache $cache,
								CoverHelper $coverHelper,
								Logger $logger,
								Maintenance $maintenance,
								UserMusicFolder $userMusicFolder,
								IRootFolder $rootFolder) {
		$this->extractor = $extractor;
		$this->artistBusinessLayer = $artistBusinessLayer;
		$this->albumBusinessLayer = $albumBusinessLayer;
		$this->trackBusinessLayer = $trackBusinessLayer;
		$this->playlistBusinessLayer = $playlistBusinessLayer;
		$this->genreBusinessLayer = $genreBusinessLayer;
		$this->cache = $cache;
		$this->coverHelper = $coverHelper;
		$this->logger = $logger;
		$this->maintenance = $maintenance;
		$this->userMusicFolder = $userMusicFolder;
		$this->rootFolder = $rootFolder;

		// Trying to enable stream support
		if (\ini_get('allow_url_fopen') !== '1') {
			$this->logger->log('allow_url_fopen is disabled. It is strongly advised to enable it in your php.ini', 'warn');
			@\ini_set('allow_url_fopen', '1');
		}
	}

	/**
	 * Gets called by 'post_write' (file creation, file update) and 'post_share' hooks
	 * @param File $file the file
	 * @param string $userId
	 * @param Folder $userHome
	 * @param string|null $filePath Deduced from $file if not given
	 */
	public function update(File $file, string $userId, Folder $userHome, string $filePath = null) : void {
		if ($filePath === null) {
			$filePath = $file->getPath();
		}

		// debug logging
		$this->logger->log("update - $filePath", 'debug');

		if (!($file instanceof File) || !$userId || !($userHome instanceof Folder)) {
			$this->logger->log('Invalid arguments given to Scanner.update - file='.\get_class($file).
					", userId=$userId, userHome=".\get_class($userHome), 'warn');
			return;
		}

		// skip files that aren't inside the user specified path
		if (!$this->userMusicFolder->pathBelongsToMusicLibrary($filePath, $userId)) {
			$this->logger->log("skipped - file is outside of specified music folder", 'debug');
			return;
		}

		$mimetype = $file->getMimeType();

		// debug logging
		$this->logger->log("update - mimetype $mimetype", 'debug');

		if (Util::startsWith($mimetype, 'image')) {<commit_msg>Remove redundant type checks from Scanner::update<commit_after><?php declare(strict_types=1);

/**
 * ownCloud - Music app
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @copyright <NAME> 2013, 2014
 * @copyright <NAME> 2016 - 2020
 */

namespace OCA\Music\Utility;

use OC\Hooks\PublicEmitter;

use \OCP\Files\File;
use \OCP\Files\Folder;
use \OCP\Files\IRootFolder;

use \OCA\Music\AppFramework\Core\Logger;
use \OCA\Music\BusinessLayer\ArtistBusinessLayer;
use \OCA\Music\BusinessLayer\AlbumBusinessLayer;
use \OCA\Music\BusinessLayer\GenreBusinessLayer;
use \OCA\Music\BusinessLayer\PlaylistBusinessLayer;
use \OCA\Music\BusinessLayer\TrackBusinessLayer;
use \OCA\Music\Db\Cache;
use \OCA\Music\Db\Maintenance;

use Symfony\Component\Console\Output\OutputInterface;

class Scanner extends PublicEmitter {
	private $extractor;
	private $artistBusinessLayer;
	private $albumBusinessLayer;
	private $trackBusinessLayer;
	private $playlistBusinessLayer;
	private $genreBusinessLayer;
	private $cache;
	private $coverHelper;
	private $logger;
	private $maintenance;
	private $userMusicFolder;
	private $rootFolder;

	public function __construct(Extractor $extractor,
								ArtistBusinessLayer $artistBusinessLayer,
								AlbumBusinessLayer $albumBusinessLayer,
								TrackBusinessLayer $trackBusinessLayer,
								PlaylistBusinessLayer $playlistBusinessLayer,
								GenreBusinessLayer $genreBusinessLayer,
								Cache $cache,
								CoverHelper $coverHelper,
								Logger $logger,
								Maintenance $maintenance,
								UserMusicFolder $userMusicFolder,
								IRootFolder $rootFolder) {
		$this->extractor = $extractor;
		$this->artistBusinessLayer = $artistBusinessLayer;
		$this->albumBusinessLayer = $albumBusinessLayer;
		$this->trackBusinessLayer = $trackBusinessLayer;
		$this->playlistBusinessLayer = $playlistBusinessLayer;
		$this->genreBusinessLayer = $genreBusinessLayer;
		$this->cache = $cache;
		$this->coverHelper = $coverHelper;
		$this->logger = $logger;
		$this->maintenance = $maintenance;
		$this->userMusicFolder = $userMusicFolder;
		$this->rootFolder = $rootFolder;

		// Trying to enable stream support
		if (\ini_get('allow_url_fopen') !== '1') {
			$this->logger->log('allow_url_fopen is disabled. It is strongly advised to enable it in your php.ini', 'warn');
			@\ini_set('allow_url_fopen', '1');
		}
	}

	/**
	 * Gets called by 'post_write' (file creation, file update) and 'post_share' hooks
	 * @param File $file the file
	 * @param string $userId
	 * @param Folder $userHome
	 * @param string|null $filePath Deduced from $file if not given
	 */
	public function update(File $file, string $userId, Folder $userHome, string $filePath = null) : void {
		if ($filePath === null) {
			$filePath = $file->getPath();
		}

		// debug logging
		$this->logger->log("update - $filePath", 'debug');

		// skip files that aren't inside the user specified path
		if (!$this->userMusicFolder->pathBelongsToMusicLibrary($filePath, $userId)) {
			$this->logger->log("skipped - file is outside of specified music folder", 'debug');
			return;
		}

		$mimetype = $file->getMimeType();

		// debug logging
		$this->logger->log("update - mimetype $mimetype", 'debug');

		if (Util::startsWith($mimetype, 'image')) {
{'fraction_non_alphanumeric': 0.12794371051120046, 'fraction_numerical': 0.005743825387708214, 'mean_word_length': 4.437158469945355, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2190908', 'n_tokens_mistral': 2526, 'n_tokens_neox': 2157, 'n_words': 529}