コード例 #1
0
static gboolean
ol_player_amarok1_get_music_info (OlMusicInfo *info)
{
  ol_assert_ret (info != NULL, FALSE);
  ol_music_info_clear (info);
  if (!ol_player_amarok1_get_string (TITLE_CMD, &info->title))
    return FALSE;
  if (!ol_player_amarok1_get_string (ARTIST_CMD, &info->artist))
    return FALSE;
  if (!ol_player_amarok1_get_string (ALBUM_CMD, &info->album))
    return FALSE;
  if (!ol_player_amarok1_get_uint (TRACK_CMD, &info->track_number))
    return FALSE;
  ol_debugf ("  title: %s\n"
             "  artist: %s\n"
             "  album: %s\n",
             ol_music_info_get_title (info),
             ol_music_info_get_artist (info),
             ol_music_info_get_album (info));
  return TRUE;
}
コード例 #2
0
ファイル: ol_lrclib.c プロジェクト: thnt/osdlyrics
int
ol_lrclib_assign_lyric (const OlMusicInfo *info,
                        const char *lrcpath)
{
    ol_log_func ();
    static char title_value[FIELD_BUFLEN] = "";
    static char artist_value[FIELD_BUFLEN] = "";
    static char album_value[FIELD_BUFLEN] = "";
    static char uri_value[FIELD_BUFLEN] = "";
    static char lrcpath_value[FIELD_BUFLEN] = "";
    static char where[FIELD_BUFLEN] = "";
    static char query[QUERY_BUFLEN] = "";
    if (db == NULL)
    {
        ol_error ("LrcLib is no initialized.");
        return 0;
    }
    ol_assert_ret (info != NULL, 0);
    if (ol_music_info_get_title (info) == NULL &&
            ol_music_info_get_uri (info) == NULL)
    {
        ol_error ("Require either title or uri be set.");
        return 0;
    }

    _copy_str (lrcpath_value, lrcpath, FIELD_BUFLEN);
    char *oldpath = NULL;
    int find_ret = -1;
    if (info->uri != NULL || (find_ret = ol_lrclib_find (info, &oldpath)) == 0)
    {
        _copy_str (title_value, info->title, FIELD_BUFLEN);
        _copy_str (artist_value, info->artist, FIELD_BUFLEN);
        _copy_str (album_value, info->album, FIELD_BUFLEN);
        _copy_str (uri_value, info->uri, FIELD_BUFLEN);
        snprintf (query, QUERY_BUFLEN, ASSIGN_LYRIC,
                  title_value, artist_value, album_value, info->track_number,
                  uri_value, lrcpath_value);
        ol_debugf ("query: %s\n", query);
        int code = sqlite3_exec (db, query, NULL, NULL, &errmsg);
        if (code != SQLITE_OK)
        {
            ol_errorf ("Assign Lyric Failed: %s\n", errmsg);
            sqlite3_free (errmsg);
        }
        return code == SQLITE_OK;
    }
    else
    {
        if (oldpath != NULL) g_free (oldpath);
        int retval = _set_where_with_info (info, where, FIELD_BUFLEN);
        if (retval == -1)
            return 0;
        snprintf (query, QUERY_BUFLEN, UPDATE_LYRIC, lrcpath_value, where);
        ol_debugf ("update query: %s\n", query);
        int code = sqlite3_exec (db, query, NULL, NULL, &errmsg);
        if (code != SQLITE_OK)
        {
            ol_errorf ("Update Lyric Failed %s\n", errmsg);
            sqlite3_free (errmsg);
        }
        return code == SQLITE_OK;
    }
}
コード例 #3
0
ファイル: ol_lrc_fetch_xiami.c プロジェクト: gxcast/osdlyrics
static OlLrcCandidate *
ol_lrc_fetch_xiami_search(const OlMusicInfo *info, int *size, const char* charset)
{
  ol_assert_ret (info != NULL, NULL);
  ol_debugf ("  title: %s\n"
             "  artist: %s\n"
             "  album: %s\n",
             info->title,
             info->artist,
             info->album);
  OlLrcCandidate *ret = NULL;
  static OlLrcCandidate candidate_list[TRY_MATCH_MAX];
  OlLrcCandidate candidate;
  int result;
  int count = 0;
  if (info->title == NULL && info->artist == NULL)
    return NULL;

  GString *url = g_string_new (PREFIX_SEARCH_URL);
  if (ol_music_info_get_title (info) != NULL)
    g_string_append_uri_escaped (url,
                                 ol_music_info_get_title (info),
                                 NULL,
                                 FALSE);
  if (ol_music_info_get_artist (info) != NULL)
  {
    g_string_append_c (url, '+');
    g_string_append_uri_escaped (url,
                                 ol_music_info_get_artist (info),
                                 NULL,
                                 FALSE);
  }

  char *search_url = g_string_free (url, FALSE);
  ol_debugf ("Search url: %s\n", search_url);

  struct memo content;
  content.mem_base = NULL;
  content.mem_len = 0;

  if((result = fetch_into_memory(search_url,
                                 NULL, /* refer */
                                 NULL, /* user-agent */
                                 NULL, /* postdata */
                                 0,    /* postdata len */
                                 &content)) >= 0)
  {
    char *current = (char*)content.mem_base;
    char *p;
    while ((p = strstr (current, TITLE_PATTERN)) != NULL)
    {
      current = p + strlen (TITLE_PATTERN);
      if (!isdigit(*current))
        continue;
      p = strchr (current, '\"');
      if (p == NULL)
        break;
      *p = '\0';
      ol_debugf ("url id: %s\n", current);
      char *id = g_strdup (current);
      current = p + 1;
      char *title = _get_title_attr (current, &current);
      if (title == NULL)
        break;
      ol_lrc_candidate_set_title (&candidate, title);
      ol_debugf ("title: %s\n", title);
      g_free (title);
      p = strstr (current, ARTIST_PATTERN);
      if (p != NULL)
      {
        char *artist = _get_title_attr (p, &current);
        if (artist != NULL)
        {
          ol_lrc_candidate_set_artist (&candidate, artist);
          ol_debugf ("artist: %s\n", artist);
          g_free (artist);
        }
      }

      if (ol_lrc_fetch_calc_rank (info, &candidate) >= LRC_RANK_THRESHOLD)
      {
        char *url = _get_lyric_url (id);
        ol_debugf ("lyric url: %s\n", url);
        if (url != NULL)
        {
          ol_lrc_candidate_set_url (&candidate, url);
          count = ol_lrc_fetch_add_candidate (info,
                                              candidate_list,
                                              count,
                                              TRY_MATCH_MAX,
                                              &candidate);
          g_free (url);
        }
      }
      g_free (id);
    }
    free(content.mem_base);
    if (count > 0)
      ret = candidate_list;
  }
  *size = count;
  g_free (search_url);
  return ret;
}