|
9 | 9 | from flask import Flask, render_template, send_from_directory, request, redirect, send_file |
10 | 10 |
|
11 | 11 | # Service Imports |
12 | | -from tiklocal.services import LibraryService, FavoriteService, RecommendService, IMAGE_EXTENSIONS |
| 12 | +from tiklocal.services import LibraryService, FavoriteService, RecommendService, IMAGE_EXTENSIONS, AUDIO_EXTENSIONS |
13 | 13 | from tiklocal.services.thumbnail import ThumbnailService |
14 | 14 | from tiklocal.services.metadata import ( |
15 | 15 | ImageMetadataStore, |
@@ -284,6 +284,11 @@ def tiktok(): |
284 | 284 | """Immersive Mixed Media Feed""" |
285 | 285 | return render_template('tiktok.html', menu='index') |
286 | 286 |
|
| 287 | + @app.route('/radio') |
| 288 | + def radio_view(): |
| 289 | + """Audio Radio Player""" |
| 290 | + return render_template('radio.html', menu='radio') |
| 291 | + |
287 | 292 | @app.route('/download') |
288 | 293 | def download_view(): |
289 | 294 | """URL Download Center""" |
@@ -519,6 +524,31 @@ def thumb_view(): |
519 | 524 |
|
520 | 525 |
|
521 | 526 | # --- API Routes --- |
| 527 | + @app.route('/api/radio/items') |
| 528 | + def api_radio_items(): |
| 529 | + offset = _read_int_arg('offset', 0, minimum=0) |
| 530 | + limit = _read_int_arg('limit', 200, minimum=1, maximum=500) |
| 531 | + audios = library_service.scan_audios() |
| 532 | + favorites = favorite_service.load() |
| 533 | + total = len(audios) |
| 534 | + page = audios[offset:offset + limit] |
| 535 | + items = [] |
| 536 | + for p in page: |
| 537 | + name = library_service.get_relative_path(p) |
| 538 | + items.append({ |
| 539 | + 'name': name, |
| 540 | + 'media_url': f'/media/{quote(name, safe="/")}', |
| 541 | + 'thumb_url': f'/thumb?uri={quote(name, safe="")}', |
| 542 | + 'title': p.stem, |
| 543 | + 'duration': None, |
| 544 | + 'is_favorite': name in favorites, |
| 545 | + }) |
| 546 | + return {'success': True, 'data': { |
| 547 | + 'items': items, |
| 548 | + 'total': total, |
| 549 | + 'has_more': offset + limit < total, |
| 550 | + }} |
| 551 | + |
522 | 552 | @app.route('/api/feed/mix') |
523 | 553 | def api_feed_mix(): |
524 | 554 | page = _read_int_arg('page', 1, minimum=1) |
|
0 commit comments