46 lines
1.2 KiB
Ruby
46 lines
1.2 KiB
Ruby
class StorageDiscoveryService
|
|
CATEGORIES = {
|
|
'movies' => 'Movies',
|
|
'tv' => 'TV Shows',
|
|
'tv_shows' => 'TV Shows',
|
|
'series' => 'TV Shows',
|
|
'docs' => 'Documentaries',
|
|
'documentaries' => 'Documentaries',
|
|
'anime' => 'Anime',
|
|
'cartoons' => 'Animation',
|
|
'animation' => 'Animation',
|
|
'sports' => 'Sports',
|
|
'music' => 'Music Videos',
|
|
'music_videos' => 'Music Videos',
|
|
'kids' => 'Kids Content',
|
|
'family' => 'Family Content'
|
|
}.freeze
|
|
|
|
def self.discover_and_create
|
|
base_path = '/videos'
|
|
return [] unless Dir.exist?(base_path)
|
|
|
|
discovered = []
|
|
|
|
Dir.children(base_path).each do |subdir|
|
|
dir_path = File.join(base_path, subdir)
|
|
next unless Dir.exist?(dir_path)
|
|
|
|
category = categorize_directory(subdir)
|
|
storage = StorageLocation.find_or_create_by!(
|
|
name: "#{category}: #{subdir.titleize}",
|
|
path: dir_path,
|
|
storage_type: 'local'
|
|
)
|
|
|
|
discovered << storage
|
|
end
|
|
|
|
discovered
|
|
end
|
|
|
|
def self.categorize_directory(dirname)
|
|
downcase = dirname.downcase
|
|
CATEGORIES[downcase] || CATEGORIES.find { |key, _| downcase.include?(key) }&.last || 'Other'
|
|
end
|
|
end |