<?phpnamespace App\Media;/** The user's own folders: Musique / Music and Vidéos / Videos (XDG user dirs on Linux, the profile on Windows). */final class MediaDirs{ public static function home(): string { $home = getenv('HOME') ?: getenv('USERPROFILE') ?: ((getenv('HOMEDRIVE') ?: '') . (getenv('HOMEPATH') ?: '')); return rtrim((string)$home, '/\\'); } /** $kind: MUSIC | VIDEOS */ public static function user(string $kind): string { $home = self::home(); $dirs = $home . '/.config/user-dirs.dirs'; if (PHP_OS_FAMILY !== 'Windows' && is_file($dirs) && preg_match('/^XDG_' . $kind . '_DIR="([^"]+)"/m', (string)file_get_contents($dirs), $m)) { $dir = str_replace('$HOME', $home, $m[1]); if ($dir !== $home && $dir !== '') { return $dir; } } foreach ($kind === 'MUSIC' ? ['Musique', 'Music'] : ['Vidéos', 'Videos'] as $name) { if (is_dir("$home/$name")) { return "$home/$name"; } } return $home . '/' . ($kind === 'MUSIC' ? 'Music' : 'Videos'); } /** Where WinZik puts what it downloads: Music/WinZik, Videos/WinZik. */ public static function winzik(string $kind): string { return self::user($kind) . '/WinZik'; }}