Merge pull request #4 from BafDyce/directory-listing-fixes
Directory listing fixes
This commit is contained in:
		@@ -2,3 +2,4 @@ opuslib==1.1.0
 | 
			
		||||
protobuf==3.1.0
 | 
			
		||||
flask
 | 
			
		||||
youtube-dl
 | 
			
		||||
python-magic
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
{% macro dirlisting(path='') -%}
 | 
			
		||||
{% macro dirlisting(dir, path='') -%}
 | 
			
		||||
    <ul>
 | 
			
		||||
    {% for subdirname in music_library.get_subdirs(path) %}
 | 
			
		||||
    {% for subdirname, subdirobj in dir.get_subdirs().items() %}
 | 
			
		||||
        {%- set subdirpath = path + subdirname + '/' %}
 | 
			
		||||
        <li class="directory">
 | 
			
		||||
            <span>{{ subdirname }}/ </span>
 | 
			
		||||
@@ -17,31 +17,24 @@
 | 
			
		||||
                <input type="submit" value="Download entire directory">
 | 
			
		||||
            </form>
 | 
			
		||||
        </li>
 | 
			
		||||
        {%- set subdirs = music_library.get_subdirs(subdirpath) %}
 | 
			
		||||
        {%- if subdirs %}
 | 
			
		||||
            {%- for subdir in subdirs %}
 | 
			
		||||
                {{- dirlisting(subdirpath) -}}
 | 
			
		||||
            {%- endfor %}
 | 
			
		||||
        {%- endif %}
 | 
			
		||||
        <ul>
 | 
			
		||||
            {%- set files = music_library.get_files(subdirpath) %}
 | 
			
		||||
            {%- if files %}
 | 
			
		||||
                {% for file in files %}
 | 
			
		||||
                <li class="file">
 | 
			
		||||
                    <form method="post" class="file file_add">
 | 
			
		||||
                        <input type="text" value="{{ subdirpath }}{{ file }}" name="add_file" hidden>
 | 
			
		||||
                        <input type="submit" value="Add">
 | 
			
		||||
                    </form>
 | 
			
		||||
                    <form action="./download" method="get"  class="file file_download">
 | 
			
		||||
                        <input type="text" value="{{ subdirpath }}{{ file }}" name="file" hidden>
 | 
			
		||||
                        <input type="submit" value="Download">
 | 
			
		||||
                         {{ file }}
 | 
			
		||||
                    </form>
 | 
			
		||||
                </li>
 | 
			
		||||
                {% endfor %}
 | 
			
		||||
            {%- endif %}
 | 
			
		||||
        </ul>
 | 
			
		||||
        {{- dirlisting(subdirobj, subdirpath) -}}
 | 
			
		||||
    {% endfor %}
 | 
			
		||||
        {%- set files = dir.get_files() %}
 | 
			
		||||
        {%- if files %}
 | 
			
		||||
            {% for file in files %}
 | 
			
		||||
            <li class="file">
 | 
			
		||||
                <form method="post" class="file file_add">
 | 
			
		||||
                    <input type="text" value="{{ subdirpath }}{{ file }}" name="add_file" hidden>
 | 
			
		||||
                    <input type="submit" value="Add">
 | 
			
		||||
                </form>
 | 
			
		||||
                <form action="./download" method="get"  class="file file_download">
 | 
			
		||||
                    <input type="text" value="{{ subdirpath }}{{ file }}" name="file" hidden>
 | 
			
		||||
                    <input type="submit" value="Download">
 | 
			
		||||
                     {{ file }}
 | 
			
		||||
                </form>
 | 
			
		||||
            </li>
 | 
			
		||||
            {% endfor %}
 | 
			
		||||
        {%- endif %}
 | 
			
		||||
    </ul>
 | 
			
		||||
{%- endmacro %}
 | 
			
		||||
 | 
			
		||||
@@ -101,7 +94,7 @@
 | 
			
		||||
        <input type="submit" value="Download entire music library">
 | 
			
		||||
    </form>
 | 
			
		||||
    <br />
 | 
			
		||||
    {{ dirlisting() }}
 | 
			
		||||
    {{ dirlisting(music_library) }}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
</div>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								util.py
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								util.py
									
									
									
									
									
								
							@@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
import configparser
 | 
			
		||||
import hashlib
 | 
			
		||||
import magic
 | 
			
		||||
import os
 | 
			
		||||
import variables as var
 | 
			
		||||
import zipfile
 | 
			
		||||
@@ -20,7 +21,11 @@ def get_recursive_filelist_sorted(path):
 | 
			
		||||
        for file in files:
 | 
			
		||||
            if file in __CONFIG.get('bot', 'ignored_files'):
 | 
			
		||||
                continue
 | 
			
		||||
            filelist.append(relroot + file)
 | 
			
		||||
 | 
			
		||||
            fullpath = os.path.join(path, relroot, file)
 | 
			
		||||
            mime = magic.from_file(fullpath, mime=True)
 | 
			
		||||
            if 'audio' in mime or 'audio' in magic.from_file(fullpath).lower() or 'video' in mime:
 | 
			
		||||
                filelist.append(relroot + file)
 | 
			
		||||
 | 
			
		||||
    filelist.sort()
 | 
			
		||||
    return filelist
 | 
			
		||||
@@ -84,6 +89,7 @@ class Dir(object):
 | 
			
		||||
            if subdir in self.subdirs:
 | 
			
		||||
                searchpath = '/'.join(path.split('/')[1::])
 | 
			
		||||
                subdirs = self.subdirs[subdir].get_subdirs(searchpath)
 | 
			
		||||
                subdirs = list(map(lambda subsubdir: os.path.join(subdir, subsubdir), subdirs))
 | 
			
		||||
        else:
 | 
			
		||||
            subdirs = self.subdirs
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user