Skip to content

Instantly share code, notes, and snippets.

@scruffyfox
Last active December 24, 2015 13:59
Show Gist options
  • Select an option

  • Save scruffyfox/6809375 to your computer and use it in GitHub Desktop.

Select an option

Save scruffyfox/6809375 to your computer and use it in GitHub Desktop.
Create playlist-like structure on file system
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Structure file for filelist.
;Each group is the path of the list, and each line after that is a link
;to include in that list
;
;This should be stored as .structure in the root directory
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[path=/media/music/by-genre/rock/]
/Users/callumtaylor/Desktop/test/media/music/Autopilot Off
[path=/media/music/by-genre/metal/]
/media/music/Black Sabbath
/media/music/Autopilot Off
[path=/media/music/by-genre/all/]
/media/music/*
#! /bin/sh
# /etc/init.d/filelist
#
# Deals with running the file list generator
touch /var/lock/filelist
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting"
sudo /usr/sbin/filelist.rb -f /mnt/filestore/media/music/ > /logs/music-filelist.log 2>&1 &
sudo /usr/sbin/filelist.rb -f /mnt/filestore/media/movies/ > /logs/movies-filelist.log 2>&1 &
sudo /usr/sbin/filelist.rb -f /mnt/filestore/media/tv-shows/ > /logs/tv-shows-filelist.log 2>&1 &
sudo /usr/sbin/filelist.rb -f /mnt/filestore/media/photos/ > /logs/photos-filelist.log 2>&1 &
;;
stop)
echo "Stopping"
sudo kill $(ps aux | grep '/usr/sbin/filelist.rb' | awk '{print $2}')
;;
*)
echo "Usage: /etc/init.d/filelist {start|stop}"
exit 1
;;
esac
exit 0
#!/usr/bin/ruby
require 'fileutils'
def main(base_path)
File.open(base_path + "/.structure", "r") do |file|
last_group = ""
while (line = file.gets)
if (line[/^\;/] != nil or line.strip.length < 1)
next
end
if (line[/\[.*\]/] != nil)
path = line.gsub(/\n/, "").strip;
path = path[1 .. path.length - 2]
paths = path.split("=")
last_group = paths[1].strip
reset_path(last_group)
next
else
path = line.strip.split("\t")
handle_path(last_group, path[0], path[1] || [])
end
end
end
end
def reset_path(path)
FileUtils.rm_rf path
FileUtils.mkdir_p path
end
def handle_path(path, link. regex)
cmd = "python /usr/sbin/rln.py -s \"#{link}\" \"#{path}\" #{regex}"
puts cmd
system(cmd)
end
def watch(path)
changed = false
if (File.exist?(path + "/.structure"))
lasttime = File.mtime(path + "/.structure")
while (!changed)
sleep(1)
changed = lasttime != File.mtime(path + "/.structure")
end
main(path)
watch(path)
end
end
if (ARGV.length < 1)
puts "Creates a playlist like folder structure"
puts "Usage: filelist [-f] <path to .structure>"
puts "Options: "
puts " -f Force rebuild"
puts ""
puts "Example .structure file"
puts ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
puts ";Structure file for filelist."
puts ";Each group is the path of the list, and each line after that is a link"
puts ";to include in that list"
puts ";"
puts ";This should be stored as .structure in the root directory"
puts ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
puts "[path=/media/music/by-genre/rock/]"
puts "/Users/callumtaylor/Desktop/test/media/music/Autopilot Off"
puts "[path=/media/music/by-genre/metal/]"
puts "/media/music/Black Sabbath"
puts "/media/music/Autopilot Off"
else
if (ARGV[0] == "-f")
main(ARGV[1])
ARGV[0] = ARGV[1]
end
watch(ARGV[0])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment