diff --git a/android/phiola/src/main/java/com/github/stsaz/phiola/MainActivity.java b/android/phiola/src/main/java/com/github/stsaz/phiola/MainActivity.java index 5499b2f..516f206 100644 --- a/android/phiola/src/main/java/com/github/stsaz/phiola/MainActivity.java +++ b/android/phiola/src/main/java/com/github/stsaz/phiola/MainActivity.java @@ -216,16 +216,7 @@ private boolean list_menu_click(MenuItem item) { list_next_add_cur(); break; case R.id.action_list_sort: - queue.sort(Phiola.QU_SORT_FILENAME); break; - - case R.id.action_list_sort_filesize: - queue.sort(Phiola.QU_SORT_FILESIZE); break; - - case R.id.action_list_sort_filedate: - queue.sort(Phiola.QU_SORT_FILEDATE); break; - - case R.id.action_list_shuffle: - queue.sort(Phiola.QU_SORT_RANDOM); break; + sort_menu_show(); break; case R.id.action_list_convert: list_convert(); break; @@ -239,6 +230,19 @@ private boolean list_menu_click(MenuItem item) { return true; } + private void sort_menu_show() { + PopupMenu m = new PopupMenu(this, b.list); + m.setOnMenuItemClickListener((item) -> { + queue.sort(item.getItemId()); + return true; + }); + m.getMenu().add(0, Phiola.QU_SORT_FILENAME, 0, getString(R.string.mlist_sort_filename)); + m.getMenu().add(0, Phiola.QU_SORT_FILESIZE, 0, getString(R.string.mlist_sort_filesize)); + m.getMenu().add(0, Phiola.QU_SORT_FILEDATE, 0, getString(R.string.mlist_sort_filedate)); + m.getMenu().add(0, Phiola.QU_SORT_RANDOM, 0, getString(R.string.mlist_shuffle)); + m.show(); + } + private static final int REQUEST_PERM_READ_STORAGE = 1, REQUEST_PERM_RECORD = 2; diff --git a/android/phiola/src/main/res/menu/list.xml b/android/phiola/src/main/res/menu/list.xml index 4a1a5eb..27f4af0 100644 --- a/android/phiola/src/main/res/menu/list.xml +++ b/android/phiola/src/main/res/menu/list.xml @@ -32,15 +32,6 @@ - - - - - - diff --git a/android/phiola/src/main/res/values/strings.xml b/android/phiola/src/main/res/values/strings.xml index 4a2f1db..6b4ea55 100644 --- a/android/phiola/src/main/res/values/strings.xml +++ b/android/phiola/src/main/res/values/strings.xml @@ -38,7 +38,8 @@ List: Show Current Track List: Add Current to Next Added track to Playlist %d - List: Sort + List: Sort... + List: Sort by File Path List: Sort by File Size List: Sort by File Date List: Shuffle diff --git a/src/format/detector.h b/src/format/detector.h index f1456ca..67024ee 100644 --- a/src/format/detector.h +++ b/src/format/detector.h @@ -14,6 +14,7 @@ enum FILE_FORMAT { FILE_MP4, FILE_OGG, FILE_PLS, + FILE_TS, FILE_WAV, FILE_WV, FILE_ID3, @@ -29,6 +30,7 @@ const char file_ext[][5] = { "mp4", "ogg", "pls", + "ts", "wav", "wv", "", @@ -44,11 +46,18 @@ const char* file_ext_str(uint i) } /** Detect file format by first several bytes -len: >=12 Return enum FILE_FORMAT */ int file_format_detect(const void *data, ffsize len) { const ffbyte *d = data; + + if (len >= 189) { + // byte sync // 0x47 + if (d[0] == 0x47 + && d[188] == 0x47) + return FILE_TS; + } + if (len >= 12) { // byte id[4]; // "RIFF" // byte size[4]; diff --git a/src/list/m3u-read.h b/src/list/m3u-read.h index 14909f0..2e38da1 100644 --- a/src/list/m3u-read.h +++ b/src/list/m3u-read.h @@ -131,6 +131,11 @@ static int m3u_process(void *ctx, phi_track *t) break; case M3UREAD_URL: + if (!ffutf8_valid(val.ptr, val.len)) { + warnlog(t, "incorrect UTF-8 data in URL"); + continue; + } + ffstr_set2(&m->pls_ent.url, &val); if (0 != m3u_add(m, t)) return PHI_ERR; diff --git a/src/list/m3u.c b/src/list/m3u.c index c4e3f37..53889bf 100644 --- a/src/list/m3u.c +++ b/src/list/m3u.c @@ -5,6 +5,7 @@ extern const phi_core *core; static const phi_queue_if *queue; static const phi_meta_if *metaif; +#define errlog(t, ...) phi_errlog(core, NULL, t, __VA_ARGS__) #define warnlog(t, ...) phi_warnlog(core, NULL, t, __VA_ARGS__) #include diff --git a/src/net/hls.h b/src/net/hls.h index d0688c4..3789fd6 100644 --- a/src/net/hls.h +++ b/src/net/hls.h @@ -109,6 +109,11 @@ static int hls_q_update(struct httpcl *h, ffstr d) continue; } + if (!ffutf8_valid(ln.ptr, ln.len)) { + errlog(h->trk, "bad UTF-8 URL"); + return -1; + } + if (ffstr_irmatchcz(&ln, ".m3u8")) { // m3u8 inside m3u8: redirect to the first sublist diff --git a/src/net/http.c b/src/net/http.c index 5cedee2..e3286d8 100644 --- a/src/net/http.c +++ b/src/net/http.c @@ -137,11 +137,12 @@ int phi_hc_resp(void *ctx, struct phi_http_data *d) static const struct map_sz24_vptr ct_ext[] = { { "application/ogg", "ogg" }, { "application/x-mpegURL", "m3u" }, - { "audio/aac", "aac" }, - { "audio/aacp", "aac" }, - { "audio/mpeg", "mp3" }, - { "audio/ogg", "ogg" }, - { "video/MP2T", "ts" }, + { "audio/aac", "aac" }, + { "audio/aacp", "aac" }, + { "audio/mpeg", "mp3" }, + { "audio/ogg", "ogg" }, + { "audio/x-aac", "aac" }, + { "video/MP2T", "ts" }, }; h->trk->data_type = map_sz24_vptr_findstr(ct_ext, FF_COUNT(ct_ext), d->ct); // help format.detector in case it didn't detect format if (!h->trk->data_type