<commit_before>// New Tumblr object
function Tumblr(tab){
    this.tab = tab;
}

// request audio posts from Tumblr API
Tumblr.prototype.getPosts = function(){
    var requestUrl = constants.TUMBLR.POSTS; 
    requestUrl += this.tab.response.hostname;
    requestUrl += "/posts?api_key=" + keys.TUMBLR.KEY;
    requestUrl += "&type=audio";
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = this.response.bind(this); 
    xhr.open("GET", requestUrl, true);
    xhr.send();
}

// request audio posts from Dashboard
Tumblr.prototype.getDashboard = function(){
    chrome.storage.sync.get(
        'tumblrAuth',
        this.checkAuth.bind(this)
    );
}

// check to see if user has auth
// if so, make signed request to dashboard
// if not, prompt for user to auth
Tumblr.prototype.checkAuth = function(oAuthObj){
    if(oAuthObj['tumblrAuth']){
        var requestUrl = constants.TUMBLR.DASHBOARD + "?type=audio"; 
        var message = 
            {
				method: "get", 
				action: requestUrl, 
				parameters: []
			}
        OAuth.completeRequest(message, 
            {
    			'consumerKey': keys.TUMBLR.KEY, 
    			'consumerSecret': keys.TUMBLR.SECRET, 
    			'token': oAuthObj['tumblrAuth'].oauth_token,
                'tokenSecret': oAuthObj['tumblrAuth'].oauth_token_secret
            }
        );
        var authorizationHeader = OAuth.getAuthorizationHeader("", message.parameters);
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = this.response.bind(this); 
        xhr.open(message.method, requestUrl, true);
        xhr.setRequestHeader("Authorization", authorizationHeader);
        xhr.send();
    }
    else{
        chrome.tabs.sendMessage(this.tab.id,
            {
                "type": "needAuth",
                "service": "Tumblr",
                "url": chrome.extension.getURL("html/options.html")
            }
        );
    }
}

// response from Tumblr API
Tumblr.prototype.response = function(e){
    if(e.target.readyState === 4){
        if(e.target.status === 200){
            var json = JSON.parse(e.target.response);
            this.parse(json);
        }
    }
}

// parse response from Tumblr API
// Build playlist of Song objects
Tumblr.prototype.parse = function(json){
    var posts = json.response.posts;
    var len = posts.length;
    if(len > 0){
        var playlist = [];
        for(var i = 0; i < len; i++){
            var post = posts[i];
            if(post.audio_type !== 'spotify'){
                var song = new Song();
                song.type = "tumblr";
                song.originalType = post.audio_type;
                song.originalSource = post.source_url;
                song.title = post.track_name;
                song.artist = post.artist;
                song.album = post.album;
                song.artwork = post.album_art;
                song.url = post.audio_url;
                song.link = post.post_url;
                song.serviceId = post.id;
                song.reblogKey = post.reblog_key;
                song.timestamp = post.timestamp;
                song.hasMeta = true;
                if(!post.track_name){
                    song.title = post.slug.replace(/-/g, ' ');
                    song.hasMeta = false;
                }<commit_msg>split soundcloud songs on tumblr by -<commit_after>// New Tumblr object
function Tumblr(tab){
    this.tab = tab;
}

// request audio posts from Tumblr API
Tumblr.prototype.getPosts = function(){
    var requestUrl = constants.TUMBLR.POSTS; 
    requestUrl += this.tab.response.hostname;
    requestUrl += "/posts?api_key=" + keys.TUMBLR.KEY;
    requestUrl += "&type=audio";
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = this.response.bind(this); 
    xhr.open("GET", requestUrl, true);
    xhr.send();
}

// request audio posts from Dashboard
Tumblr.prototype.getDashboard = function(){
    chrome.storage.sync.get(
        'tumblrAuth',
        this.checkAuth.bind(this)
    );
}

// check to see if user has auth
// if so, make signed request to dashboard
// if not, prompt for user to auth
Tumblr.prototype.checkAuth = function(oAuthObj){
    if(oAuthObj['tumblrAuth']){
        var requestUrl = constants.TUMBLR.DASHBOARD + "?type=audio"; 
        var message = 
            {
				method: "get", 
				action: requestUrl, 
				parameters: []
			}
        OAuth.completeRequest(message, 
            {
    			'consumerKey': keys.TUMBLR.KEY, 
    			'consumerSecret': keys.TUMBLR.SECRET, 
    			'token': oAuthObj['tumblrAuth'].oauth_token,
                'tokenSecret': oAuthObj['tumblrAuth'].oauth_token_secret
            }
        );
        var authorizationHeader = OAuth.getAuthorizationHeader("", message.parameters);
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = this.response.bind(this); 
        xhr.open(message.method, requestUrl, true);
        xhr.setRequestHeader("Authorization", authorizationHeader);
        xhr.send();
    }
    else{
        chrome.tabs.sendMessage(this.tab.id,
            {
                "type": "needAuth",
                "service": "Tumblr",
                "url": chrome.extension.getURL("html/options.html")
            }
        );
    }
}

// response from Tumblr API
Tumblr.prototype.response = function(e){
    if(e.target.readyState === 4){
        if(e.target.status === 200){
            var json = JSON.parse(e.target.response);
            this.parse(json);
        }
    }
}

// parse response from Tumblr API
// Build playlist of Song objects
Tumblr.prototype.parse = function(json){
    var posts = json.response.posts;
    var len = posts.length;
    if(len > 0){
        var playlist = [];
        for(var i = 0; i < len; i++){
            var post = posts[i];
            if(post.audio_type !== 'spotify'){
                var song = new Song();
                song.type = "tumblr";
                song.originalType = post.audio_type;
                song.originalSource = post.source_url;
                song.title = post.track_name;
                song.artist = post.artist;
                if(post.audio_type === 'soundcloud' && !song.artist){
                    var titleSplit = post.track_name.split(' - ');
                    if(titleSplit.length === 2){
                        song.artist = titleSplit[0];
                        song.title = titleSplit[1];
                    }
                }
                song.album = post.album;
                song.artwork = post.album_art;
                song.url = post.audio_url;
                song.link = post.post_url;
                song.serviceId = post.id;
                song.reblogKey = post.reblog_key;
                song.timestamp = post.timestamp;
                song.hasMeta = true;
                if(!post.track_name){
                    song.title = post.slug.replace(/-/g, ' ');
                    song.hasMeta = false;
                }
{'fraction_non_alphanumeric': 0.12462050021685701, 'fraction_numerical': 0.002168570189388463, 'mean_word_length': 1.8329238329238329, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, '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': '4293841', 'n_tokens_mistral': 2211, 'n_tokens_neox': 2033, 'n_words': 410}