Exemple #1
0
static GList *relations_generated_parse(cb_object *capo)
{
    GList *result_list = NULL;
    GList *temple_list = NULL;

    if(capo->s->title && capo->s->album) {
        temple_list = g_list_prepend(temple_list, "Musicbrainz Recording:http://musicbrainz.org/search?query=\"${title}\"+AND+artist%3A\"${artist}\"+AND+release%3A\"${album}\"&type=recording&advanced=1");
    }

    if(capo->s->album) {
        temple_list = g_list_prepend(temple_list, "Musicbrainz Album:http://musicbrainz.org/search?query=\"${album}\"+AND+artist%3A\"${artist}\"&type=release&advanced=1");
        temple_list = g_list_prepend(temple_list, "Wikipedia Album:http://en.wikipedia.org/wiki/Special:Search/${album}(${artist})");
    }

    temple_list = g_list_prepend(temple_list, "Musicbrainz Artist:http://musicbrainz.org/search?query=\"${artist}\"&type=artist");
    temple_list = g_list_prepend(temple_list, "Wikipedia Artist:http://en.wikipedia.org/wiki/Special:Search/${artist}");
    temple_list = g_list_prepend(temple_list, "Lastfm Page:http://last.fm/music/${artist}");

    for(GList *elem = temple_list; elem; elem = elem->next) {
        gchar *result_url = prepare_url(elem->data, capo->s, TRUE);
        if(result_url != NULL) {
            GlyrMemCache *result = DL_init();
            result->data = result_url;
            result->size = strlen(result_url);
            result->dsrc = g_strdup(OFFLINE_PROVIDER);
            result->prov = g_strdup("generated");
            result->type = GLYR_TYPE_RELATION;
            update_md5sum(result);
            result_list = g_list_prepend(result_list, result);
        }
    }

    g_list_free(temple_list);
    return result_list;
}
Exemple #2
0
static int download_queue_request(CURLM *multi, struct repo_t *repo) {
  struct stat st;
  _cleanup_free_ char *url = NULL;

  if (repo->curl == NULL) {
    /* it's my first time, be gentle */
    if (repo->servercount == 0) {
      fprintf(stderr, "error: no servers configured for repo %s\n", repo->name);
      return -1;
    }
    repo->curl = curl_easy_init();
    snprintf(repo->diskfile, sizeof(repo->diskfile), CACHEPATH "/%s.files",
             repo->name);
    curl_easy_setopt(repo->curl, CURLOPT_FOLLOWLOCATION, 1L);
    curl_easy_setopt(repo->curl, CURLOPT_WRITEFUNCTION, write_handler);
    curl_easy_setopt(repo->curl, CURLOPT_WRITEDATA, repo);
    curl_easy_setopt(repo->curl, CURLOPT_PRIVATE, repo);
    curl_easy_setopt(repo->curl, CURLOPT_ERRORBUFFER, repo->errmsg);
    curl_easy_setopt(repo->curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_easy_setopt(repo->curl, CURLOPT_USERAGENT,
                     PACKAGE "/v" PACKAGE_VERSION);
    repo->tmpfile.fd = open_tmpfile(O_RDWR | O_NONBLOCK);
    if (repo->tmpfile.fd < 0) {
      fprintf(stderr,
              "error: failed to create temporary file for download: %s\n",
              strerror(-repo->tmpfile.fd));
      return -1;
    }
  } else {
    curl_multi_remove_handle(multi, repo->curl);
    lseek(repo->tmpfile.fd, 0, SEEK_SET);
    ftruncate(repo->tmpfile.fd, 0);
    repo->server_idx++;
  }

  if (repo->server_idx >= repo->servercount) {
    fprintf(stderr, "error: failed to update repo: %s\n", repo->name);
    return -1;
  }

  url = prepare_url(repo->servers[repo->server_idx], repo->name, repo->arch);
  if (url == NULL) {
    fputs("error: failed to allocate URL for download\n", stderr);
    return -1;
  }

  curl_easy_setopt(repo->curl, CURLOPT_URL, url);

  if (repo->force == 0 && stat(repo->diskfile, &st) == 0) {
    curl_easy_setopt(repo->curl, CURLOPT_TIMEVALUE, (long)st.st_mtime);
    curl_easy_setopt(repo->curl, CURLOPT_TIMECONDITION,
                     CURL_TIMECOND_IFMODSINCE);
  }

  repo->dl_time_start = now();
  curl_multi_add_handle(multi, repo->curl);

  return 0;
}
Exemple #3
0
static gchar *configure_regex(const gchar *regex, GlyrQuery *subs)
{
    gchar *correct_regex = NULL;
    if(regex && subs) {
        GlyrQuery temp;
        temp.artist = REGEX_ESCAPE(subs->artist);
        temp.album  = REGEX_ESCAPE(subs->album);
        temp.title  = REGEX_ESCAPE(subs->title);

        correct_regex = prepare_url(regex, &temp, FALSE);

        g_free(temp.artist);
        g_free(temp.album);
        g_free(temp.title);
    }
    return correct_regex;
}