* add more ducking command * fix current music command * provide more controls, like pause, resume, clear. * add more controls in the web interface * refactored and improved: 1. move get_music_tag_info to util, and 2. refined logic related to it. 3. now playlist will check for tag info thus update_music_tag_info is useless and was removed 4. add "add folder" feature to !file asked in #65, 5. fix bugs related to !file * truncate file list if too long * fixed several tiny bugs * fixed several tiny bugs continue * fixed several tiny bugs continue continue * fixed several tiny bugs continue**3 * fixed several tiny bugs continue**4 * added !filematch command to add files that match a regex pattern. * truncate long message * fix web interface delete file issue * refresh after delete file * add regex to listfile command * refactored command part, added partial match support for commands * organized * added random command * typo * typo * Fixed many bugs. * Added workaround for azlux/pymumble#44 to fix the memory leak. * changed logging style. * fixed bugs related to random and resume * fix now playing * fixed issue related to download * fixed issue related to download 2 * fixed thumbnail issue * fixed add url problem in web interface * REFACTORED, turned db.ini into sqlite3 database. * fixed remove song problem * fixed radio get title problem. auto download if tmp file is deleted * fixed current index not loaded from database * fixed: order of songs loaded from the database * fixed: some obscure bugs. beautified error of commands * added a workaround for TerryGeng/botamusique#1. * beautified * fixed: channel not loaded in the config * fixed: auto checked for updates * fixed: mysterious bug: sometimes "now playing" string cannot be properly displayed. The real reason is: do use <br />, do not use <br>. I tried hours to find out this. * chore: unified debug messages that refer to music items * feav: fetch ffmpeg stderr mentioned in #72, reformatted logs. * fix: async download not working * fix: async download not working, still * fix: async download not working, finished * feat: queue command: ▶current playing item◀ * feat: support more than one command prefix * chore: added some WARNINGs into default config file to avoid people to touch it. * refactor: packed all string contants into constants.py, just to avoid people messing it around. * refactor: required by azlux. Added a configuration.example.ini to keep people away from configuration.default.ini
		
			
				
	
	
		
			386 lines
		
	
	
		
			18 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			386 lines
		
	
	
		
			18 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
{% macro dirlisting(dir, path='') -%}
 | 
						|
<ul class="list-group">
 | 
						|
    {% for subdirname, subdirobj in dir.get_subdirs().items() %}
 | 
						|
    {%- set subdirpath = os.path.relpath(subdirobj.fullpath, music_library.fullpath) %}
 | 
						|
    {%- set subdirid = subdirpath.replace("/","-") %}
 | 
						|
    <li class="directory list-group-item list-group-item-primary">
 | 
						|
        <div class="btn-group" role="group">
 | 
						|
            <div class="btn-group" role="group">
 | 
						|
                <button type="button" class="btn btn-success btn-sm"
 | 
						|
                        onclick="request('/post', {add_folder : '{{ subdirpath }}'})">
 | 
						|
                    <i class="fa fa-plus" aria-hidden="true"></i>
 | 
						|
                </button>
 | 
						|
                <div class="btn-group" role="group">
 | 
						|
                    <button id="btnGroupDrop2" type="button" class="btn btn-success btn-sm dropdown-toggle btn-space" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></button>
 | 
						|
                    <div class="dropdown-menu" aria-labelledby="btnGroupDrop2" style="">
 | 
						|
                        <a class="dropdown-item"
 | 
						|
                           onclick="request('/post', {add_folder : '{{ subdirpath }}'})">
 | 
						|
                            <i class="fa fa-folder" aria-hidden="true"></i> Entire folder
 | 
						|
                        </a>
 | 
						|
                        <a class="dropdown-item"
 | 
						|
                           onclick="request('/post', {add_folder_recursively : '{{ subdirpath }}'})">
 | 
						|
                            <i class="fa fa-folder" aria-hidden="true"></i> Entire folder and sub-folders
 | 
						|
                        </a>
 | 
						|
                    </div>
 | 
						|
                </div>
 | 
						|
            </div>
 | 
						|
 | 
						|
        </div>
 | 
						|
 | 
						|
        <div class="btn-group lead"><div class="btn-space"><i class="fa fa-folder" aria-hidden="true"></i></div><a class="lead" data-toggle="collapse"
 | 
						|
                    data-target="#multiCollapse-{{ subdirid }}" aria-expanded="true"
 | 
						|
                    aria-controls="multiCollapse-{{ subdirid }}" href="#"> {{ subdirpath }}/</a>
 | 
						|
        </div>
 | 
						|
 | 
						|
        <div class="btn-group" style="float: right;">
 | 
						|
            <form action="./download" method="get" class="directory">
 | 
						|
                <input type="text" value="{{ subdirpath }}" name="directory" hidden>
 | 
						|
                <button type="submit" class="btn btn-primary btn-sm btn-space"><i class="fa fa-download" aria-hidden="true"></i></button>
 | 
						|
            </form>
 | 
						|
            <button type="submit" class="btn btn-danger btn-sm btn-space"
 | 
						|
                    onclick="request('/post', {delete_folder : '{{ subdirpath }}'}, true)">
 | 
						|
                <i class="fas fa-trash-alt"></i>
 | 
						|
            </button>
 | 
						|
        </div>
 | 
						|
    </li>
 | 
						|
    <div class="collapse multi-collapse" id="multiCollapse-{{ subdirid }}">
 | 
						|
        {{- dirlisting(subdirobj, subdirpath) -}}
 | 
						|
    </div>
 | 
						|
    {% endfor %}
 | 
						|
    {%- set files = dir.get_files() %}
 | 
						|
    {%- if files %}
 | 
						|
    {% for file in files %}
 | 
						|
    {% set filepath = os.path.relpath(os.path.join(dir.fullpath, file), music_library.fullpath) %}
 | 
						|
    <li class="file list-group-item">
 | 
						|
        <div class="btn-group" role="group">
 | 
						|
            <div class="btn-group" role="group">
 | 
						|
                <button type="button" class="btn btn-success btn-sm"
 | 
						|
                        onclick="request('/post', {add_file_bottom : '{{ filepath }}'})">
 | 
						|
                    <i class="fa fa-plus" aria-hidden="true"></i>
 | 
						|
                </button>
 | 
						|
                <div class="btn-group" role="group">
 | 
						|
                    <button id="btnGroupDrop2" type="button" class="btn btn-success btn-sm dropdown-toggle btn-space" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></button>
 | 
						|
                    <div class="dropdown-menu" aria-labelledby="btnGroupDrop2" style="">
 | 
						|
                        <a class="dropdown-item"
 | 
						|
                           onclick="request('/post', {add_file_bottom : '{{ filepath }}'})">
 | 
						|
                            <i class="fa fa-angle-down" aria-hidden="true"></i> To bottom of play list
 | 
						|
                        </a>
 | 
						|
                        <a class="dropdown-item"
 | 
						|
                           onclick="request('/post', {add_file_next : '{{ filepath }}'})">
 | 
						|
                            <i class="fa fa-angle-right" aria-hidden="true"></i> After current song
 | 
						|
                        </a>
 | 
						|
                    </div>
 | 
						|
                </div>
 | 
						|
            </div>
 | 
						|
 | 
						|
        </div>
 | 
						|
        <div class="btn-group lead"><div class="btn-space"><i class="fa fa-music" aria-hidden="true"></i></div> {{ filepath }}</div>
 | 
						|
 | 
						|
        <div class="btn-group" style="float: right;">
 | 
						|
            <form action="./download" method="get" class="file file_download">
 | 
						|
                <input type="text" value="{{ filepath }}" name="file" hidden>
 | 
						|
                <button type="submit" class="btn btn-primary btn-sm btn-space"><i class="fa fa-download" aria-hidden="true"></i></button>
 | 
						|
            </form>
 | 
						|
            <button type="submit" class="btn btn-danger btn-sm btn-space"
 | 
						|
                    onclick="request('/post', {delete_music_file : '{{ filepath }}'}, true)">
 | 
						|
                <i class="fas fa-trash-alt"></i>
 | 
						|
            </button>
 | 
						|
        </div>
 | 
						|
    </li>
 | 
						|
    {% endfor %}
 | 
						|
    {%- endif %}
 | 
						|
</ul>
 | 
						|
{%- endmacro %}
 | 
						|
 | 
						|
<!DOCTYPE html>
 | 
						|
 | 
						|
<head>
 | 
						|
    <meta charset="UTF-8">
 | 
						|
    <title>botamusique web interface</title>
 | 
						|
    <link rel="stylesheet" href="/static/css/bootstrap.min.css">
 | 
						|
    <link rel="stylesheet" href="/static/css/custom.css">
 | 
						|
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
 | 
						|
    <META HTTP-EQUIV="Expires" CONTENT="-1">
 | 
						|
</head>
 | 
						|
 | 
						|
<body>
 | 
						|
    <div class="container">
 | 
						|
        <div class="bs-docs-section">
 | 
						|
            <div class="page-header" id="banner">
 | 
						|
                <h1><i class="fa fa-music" aria-hidden="true"></i> botamusique Web Interface</h1>
 | 
						|
            </div>
 | 
						|
        </div>
 | 
						|
        <div class="bs-docs-section">
 | 
						|
            <div class="row">
 | 
						|
            <div class="col">
 | 
						|
                <div id="playlist" class="card">
 | 
						|
                    <div class="card-header">
 | 
						|
                        <h2 class="card-title"><i class="fa fa-list" aria-hidden="true"></i> Play List</h2>
 | 
						|
                    </div>
 | 
						|
 | 
						|
                    <div class="card-body">
 | 
						|
                        <div class="btn-group" style="margin-bottom: 5px;">
 | 
						|
                            <button type="button" class="btn btn-primary btn-space"
 | 
						|
                                    onclick="request('/post', {action : 'randomize'})">
 | 
						|
                                <i class="fas fa-random" aria-hidden="true"></i>
 | 
						|
                            </button>
 | 
						|
 | 
						|
                            <button type="button" id="play-btn" class="btn btn-info btn-space"
 | 
						|
                                    onclick="request('/post', {action : 'resume'})" disabled>
 | 
						|
                                <i class="fas fa-play" aria-hidden="true"></i>
 | 
						|
                            </button>
 | 
						|
 | 
						|
                            <button type="button" id="pause-btn" class="btn btn-warning btn-space"
 | 
						|
                                    onclick="request('/post', {action : 'pause'})" disabled>
 | 
						|
                                <i class="fas fa-pause" aria-hidden="true"></i>
 | 
						|
                            </button>
 | 
						|
 | 
						|
                            <button type="button" id="stop-btn" class="btn btn-danger btn-space"
 | 
						|
                                    onclick="request('/post', {action : 'stop'})" disabled>
 | 
						|
                                <i class="fas fa-stop" aria-hidden="true"></i>
 | 
						|
                            </button>
 | 
						|
                        </div>
 | 
						|
 | 
						|
                        <div class="btn-group" style="float: right;">
 | 
						|
                            <button type="button" class="btn btn-warning btn-space"
 | 
						|
                                    onclick="request('/post', {action : 'volume_down'})">
 | 
						|
                                <i class="fa fa-volume-down" aria-hidden="true"></i>
 | 
						|
                            </button>
 | 
						|
                            <button type="button" class="btn btn-warning btn-space"
 | 
						|
                                    onclick="request('/post', {action : 'volume_up'})">
 | 
						|
                                <i class="fa fa-volume-up" aria-hidden="true"></i>
 | 
						|
                            </button>
 | 
						|
                        </div>
 | 
						|
 | 
						|
                        <table class="table">
 | 
						|
                            <thead>
 | 
						|
                                <tr>
 | 
						|
                                    <th scope="col">#</th>
 | 
						|
                                    <th scope="col">Title</th>
 | 
						|
                                    <th scope="col">Url/Path</th>
 | 
						|
                                    <th scope="col">Action</th>
 | 
						|
                                </tr>
 | 
						|
                            </thead>
 | 
						|
                            <tbody id="playlist-table">
 | 
						|
                                <tr class="table-dark">
 | 
						|
                                <td colspan="4" class="text-muted" style="text-align:center;"> Fetching playlist .... </td>
 | 
						|
                                </tr>
 | 
						|
                            </tbody>
 | 
						|
                        </table>
 | 
						|
 | 
						|
                        <div class="btn-group">
 | 
						|
                            <button type="button" class="btn btn-danger btn-space"
 | 
						|
                                    onclick="request('/post', {action : 'clear'})">
 | 
						|
                                <i class="fas fa-trash-alt" aria-hidden="true"></i> Clear Playlist
 | 
						|
                            </button>
 | 
						|
                        </div>
 | 
						|
                    </div>
 | 
						|
                </div>
 | 
						|
            </div>
 | 
						|
        </div>
 | 
						|
        </div>
 | 
						|
 | 
						|
        <div class="bs-docs-section">
 | 
						|
            <div class="row">
 | 
						|
            <div class="col">
 | 
						|
                <div id="browser" class="card">
 | 
						|
                    <div class="card-header">
 | 
						|
                        <h2 class="card-title"><i class="fa fa-list" aria-hidden="true"></i> Music Library</h2>
 | 
						|
                    </div>
 | 
						|
 | 
						|
                    <div class="card-body">
 | 
						|
                        <div class="btn-group" style="margin-bottom: 5px;" role="group">
 | 
						|
                            <form action="./download" method="get" class="directory form1">
 | 
						|
                                <input type="text" value="./" name="directory" hidden>
 | 
						|
                                <button type="submit" class="btn btn-secondary btn-space"><i class="fa fa-download" aria-hidden="true"></i> Download All</button>
 | 
						|
                            </form>
 | 
						|
                            <form method="post" class="directory form3">
 | 
						|
                                <input type="text" value="./" name="add_folder_recursively" hidden>
 | 
						|
                                <button type="submit" class="btn btn-secondary btn-space"><i class="fa fa-plus" aria-hidden="true"></i> Add All</button>
 | 
						|
                            </form>
 | 
						|
                        </div>
 | 
						|
                        <br />
 | 
						|
                        {{ dirlisting(music_library) }}
 | 
						|
                    </div>
 | 
						|
                </div>
 | 
						|
            </div>
 | 
						|
        </div>
 | 
						|
        </div>
 | 
						|
    </div>
 | 
						|
 | 
						|
    <div id="upload" class="container">
 | 
						|
        <div class="bs-docs-section">
 | 
						|
            <div class="row">
 | 
						|
            <div class="col">
 | 
						|
                <div class="card">
 | 
						|
                    <div class="card-header">
 | 
						|
                        <h5 class="card-title">Upload File</h5>
 | 
						|
                    </div>
 | 
						|
                    <div class="card-body">
 | 
						|
                        <form action="./upload" method="post" enctype="multipart/form-data">
 | 
						|
                            <div class="row" style="margin-bottom: 5px;">
 | 
						|
                                <div id="uploadBox" class="col-lg-7 input-group">
 | 
						|
                                    <div id="uploadField" style="display: flex; width: 100%">
 | 
						|
                                        <div class="custom-file btn-space">
 | 
						|
                                            <input type="file" name="file[]" class="custom-file-input" id="uploadSelectFile"
 | 
						|
                                                   aria-describedby="uploadSubmit" value="Browse Music file" multiple/>
 | 
						|
                                            <label class="custom-file-label" for="uploadSelectFile">Choose file</label>
 | 
						|
                                        </div>
 | 
						|
                                    </div>
 | 
						|
                                </div>
 | 
						|
                                <div class="col-lg-4 input-group-append">
 | 
						|
                                    <span class="input-group-text">Upload To</span>
 | 
						|
                                    <input class="form-control btn-space" list="targetdirs" id="targetdir" name="targetdir"
 | 
						|
                                           placeholder="uploads" />
 | 
						|
                                    <datalist id="targetdirs">
 | 
						|
                                        <option value="uploads">
 | 
						|
                                            {% for dir in music_library.get_subdirs_recursively() %}
 | 
						|
                                                <option value="{{ dir }}">
 | 
						|
                                            {% endfor %}
 | 
						|
                                    </datalist>
 | 
						|
                                </div>
 | 
						|
                                <button class="btn btn-primary btn-space" type="submit"
 | 
						|
                                        id="uploadSubmit" style="margin-left: -5px;">Upload!</button>
 | 
						|
                            </div>
 | 
						|
                        </form>
 | 
						|
                    </div>
 | 
						|
                </div>
 | 
						|
            </div>
 | 
						|
        </div>
 | 
						|
        </div>
 | 
						|
 | 
						|
        <div class="bs-docs-section" style="margin-bottom: 150px;">
 | 
						|
            <div class="row">
 | 
						|
            <div class="col">
 | 
						|
                <div class="card">
 | 
						|
                    <div class="card-header">
 | 
						|
                        <h5 class="card-title">Add URL</h5>
 | 
						|
                    </div>
 | 
						|
                    <div class="card-body">
 | 
						|
                        <label>Add Youtube/Soundcloud URL</label>
 | 
						|
                        <div class="input-group">
 | 
						|
                            <input class="form-control btn-space" type="text" id="add_url_input" placeholder="URL...">
 | 
						|
                            <button type="submit" class="btn btn-primary"
 | 
						|
                            onclick="request('/post', {add_url :  $('#add_url_input')[0].value })">Add URL</button>
 | 
						|
                        </div>
 | 
						|
                    </div>
 | 
						|
                </div>
 | 
						|
            </div>
 | 
						|
            <div class="col">
 | 
						|
                <div class="card">
 | 
						|
                    <div class="card-header">
 | 
						|
                        <h5 class="card-title">Add Radio</h5>
 | 
						|
                    </div>
 | 
						|
                    <div class="card-body">
 | 
						|
                        <label>Add Radio URL</label>
 | 
						|
                        <div class="input-group">
 | 
						|
                            <input class="form-control btn-space" type="text" id="add_radio_input" placeholder="Radio Address...">
 | 
						|
                            <button type="submit" class="btn btn-primary"
 | 
						|
                            onclick="request('/post', {add_radio : $('#add_radio_input')[0].value })">Add Radio</button>
 | 
						|
                        </div>
 | 
						|
                    </div>
 | 
						|
                </div>
 | 
						|
            </div>
 | 
						|
        </div>
 | 
						|
        </div>
 | 
						|
    </div>
 | 
						|
 | 
						|
    <script src="/static/js/jquery-3.4.1.min.js" crossorigin="anonymous"></script>
 | 
						|
    <script src="/static/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
 | 
						|
    <script src="/static/js/fontawesome.all.js" crossorigin="anonymous"></script>
 | 
						|
 | 
						|
    <script>
 | 
						|
        $('#uploadSelectFile').on('change', function () {
 | 
						|
            //get the file name
 | 
						|
            var fileName = $(this).val().replace('C:\\fakepath\\', " ");
 | 
						|
            //replace the "Choose a file" label
 | 
						|
            $(this).next('.custom-file-label').html(fileName);
 | 
						|
        });
 | 
						|
        $('a.a-submit, button.btn-submit').on('click', function (event) {
 | 
						|
            $(event.target).closest('form').submit();
 | 
						|
        });
 | 
						|
 | 
						|
        var playlist_ver = 0;
 | 
						|
 | 
						|
        function request(url, _data, refresh=false){
 | 
						|
            $.ajax({
 | 
						|
                type: 'POST',
 | 
						|
                url: '/post',
 | 
						|
                data : _data,
 | 
						|
                statusCode : {
 | 
						|
                    200 : function(data) {
 | 
						|
                        if (data.ver !== playlist_ver) {
 | 
						|
                            updatePlaylist();
 | 
						|
                            playlist_ver = data.ver;
 | 
						|
                        }
 | 
						|
                        updateControls(data.empty, data.play);
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            });
 | 
						|
            if(refresh){
 | 
						|
                location.reload()
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        function displayPlaylist(data){
 | 
						|
            // console.info(data);
 | 
						|
            $("#playlist-table tr").remove();
 | 
						|
 | 
						|
            var items = data.items;
 | 
						|
            $.each(items, function(index, item){
 | 
						|
                $("#playlist-table").append(item);
 | 
						|
            });
 | 
						|
 | 
						|
        }
 | 
						|
 | 
						|
        function updatePlaylist(){
 | 
						|
            $.ajax({
 | 
						|
                type: 'GET',
 | 
						|
                url: '/playlist',
 | 
						|
                statusCode : {
 | 
						|
                    200 : displayPlaylist
 | 
						|
                }
 | 
						|
            });
 | 
						|
        }
 | 
						|
 | 
						|
        function updateControls(empty, play){
 | 
						|
            if(empty){
 | 
						|
                $("#play-btn").prop("disabled", true);
 | 
						|
                $("#pause-btn").prop("disabled", true);
 | 
						|
                $("#stop-btn").prop("disabled", true);
 | 
						|
            }else{
 | 
						|
                if(play){
 | 
						|
                    $("#play-btn").prop("disabled", true);
 | 
						|
                    $("#pause-btn").prop("disabled", false);
 | 
						|
                    $("#stop-btn").prop("disabled", false);
 | 
						|
                }else{
 | 
						|
                    $("#play-btn").prop("disabled", false);
 | 
						|
                    $("#pause-btn").prop("disabled", true);
 | 
						|
                    $("#stop-btn").prop("disabled", true);
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        // Check the version of playlist to see if update is needed.
 | 
						|
        setInterval(function(){
 | 
						|
            $.ajax({
 | 
						|
                type: 'POST',
 | 
						|
                url : '/post',
 | 
						|
                statusCode : {
 | 
						|
                    200 : function(data){
 | 
						|
                        if(data.ver !== playlist_ver){
 | 
						|
                            updatePlaylist();
 | 
						|
                            playlist_ver = data.ver;
 | 
						|
                        }
 | 
						|
                        updateControls(data.empty, data.play);
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            });
 | 
						|
        } , 3000);
 | 
						|
 | 
						|
        $(document).ready(updatePlaylist);
 | 
						|
 | 
						|
    </script>
 | 
						|
</body>
 | 
						|
 | 
						|
</html> |