Much base work started
This commit is contained in:
46
app/services/storage_discovery_service.rb
Normal file
46
app/services/storage_discovery_service.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
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
|
||||
Reference in New Issue
Block a user