]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
http playlist: add possibility to sort by name only
authorJaroslav Kysela <perex@perex.cz>
Thu, 27 Apr 2017 12:01:07 +0000 (14:01 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 27 Apr 2017 12:01:07 +0000 (14:01 +0200)
docs/markdown/url.md
src/webui/webui.c

index 6a75e05f028698eafd96ce1ce9e341a844d32377..9265ce9f4bdf5986390194f9eb1a02ec165d1971 100644 (file)
@@ -43,6 +43,15 @@ dvrid         | One DVR record specified by short DVR ID
 Option   | Explanation
 ---------|------------------------------------------------------------------------------
 profile  | Override streaming profile, otherwise the default profile for the user is used.
+sort     | Sorting method
+
+Sorting method | Scope    | Description
+---------------|----------|-----------------------------------------------------------
+numname        | channel  | Channel number as first key, channel name as second key
+name           | channel  | Channel name only
+idxname        | tag      | Tag index as first key, tag name as second key
+name           | tag      | Tag name only
+
 
 ### /stream/WHAT/IDENTIFIER
 
index 0bac6cf37592fdfeb214c801f71b46cd135f6824..15fed7df8bcd0804be04ad95714d42c139972026 100644 (file)
@@ -64,6 +64,8 @@
 #define MIME_M3U "audio/x-mpegurl"
 #define MIME_E2 "application/x-e2-bouquet"
 
+typedef int (sortfcn_t)(const void *, const void *);
+
 enum {
   PLAYLIST_M3U,
   PLAYLIST_E2,
@@ -90,6 +92,25 @@ http_channel_playlist_cmp(const void *a, const void *b)
   return r;
 }
 
+static int
+http_channel_playlist_cmp2(const void *a, const void *b)
+{
+  channel_t *c1 = *(channel_t **)a, *c2 = *(channel_t **)b;
+  return strcasecmp(channel_get_name(c1), channel_get_name(c2));
+}
+
+static sortfcn_t *http_channel_playlist_sfcn(http_connection_t *hc)
+{
+  const char *sorttype = http_arg_get(&hc->hc_req_args, "sort");
+  if (sorttype) {
+    if (!strcmp(sorttype, "numname"))
+      return &http_channel_playlist_cmp;
+    if (!strcmp(sorttype, "name"))
+      return &http_channel_playlist_cmp2;
+  }
+  return &http_channel_playlist_cmp;
+}
+
 /*
  *
  */
@@ -103,6 +124,25 @@ http_channel_tag_playlist_cmp(const void *a, const void *b)
   return r;
 }
 
+static int
+http_channel_tag_playlist_cmp2(const void *a, const void *b)
+{
+  channel_tag_t *ct1 = *(channel_tag_t **)a, *ct2 = *(channel_tag_t **)b;
+  return strcasecmp(ct1->ct_name, ct2->ct_name);
+}
+
+static sortfcn_t *http_channel_tag_playlist_sfcn(http_connection_t *hc)
+{
+  const char *sorttype = http_arg_get(&hc->hc_req_args, "sort");
+  if (sorttype) {
+    if (!strcmp(sorttype, "idxname"))
+      return &http_channel_tag_playlist_cmp;
+    if (!strcmp(sorttype, "name"))
+      return &http_channel_tag_playlist_cmp2;
+  }
+  return &http_channel_tag_playlist_cmp;
+}
+
 /**
  *
  */
@@ -666,7 +706,7 @@ http_tag_playlist(http_connection_t *hc, int pltype, channel_tag_t *tag)
 
   assert(idx == count);
 
-  qsort(chlist, count, sizeof(channel_t *), http_channel_playlist_cmp);
+  qsort(chlist, count, sizeof(channel_t *), http_channel_playlist_sfcn(hc));
 
   if (pltype == PLAYLIST_M3U)
     htsbuf_append_str(hq, "#EXTM3U\n");
@@ -724,6 +764,7 @@ http_tag_list_playlist(http_connection_t *hc, int pltype)
   hq = &hc->hc_reply;
 
   profile = profile_validate_name(http_arg_get(&hc->hc_req_args, "profile"));
+
   hostpath = http_get_hostpath(hc);
 
   TAILQ_FOREACH(ct, &channel_tags, ct_link)
@@ -738,7 +779,7 @@ http_tag_list_playlist(http_connection_t *hc, int pltype)
 
   assert(idx == count);
 
-  qsort(ctlist, count, sizeof(channel_tag_t *), http_channel_tag_playlist_cmp);
+  qsort(ctlist, count, sizeof(channel_tag_t *), http_channel_tag_playlist_sfcn(hc));
 
   if (pltype == PLAYLIST_E2 || pltype == PLAYLIST_SATIP_M3U) {
     CHANNEL_FOREACH(ch)
@@ -753,7 +794,7 @@ http_tag_list_playlist(http_connection_t *hc, int pltype)
 
     assert(chidx == chcount);
 
-    qsort(chlist, chcount, sizeof(channel_t *), http_channel_playlist_cmp);
+    qsort(chlist, chcount, sizeof(channel_t *), http_channel_playlist_sfcn(hc));
   } else {
     chlist = NULL;
   }
@@ -832,7 +873,7 @@ http_channel_list_playlist(http_connection_t *hc, int pltype)
 
   assert(idx == count);
 
-  qsort(chlist, count, sizeof(channel_t *), http_channel_playlist_cmp);
+  qsort(chlist, count, sizeof(channel_t *), http_channel_playlist_sfcn(hc));
 
   htsbuf_append_str(hq, pltype == PLAYLIST_E2 ? "#NAME Tvheadend Channels\n" : "#EXTM3U\n");
   for (idx = 0; idx < count; idx++) {