<commit_before>#include <stdio.h>
#include <string.h>

#include <spotify/api.h>

#include "artist.h"
#include "album.h"
#include "debug.h"
#include "link.h"
#include "util.h"
#include "sp_opaque.h"
#include "track.h"

/* The Visual C++ compiler doesn't know 'snprintf'... */
#ifdef _MSC_VER
#define snprintf _snprintf
#endif

static void baseconvert(const char *src, char *dest, int frombase, int tobase, int padlen);
static void id_bytes_to_uri(const unsigned char* id, char* uri);
static void id_uri_to_bytes(const char* uri, unsigned char* id);

SP_LIBEXPORT(sp_link *) sp_link_create_from_string (const char *link) {
	const char *ptr;
	sp_link *lnk;
	unsigned char id[16];
	sp_session *session;
	
	if(link == NULL)
		return NULL;
	
	ptr = link;
	
	/* Check if link starts with "spotify:" */
	if(strncmp("spotify:", ptr, 8) != 0)
		return NULL;

	ptr += 8;
	
	/* Get session. */
	session = libopenspotify_link_get_session();
	
	if(session == NULL)
		return NULL;
	
	/* Allocate memory for link. */
	if((lnk = (sp_link *)malloc(sizeof(sp_link))) == NULL)
		return NULL;
	
	lnk->type      = SP_LINKTYPE_INVALID;
	lnk->data.data = NULL;
	lnk->refs      = 1;
	
	/* Link refers to a track. */
	if(strncmp("track:", ptr, 6) == 0){
		ptr += 6;

		id_uri_to_bytes(ptr, id);

		lnk->type       = SP_LINKTYPE_TRACK;
		lnk->data.track = osfy_track_add(session, id);
		sp_track_add_ref(lnk->data.track);
	}
	/* Link refers to an album. */
	else if(strncmp("album:", ptr, 6) == 0){
		ptr += 6;

		id_uri_to_bytes(ptr, id);

		lnk->type       = SP_LINKTYPE_ALBUM;
		lnk->data.album = sp_album_add(session, id);
		sp_album_add_ref(lnk->data.album);

		/* Browse album if needed */
		if(sp_album_is_loaded(lnk->data.artist) == 0) {
			DSFYDEBUG("Browsing not yet loaded album\n");
			osfy_album_browse(session, lnk->data.album);
		}
	}
	}
	/* Link refers to an artist. */
	else if(strncmp("artist:", ptr, 7) == 0){
		ptr += 7;

		id_uri_to_bytes(ptr, id);

		lnk->type        = SP_LINKTYPE_ARTIST;
		lnk->data.artist = osfy_artist_add(session, id);
		sp_artist_add_ref(lnk->data.artist);

		/* Browse artist if needed */
		if(sp_artist_is_loaded(lnk->data.artist) == 0) {
			DSFYDEBUG("Browsing not yet loaded artist\n");
			osfy_artist_browse(session, lnk->data.artist);
		}
	}<commit_msg>Fix two copy/paste issues that prevented sp_link.c from compiling<commit_after>#include <stdio.h>
#include <string.h>

#include <spotify/api.h>

#include "artist.h"
#include "album.h"
#include "debug.h"
#include "link.h"
#include "util.h"
#include "sp_opaque.h"
#include "track.h"

/* The Visual C++ compiler doesn't know 'snprintf'... */
#ifdef _MSC_VER
#define snprintf _snprintf
#endif

static void baseconvert(const char *src, char *dest, int frombase, int tobase, int padlen);
static void id_bytes_to_uri(const unsigned char* id, char* uri);
static void id_uri_to_bytes(const char* uri, unsigned char* id);

SP_LIBEXPORT(sp_link *) sp_link_create_from_string (const char *link) {
	const char *ptr;
	sp_link *lnk;
	unsigned char id[16];
	sp_session *session;
	
	if(link == NULL)
		return NULL;
	
	ptr = link;
	
	/* Check if link starts with "spotify:" */
	if(strncmp("spotify:", ptr, 8) != 0)
		return NULL;

	ptr += 8;
	
	/* Get session. */
	session = libopenspotify_link_get_session();
	
	if(session == NULL)
		return NULL;
	
	/* Allocate memory for link. */
	if((lnk = (sp_link *)malloc(sizeof(sp_link))) == NULL)
		return NULL;
	
	lnk->type      = SP_LINKTYPE_INVALID;
	lnk->data.data = NULL;
	lnk->refs      = 1;
	
	/* Link refers to a track. */
	if(strncmp("track:", ptr, 6) == 0){
		ptr += 6;

		id_uri_to_bytes(ptr, id);

		lnk->type       = SP_LINKTYPE_TRACK;
		lnk->data.track = osfy_track_add(session, id);
		sp_track_add_ref(lnk->data.track);
	}
	/* Link refers to an album. */
	else if(strncmp("album:", ptr, 6) == 0){
		ptr += 6;

		id_uri_to_bytes(ptr, id);

		lnk->type       = SP_LINKTYPE_ALBUM;
		lnk->data.album = sp_album_add(session, id);
		sp_album_add_ref(lnk->data.album);

		/* Browse album if needed */
		if(sp_album_is_loaded(lnk->data.album) == 0) {
			DSFYDEBUG("Browsing not yet loaded album\n");
			osfy_album_browse(session, lnk->data.album);
		}
	}
	/* Link refers to an artist. */
	else if(strncmp("artist:", ptr, 7) == 0){
		ptr += 7;

		id_uri_to_bytes(ptr, id);

		lnk->type        = SP_LINKTYPE_ARTIST;
		lnk->data.artist = osfy_artist_add(session, id);
		sp_artist_add_ref(lnk->data.artist);

		/* Browse artist if needed */
		if(sp_artist_is_loaded(lnk->data.artist) == 0) {
			DSFYDEBUG("Browsing not yet loaded artist\n");
			osfy_artist_browse(session, lnk->data.artist);
		}
	}
{'fraction_non_alphanumeric': 0.1558018252933507, 'fraction_numerical': 0.007388092133854845, 'mean_word_length': 3.8300104931794334, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '779494', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1801, 'n_words': 420}