2013-06-08 18:49:21 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2013-06-13 20:33:13 +01:00
|
|
|
|
using System.IO;
|
2013-06-08 18:49:21 +01:00
|
|
|
|
using System.Linq;
|
2013-06-11 17:40:22 +01:00
|
|
|
|
using System.Net;
|
2013-06-08 18:49:21 +01:00
|
|
|
|
using System.Text;
|
2013-06-11 17:40:22 +01:00
|
|
|
|
using System.Threading.Tasks;
|
2013-06-08 18:49:21 +01:00
|
|
|
|
using IF.Lastfm.Core;
|
|
|
|
|
using IF.Lastfm.Core.Api;
|
2013-06-13 21:30:18 +01:00
|
|
|
|
using IF.Lastfm.Core.Api.Helpers;
|
2013-06-13 20:33:13 +01:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
2013-06-08 18:49:21 +01:00
|
|
|
|
|
|
|
|
|
namespace IF.Lastfm.Console
|
|
|
|
|
{
|
2013-06-13 20:33:13 +01:00
|
|
|
|
internal class Program
|
2013-06-08 18:49:21 +01:00
|
|
|
|
{
|
2013-06-13 20:33:13 +01:00
|
|
|
|
private static string _apiKey;
|
|
|
|
|
private static string _apiSecret;
|
|
|
|
|
private static string _username;
|
|
|
|
|
private static string _pass;
|
2013-06-08 18:49:21 +01:00
|
|
|
|
|
2013-06-13 20:33:13 +01:00
|
|
|
|
private static void Main(string[] args)
|
2013-06-08 18:49:21 +01:00
|
|
|
|
{
|
2013-06-13 21:30:18 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Task.Run(async () => await Run()).Wait();
|
|
|
|
|
}
|
|
|
|
|
catch (AggregateException agg)
|
|
|
|
|
{
|
|
|
|
|
foreach (var ex in agg.InnerExceptions)
|
|
|
|
|
{
|
2013-06-15 13:57:20 +01:00
|
|
|
|
System.Console.WriteLine("Exception thrown:\n {0}\n {1}",
|
2013-06-13 21:30:18 +01:00
|
|
|
|
ex.Message,
|
|
|
|
|
ex.StackTrace);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.Console.ReadLine();
|
2013-06-11 17:40:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task Run()
|
|
|
|
|
{
|
2013-06-13 20:33:13 +01:00
|
|
|
|
await LoadSession();
|
|
|
|
|
|
|
|
|
|
var auth = new Auth(_apiKey, _apiSecret);
|
|
|
|
|
await auth.GetSessionTokenAsync(_username, _pass);
|
2013-06-11 17:40:22 +01:00
|
|
|
|
|
|
|
|
|
var albumApi = new AlbumApi(auth);
|
|
|
|
|
|
|
|
|
|
var album = await albumApi.GetAlbumInfoAsync("Grimes", "Visions", false);
|
2013-06-13 20:33:13 +01:00
|
|
|
|
|
|
|
|
|
}
|
2013-06-11 17:40:22 +01:00
|
|
|
|
|
2013-06-13 20:33:13 +01:00
|
|
|
|
private async static Task LoadSession()
|
|
|
|
|
{
|
|
|
|
|
const string path = @"C:\lastfm-wp-config.json";
|
2013-06-08 18:49:21 +01:00
|
|
|
|
|
2013-06-13 20:33:13 +01:00
|
|
|
|
string json;
|
|
|
|
|
using (var reader = new StreamReader(path))
|
|
|
|
|
{
|
|
|
|
|
json = await reader.ReadToEndAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var jo = JsonConvert.DeserializeObject<JToken>(json);
|
|
|
|
|
|
|
|
|
|
_apiKey = jo.Value<string>("apikey");
|
|
|
|
|
_apiSecret = jo.Value<string>("apisecret");
|
|
|
|
|
_username = jo.Value<string>("username");
|
|
|
|
|
_pass = jo.Value<string>("pass");
|
2013-06-08 18:49:21 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-13 20:33:13 +01:00
|
|
|
|
}
|