Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
stsaz committed Nov 23, 2024
1 parent 3307158 commit d45ded3
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions android/phiola/src/main/res/menu/list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@
<item android:id="@+id/action_list_sort"
android:title="@string/mlist_sort" />

<item android:id="@+id/action_list_sort_filesize"
android:title="@string/mlist_sort_filesize" />

<item android:id="@+id/action_list_sort_filedate"
android:title="@string/mlist_sort_filedate" />

<item android:id="@+id/action_list_shuffle"
android:title="@string/mlist_shuffle" />

<item android:id="@+id/action_list_convert"
android:title="@string/mlist_convert" />

Expand Down
3 changes: 2 additions & 1 deletion android/phiola/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
<string name="mlist_show_track">List: Show Current Track</string>
<string name="mlist_next_add">List: Add Current to Next</string>
<string name="mlist_trk_added">Added track to Playlist %d</string>
<string name="mlist_sort">List: Sort</string>
<string name="mlist_sort">List: Sort...</string>
<string name="mlist_sort_filename">List: Sort by File Path</string>
<string name="mlist_sort_filesize">List: Sort by File Size</string>
<string name="mlist_sort_filedate">List: Sort by File Date</string>
<string name="mlist_shuffle">List: Shuffle</string>
Expand Down
11 changes: 10 additions & 1 deletion src/format/detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum FILE_FORMAT {
FILE_MP4,
FILE_OGG,
FILE_PLS,
FILE_TS,
FILE_WAV,
FILE_WV,
FILE_ID3,
Expand All @@ -29,6 +30,7 @@ const char file_ext[][5] = {
"mp4",
"ogg",
"pls",
"ts",
"wav",
"wv",
"",
Expand All @@ -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];
Expand Down
5 changes: 5 additions & 0 deletions src/list/m3u-read.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/list/m3u.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <list/entry.h>
Expand Down
5 changes: 5 additions & 0 deletions src/net/hls.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions src/net/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d45ded3

Please sign in to comment.