<commit_before>﻿using KoScrobbler.Interfaces;
using System;
using System.Collections.Generic;
using KoScrobbler.Entities;
using KoScrobbler.Entities.Exceptions;
using KoScrobbler.Entities.LastFmApi;

namespace KoScrobbler
{
    public class Scrobbler : ILastFmScrobbler
    {
        internal static string ApiKey;
        internal static string ApiSecret;
        private LastFmApiClient client;
        public string SessionKey { get; set; }

        private LastFmApiClient Client
        {
            get
            {
                if (client == null)
                    client = new LastFmApiClient();
                client.SessionKey = SessionKey;
                return client;
            }
        }

        public Scrobbler(string apiKey, string apiSecret)
        {
            ApiKey = apiKey;
            ApiSecret = apiSecret;
        }

        public GetSessionResult CreateSession(string userName, string password)
        {
            var method = "auth.getmobilesession";

            var parameters = new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string>("username", userName),
                new KeyValuePair<string, string>("password", password)
            };

            var response = TryPost<LastFmGetSessionResponse>(method, parameters);

            if (response?.Session == null)
                return new GetSessionResult();

            return new GetSessionResult()
            {
                SessionKey = response.Session.Key,
                Success = true
            };
        }

        public ValidateSessionResult ValidateSession(string userName, string sessionKey)
        {
            var method = "user.getInfo";

            ValidateSessionKey(sessionKey);

            var parameters = new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string>("sk", sessionKey)
            };

            var getInfoResponse = TryGet<LastFmGetUserInfoResponse>(method, parameters);

            if (getInfoResponse?.UserInfo == null || 
                !string.Equals(getInfoResponse.UserInfo.Name, userName, StringComparison.InvariantCulture))
                return new ValidateSessionResult();

            SessionKey = sessionKey;

            return new ValidateSessionResult
            {
                Success = true,
                UserName = userName,
                SessionKey = sessionKey
            };
        }

        public ScrobbleResult TryScrobble(List<Scrobble> scrobbles)
        {
            var method = "track.scrobble";

            ValidateSessionKey(SessionKey);

            var parameters = new List<KeyValuePair<string, string>>();

            for (int i = 0; i < scrobbles.Count; i++)
            {
                parameters.Add(new KeyValuePair<string, string>($"track[{i}]", scrobbles[i].Title));
                parameters.Add(new KeyValuePair<string, string>($"artist[{i}]", scrobbles[i].Artist));<commit_msg>Case sensitivty fix<commit_after>﻿using KoScrobbler.Interfaces;
using System;
using System.Collections.Generic;
using KoScrobbler.Entities;
using KoScrobbler.Entities.Exceptions;
using KoScrobbler.Entities.LastFmApi;

namespace KoScrobbler
{
    public class Scrobbler : ILastFmScrobbler
    {
        internal static string ApiKey;
        internal static string ApiSecret;
        private LastFmApiClient client;
        public string SessionKey { get; set; }

        private LastFmApiClient Client
        {
            get
            {
                if (client == null)
                    client = new LastFmApiClient();
                client.SessionKey = SessionKey;
                return client;
            }
        }

        public Scrobbler(string apiKey, string apiSecret)
        {
            ApiKey = apiKey;
            ApiSecret = apiSecret;
        }

        public GetSessionResult CreateSession(string userName, string password)
        {
            var method = "auth.getmobilesession";

            var parameters = new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string>("username", userName),
                new KeyValuePair<string, string>("password", password)
            };

            var response = TryPost<LastFmGetSessionResponse>(method, parameters);

            if (response?.Session == null)
                return new GetSessionResult();

            return new GetSessionResult()
            {
                SessionKey = response.Session.Key,
                Success = true
            };
        }

        public ValidateSessionResult ValidateSession(string userName, string sessionKey)
        {
            var method = "user.getInfo";

            ValidateSessionKey(sessionKey);

            var parameters = new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string>("sk", sessionKey)
            };

            var getInfoResponse = TryGet<LastFmGetUserInfoResponse>(method, parameters);

            if (getInfoResponse?.UserInfo == null || 
                !string.Equals(getInfoResponse.UserInfo.Name, userName, StringComparison.InvariantCultureIgnoreCase))
                return new ValidateSessionResult();

            SessionKey = sessionKey;

            return new ValidateSessionResult
            {
                Success = true,
                UserName = userName,
                SessionKey = sessionKey
            };
        }

        public ScrobbleResult TryScrobble(List<Scrobble> scrobbles)
        {
            var method = "track.scrobble";

            ValidateSessionKey(SessionKey);

            var parameters = new List<KeyValuePair<string, string>>();

            for (int i = 0; i < scrobbles.Count; i++)
            {
                parameters.Add(new KeyValuePair<string, string>($"track[{i}]", scrobbles[i].Title));
                parameters.Add(new KeyValuePair<string, string>($"artist[{i}]", scrobbles[i].Artist));
{'fraction_non_alphanumeric': 0.08475141808475142, 'fraction_numerical': 0.000333667000333667, 'mean_word_length': 1.8561219628394474, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 31, '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': '3273021', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1480, 'n_words': 335}