Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
lilkidsuave authored Jun 27, 2024
1 parent 995b74a commit 051d9df
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 128 deletions.
37 changes: 7 additions & 30 deletions qbdl_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
encryption_key = os.environ.get('ENCRYPTION_KEY') or Fernet.generate_key()
fernet = Fernet(encryption_key)

qobuz_dl = None # Initialize QobuzDL instance globally

def encrypt_password(password):
return fernet.encrypt(password.encode()).decode()

Expand All @@ -23,29 +21,22 @@ def decrypt_password(encrypted_password):

@app.route('/', methods=['GET', 'POST'])
def index():
global qobuz_dl

if request.method == 'POST':
email = request.form['email']
password = request.form['password']
url = request.form['url']
download_location = request.form['download_location']
quality = int(request.form['quality'])
remember = request.form.get('rememberMe')
search_type = request.form.get('searchType') # Get search type from form

try:
qobuz_dl = QobuzDL(
qobuz = QobuzDL(
directory=download_location,
quality=quality
)
qobuz_dl.get_tokens()
qobuz_dl.initialize_client(email, password, qobuz_dl.app_id, qobuz_dl.secrets)
# Handle search based on type
results = qobuz_dl.search_by_type(url, search_type, limit=10)
return render_template('index.html', email=email, password=password,
download_location=download_location, quality=quality,
search_results=results)
qobuz.get_tokens()
qobuz.initialize_client(email, password, qobuz.app_id, qobuz.secrets)
qobuz.handle_url(url)
except Exception as e:
logging.error("An error occurred: " + str(e))
return jsonify(status='error', message='An internal error occurred. Please try again later.'), 500
Expand All @@ -66,20 +57,6 @@ def index():

return render_template('index.html', email=email, password=password, download_location=download_location, quality=quality)

# Route to handle AJAX search requests
@app.route('/search', methods=['GET'])
def search():
global qobuz_dl

query = request.args.get('query')
search_type = request.args.get('searchType')

if query and search_type and qobuz_dl:
try:
results = qobuz_dl.search_by_type(query, search_type, limit=10)
return jsonify(results)
except Exception as e:
logging.error(f"An error occurred during search: {str(e)}")
return jsonify([]) # Return empty list on error

return jsonify([]) # Return empty list if no query or search type provided
#if __name__ == '__main__':
#from werkzeug.serving import run_simple
#run_simple('0.0.0.0', 5000, app)
131 changes: 33 additions & 98 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ <h2 class="mb-4">QobuzDlGui-Reborn</h2>
<input type="checkbox" class="form-check-input" name="rememberMe" id="rememberMe">
<label class="form-check-label" for="rememberMe">Remember me and settings</label>
</div>
<div class="form-group">
<label for="searchType">Search Type:</label>
<select class="form-control" name="searchType" id="searchType" required>
<option value="album">Album</option>
<option value="artist">Artist</option>
<option value="track">Track</option>
<option value="playlist">Playlist</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Download</button>
</form>
<div id="progress-container" style="display: none;">
Expand All @@ -62,104 +53,48 @@ <h4>Downloading...</h4>
</div>
<p id="status-text">Starting download...</p>
</div>

<div id="search-results" style="margin-top: 20px;">
<!-- Search results will be displayed here -->
</div>


<script>
$('#downloadForm').submit(function (e) {
e.preventDefault();
$('#progress-container').show();
$('#downloadForm').submit(function(e) {
e.preventDefault();
$('#progress-container').show();

$.ajax({
type: 'POST',
url: '/',
data: $(this).serialize(),
success: function(data) {
if (data.status === 'completed') {
$('#progress-bar').css('width', '100%');
$('#status-text').text('Download Completed!');

$.ajax({
type: 'POST',
url: '/',
data: $(this).serialize(),
success: function (data) {
if (data.status === 'completed') {
$('#progress-bar').css('width', '100%');
$('#status-text').text('Download Completed!');

// Reload the page after 1 second
setTimeout(function () {
location.reload();
}, 1000);
}
},
error: function (jqXHR, textStatus, errorThrown) {
$('#status-text').text('An error occurred: ' + jqXHR.responseJSON.message);
},
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
percentComplete = parseInt(percentComplete * 100);
$('#progress-bar').css('width', percentComplete + '%');
}
}, false);
return xhr;
// Reload the page after 1 second
setTimeout(function() {
location.reload();
}, 1000);
}
});
});

// AJAX search function
$('#searchType').change(function () {
performSearch();
});

$('#url').on('input', function () {
performSearch();
});

function performSearch() {
var query = $('#url').val();
var searchType = $('#searchType').val();

if (query.length >= 3) {
$.ajax({
url: '/search',
type: 'GET',
data: {
query: query,
searchType: searchType
},
success: function (data) {
displaySearchResults(data);
},
error: function (jqXHR, textStatus, errorThrown) {
console.error('Error performing search:', errorThrown);
},
error: function(jqXHR, textStatus, errorThrown) {
$('#status-text').text('An error occurred: ' + jqXHR.responseJSON.message);
},
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
percentComplete = parseInt(percentComplete * 100);
$('#progress-bar').css('width', percentComplete + '%');
}
});
} else {
$('#search-results').empty();
}
}

function displaySearchResults(results) {
$('#search-results').empty();

if (results.length > 0) {
var ul = $('<ul class="list-group"></ul>');

results.forEach(function (item) {
var li = $('<li class="list-group-item"></li>');
var link = $('<a href="' + item.url + '" target="_blank">' + item.text + '</a>');
li.append(link);
ul.append(li);
});

$('#search-results').append(ul);
} else {
$('#search-results').append('<p>No results found.</p>');
}, false);
return xhr;
}
}
});
});
</script>
<div class="footer">
<p>QoBuzDlGui-Reborn &copy; Gyarbij and LilKidSuave 2023-2024</p>
</div>
</div>
</div>
</body>

</html>

0 comments on commit 051d9df

Please sign in to comment.