コード例 #1
0
ファイル: dvr_rec.c プロジェクト: cloph/tvheadend
/**
 * Replace various chars with a dash
 */
static char *
cleanup_filename(char *s, dvr_config_t *cfg)
{
  int i, len = strlen(s), len2;
  char *s1;

  s1 = intlconv_utf8safestr(cfg->dvr_charset_id, s, len * 2);
  if (s1 == NULL) {
    tvherror("dvr", "Unsupported charset %s using ASCII", cfg->dvr_charset);
    s1 = intlconv_utf8safestr(intlconv_charset_id("ASCII", 1, 1),
                             s, len * 2);
    if (s1 == NULL)
      return NULL;
  }
  s = s1;

  /* Do not create hidden files */
  if (s[0] == '.')
    s[0] = '_';

  len2 = strlen(s);
  for (i = 0; i < len2; i++) {

    if(s[i] == '/')
      s[i] = '-';

    else if(cfg->dvr_whitespace_in_title &&
            (s[i] == ' ' || s[i] == '\t'))
      s[i] = '-';	

    else if(cfg->dvr_clean_title &&
            ((s[i] < 32) || (s[i] > 122) ||
             (strchr("/:\\<>|*?'\"", s[i]) != NULL)))
      s[i] = '_';
    else if(cfg->dvr_windows_compatible_filenames &&
             (strchr("/:\\<>|*?'\"", s[i]) != NULL))
      s[i] = '_';
  }

  if(cfg->dvr_windows_compatible_filenames) {
    // trim trailing spaces and dots
    for (i = len2 - 1; i >= 0; i--) {
      if((s[i] != ' ') && (s[i] != '.'))
        break;
      s[i] = '\0';
    }
  }

  return s;
}
コード例 #2
0
ファイル: dvr_rec.c プロジェクト: JPP1/tvheadend
/**
 * Replace various chars with a dash
 */
static char *
cleanup_filename(char *s, dvr_config_t *cfg)
{
  int i, len = strlen(s);
  char *s1;

  s1 = intlconv_utf8safestr(cfg->dvr_charset_id, s, len * 2);
  if (s1 == NULL) {
    tvherror("dvr", "Unsupported charset %s using ASCII", cfg->dvr_charset);
    s1 = intlconv_utf8safestr(intlconv_charset_id("ASCII", 1, 1),
                             s, len * 2);
    if (s1 == NULL)
      return NULL;
  }
  s = s1;

  /* Do not create hidden files */
  if (s[0] == '.')
    s[0] = '_';

  for (i = 0, len = strlen(s); i < len; i++) {

    if(s[i] == '/')
      s[i] = '-';

    else if(cfg->dvr_whitespace_in_title &&
            (s[i] == ' ' || s[i] == '\t'))
      s[i] = '-';	

    else if(cfg->dvr_clean_title &&
            ((s[i] < 32) || (s[i] > 122) ||
             (strchr("/:\\<>|*?'\"", s[i]) != NULL)))
      s[i] = '_';
  }

  return s;
}
コード例 #3
0
ファイル: m3u.c プロジェクト: ProfYaffle/tvheadend
/*
 * Note: text in data pointer is not preserved (must be read/write)
 */
htsmsg_t *parse_m3u
  (char *data, const char *charset, const char *url)
{
  char *p, *x, *y;
  char *charset_id = intlconv_charset_id(charset, 0, 1);
  const char *multi_name;
  int delim;
  htsmsg_t *m = htsmsg_create_map();
  htsmsg_t *item = NULL, *l = NULL, *t, *key = NULL;
  char buf[512];

  while (*data && *data <= ' ') data++;
  p = data;
  data = until_eol(data);
  if (strncmp(p, "#EXTM3U", 7)) {
    htsmsg_add_msg(m, "items", htsmsg_create_list());
    return m;
  }
  while (*data) {
    if (strncmp(data, "#EXTINF:", 8) == 0) {
      if (item == NULL)
        item = htsmsg_create_map();
      data += 8;
      p = data;
      if (*data == '-') data++;
      while (*data >= '0' && *data <= '9') data++;
      delim = *data;
      *data = '\0';
      htsmsg_add_s64(item, "m3u-duration", strtoll(p, NULL, 10));
      *data = delim;
      while (*data > ' ' && *data != ',') data++;
      while (delim && delim != ',' && delim != '\n' && delim != '\r') {
        while (*data && *data <= ' ') data++;
        if (*data == '\0' || *data == ',') break;
        p = data++;
        while (*data && *data != ',' && *data != '=') data++;
        if (*data == '=') {
          *data = '\0';
          x = get_m3u_str(data + 1, &data, &delim);
          if (*p && *x) {
            y = intlconv_to_utf8safestr(charset_id, x, strlen(x)*2);
            htsmsg_add_str(item, p, y ?: ".invalid.charset.");
            free(y);
          }
          get_m3u_str_post(&data, delim);
        }
      }
      p = NULL;
      if (*data == ',') {
        delim = ',';
        data++;
      }
      if (delim == ',') {
        while (*data && *data <= ' ' && *data != '\n' && *data != '\r') data++;
        if (*data)
          p = data;
      }
      data = until_eol(data);
      if (p && *p) {
        y = intlconv_to_utf8safestr(charset_id, p, strlen(p)*2);
        htsmsg_add_str(item, "m3u-name", y ?: ".invalid.charset.");
        free(y);
      }