Guest User

Untitled

a guest
Jan 18th, 2011
353
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. video_ext="avi mkv"
  4. player="smplayer -fullscreen"
  5. items_per_page=15
  6. more_label="More"
  7. playlist_enable=1
  8. playlist_minimum=5
  9. playlist_label="[Playlist]"
  10.  
  11. list_dir()
  12. {
  13.     local dir=$1
  14.  
  15.     local names="-iname '*.iso'"
  16.     for ext in $video_ext; do
  17.         names="$names -or -iname '*.${ext}'"
  18.     done
  19.  
  20.     eval find -s "\"$dir\"" -mindepth 1 -maxdepth 1 -type d -or $names | while read item; do
  21.         if [ `basename "$item" | cut -c 1` = '.' ]; then
  22.             continue
  23.         fi
  24.         if [ -d "$item" -a `count_video "$item"` -eq 0 ]; then
  25.             continue
  26.         fi
  27.  
  28.         echo "$item"
  29.     done
  30. }
  31.  
  32. count_video()
  33. {
  34.     local dir=$1
  35.  
  36.     local names="-name 'VIDEO_TS' -or -iname '*.iso'"
  37.     for ext in $video_ext; do
  38.         names="$names -or -iname '*.${ext}'"
  39.     done
  40.  
  41.     eval find "\"$dir\"" $names | wc -l
  42. }
  43.  
  44. remove_ext()
  45. {
  46.     basename "$1" | sed 's/^\(.*\)\..*$/\1/' | sed 's/_/ /g'
  47. }
  48.  
  49. xml_escape()
  50. {
  51.     echo "$1" | sed 's/&/\&/g'
  52. }
  53.  
  54. print_video()
  55. {
  56.     local file=$1
  57.     local label=`remove_ext "$file"`
  58.  
  59.     echo "<item label=\"`xml_escape "$label"`\">"
  60.     echo "  <action name=\"Execute\">"
  61.     echo "    <command>$player &quot;`xml_escape "$file"`&quot;</command>"
  62.     echo "  </action>"
  63.     echo "</item>"
  64. }
  65.  
  66. print_playlist()
  67. {
  68.     local files=$1
  69.  
  70.     echo "<item label=\"`xml_escape "$playlist_label"`\">"
  71.     echo "  <action name=\"Execute\">"
  72.     echo "    <command>$player `xml_escape "$files"`</command>"
  73.     echo "  </action>"
  74.     echo "</item>"
  75. }
  76.  
  77. print_dvd()
  78. {
  79.     local file=$1
  80.     if [ -d "$file" ]; then
  81.         local label=`basename "$file"`
  82.     else
  83.         local label=`remove_ext "$file"`
  84.     fi
  85.  
  86.     echo "<item label=\"`xml_escape "$label"`\">"
  87.     echo "  <action name=\"Execute\">"
  88.     echo "    <command>$player &quot;dvdnav:///`xml_escape "$file"`&quot;</command>"
  89.     echo "  </action>"
  90.     echo "</item>"
  91. }
  92.  
  93. print_dir()
  94. {
  95.     local dir=$1
  96.     local wrap_in_menu=$2
  97.  
  98.     if [ -d "$dir/VIDEO_TS" ]; then
  99.         print_dvd "$dir"
  100.         return 0
  101.     fi
  102.  
  103.     local basename=`basename "$dir"`
  104.     local items=`list_dir "$dir" | wc -l`
  105.     local pages=$(($items / $items_per_page))
  106.     if [ `expr $items % $items_per_page` = "0" ]; then
  107.         pages=$(($pages - 1))
  108.     fi
  109.     if [ $items -le 1 ]; then
  110.         wrap_in_menu="no"
  111.     fi
  112.  
  113.     if [ "$wrap_in_menu" != "no" ]; then
  114.         local menu_id=`echo "x$dir" | sed 's/\([^a-z0-9]\)//gI'`
  115.         echo "<menu id=\"$menu_id\" label=\"`xml_escape "$basename"`\">"
  116.     fi
  117.  
  118.     local item_count=0
  119.     local pages_count=0
  120.     local playlist=""
  121.     local playlist_count=0
  122.     list_dir "$dir" | while read item; do
  123.         if [ $item_count -gt 0 -a $(($item_count % $items_per_page)) -eq 0 ]; then
  124.             echo
  125.             echo "<menu id=\"${menu_id}More${pages_count}\" label=\"`xml_escape "$more_label"`\">"
  126.             pages_count=$(($pages_count + 1))
  127.         fi
  128.  
  129.         if [ -d "$item" ]; then
  130.             print_dir "$item"
  131.         elif [ `echo "$item" | grep '^.*\.iso$' | wc -l` -eq 1 ]; then
  132.             print_dvd "$item"
  133.         else
  134.             print_video "$item"
  135.             if [ $playlist_enable -eq 1 ]; then
  136.                 for ext in $video_ext; do
  137.                     if [ `echo "$item" | grep "^.*\\.${ext}\$" | wc -l` -eq 1 ]; then
  138.                         playlist="$playlist \"$item\""
  139.                         playlist_count=$(($playlist_count + 1))
  140.                         break
  141.                     fi
  142.                 done
  143.             fi
  144.         fi
  145.  
  146.         item_count=$(($item_count + 1))
  147.         if [ $playlist_enable -eq 1 -a $item_count -ge $items -a $playlist_count -ge $playlist_minimum ]; then
  148.             print_playlist "$playlist"
  149.         fi
  150.     done
  151.  
  152.     while [ "$pages" -gt 0 ]; do
  153.         echo "</menu>"
  154.         pages=$(($pages - 1))
  155.     done
  156.  
  157.     if [ "$wrap_in_menu" != "no" ]; then
  158.         echo "</menu>"
  159.     fi
  160. }
  161.  
  162. echo "<openbox_pipe_menu>"
  163. print_dir "$1" no
  164. echo "</openbox_pipe_menu>"
RAW Paste Data