Skip to content
This repository has been archived by the owner on Mar 24, 2020. It is now read-only.

Commit

Permalink
Added FanartTV and RottenTomatoes API Libraries
Browse files Browse the repository at this point in the history
Not yet used by Ember but in this way you can have fun.
you need to request and API from both. Will add to the new scraper soon
:)

On RottenTomatoes I just added the calls we may need.
  • Loading branch information
m.savazzi committed Feb 22, 2013
1 parent 18e0a32 commit 70d2d9d
Show file tree
Hide file tree
Showing 34 changed files with 1,720 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Ember Media Manager.sln
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "scraper.EmberCore.TMDB", "A
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatTmdb", "WatTmdb\WatTmdb.csproj", "{EFC11645-FAB4-4C30-A498-29F5ECDF77E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FanartTVAPI", "FanartTVAPI\FanartTVAPI.csproj", "{70F651C6-6BB4-4E4D-AD6C-25C36CA1E9E6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RottenTomatoesAPI", "RottenTomatoesAPI\RottenTomatoesAPI.csproj", "{8DAFAF56-AD78-4B47-866F-E8179511AF5B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -239,6 +243,26 @@ Global
{EFC11645-FAB4-4C30-A498-29F5ECDF77E8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{EFC11645-FAB4-4C30-A498-29F5ECDF77E8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{EFC11645-FAB4-4C30-A498-29F5ECDF77E8}.Release|x86.ActiveCfg = Release|Any CPU
{70F651C6-6BB4-4E4D-AD6C-25C36CA1E9E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{70F651C6-6BB4-4E4D-AD6C-25C36CA1E9E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70F651C6-6BB4-4E4D-AD6C-25C36CA1E9E6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{70F651C6-6BB4-4E4D-AD6C-25C36CA1E9E6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{70F651C6-6BB4-4E4D-AD6C-25C36CA1E9E6}.Debug|x86.ActiveCfg = Debug|Any CPU
{70F651C6-6BB4-4E4D-AD6C-25C36CA1E9E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70F651C6-6BB4-4E4D-AD6C-25C36CA1E9E6}.Release|Any CPU.Build.0 = Release|Any CPU
{70F651C6-6BB4-4E4D-AD6C-25C36CA1E9E6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{70F651C6-6BB4-4E4D-AD6C-25C36CA1E9E6}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{70F651C6-6BB4-4E4D-AD6C-25C36CA1E9E6}.Release|x86.ActiveCfg = Release|Any CPU
{8DAFAF56-AD78-4B47-866F-E8179511AF5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8DAFAF56-AD78-4B47-866F-E8179511AF5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8DAFAF56-AD78-4B47-866F-E8179511AF5B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{8DAFAF56-AD78-4B47-866F-E8179511AF5B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{8DAFAF56-AD78-4B47-866F-E8179511AF5B}.Debug|x86.ActiveCfg = Debug|Any CPU
{8DAFAF56-AD78-4B47-866F-E8179511AF5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8DAFAF56-AD78-4B47-866F-E8179511AF5B}.Release|Any CPU.Build.0 = Release|Any CPU
{8DAFAF56-AD78-4B47-866F-E8179511AF5B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{8DAFAF56-AD78-4B47-866F-E8179511AF5B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{8DAFAF56-AD78-4B47-866F-E8179511AF5B}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
104 changes: 104 additions & 0 deletions FanartTVAPI/FanartTV/FanartTV.Async.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RestSharp;
using System.Net;

namespace FanartTV.V1
{
public partial class FanartTV
{
#region Process Execution

private void ProcessAsyncRequest<T>(RestRequest request, Action<FanartTVAsyncResult<T>> callback)
where T : new()
{
var client = new RestClient(BASE_URL);
client.AddHandler("application/json", new WatJsonDeserializer());
client.AddHandler("application/json charset=utf-8", new WatJsonDeserializer());

if (Timeout.HasValue)
client.Timeout = Timeout.Value;

#if !WINDOWS_PHONE
if (Proxy != null)
client.Proxy = Proxy;
#endif

Error = null;

//request.AddHeader("Accept", "application/json");
//request.AddParameter("api_key", ApiKey);

++AsyncCount;
var asyncHandle = client.ExecuteAsync<T>(request, resp =>
{
--AsyncCount;
var result = new FanartTVAsyncResult<T>
{
Data = resp.Data != null ? resp.Data : default(T),
UserState = request.UserState
};
ResponseContent = resp.Content;
ResponseHeaders = resp.Headers.ToDictionary(k => k.Name, v => v.Value);
if (resp.ResponseStatus != ResponseStatus.Completed)
{
if (resp.Content.Contains("status_message"))
result.Error = resp.Content ;
else if (resp.ErrorException != null)
throw resp.ErrorException;
else
result.Error = resp.Content ;
}
Error = result.Error;
callback(result);
});
}


#endregion

private static bool CheckQuery<T>(string query, object userState, Action<FanartTVAsyncResult<T>> callback)
where T : class
{
if (string.IsNullOrEmpty(query))
{
callback(new FanartTVAsyncResult<T>
{
Data = null,
Error = "Search cannot be empty",
UserState = userState
});
return false;
}

return true;
}

#region Movie Info

/// <summary>
/// Retrieve all the basic movie information for a particular movie by FanartTV reference.
/// http://fanart.tv/api-docs/movie-api/
/// </summary>
/// <param name="apikey">FanartTV movie id</param>
/// <param name="id">optional - ISO 639-1 language code</param>
/// The following parameters are optional but if you want to change any from the default value you must specify all optional parameters before the one you are changing (so if you are changing just format you don’t have to specify type, but if you want to change the sort you MUST also specify the format and type)</param>
/// <param name="format">Returns the results in the requested format - json (default) / php (returns a php serialized object)</param>
/// <param name="type">Returns the requested image types - all (default) / movielogo / movieart / moviedisc</param>
/// <param name="sort">1 – Sorted by most popular image then newest(default) / 2 – Sorted by newest uploaded image / 3 – Sorted by oldest uploaded image</param>
/// <param name="limit">Value is either 1 (1 image) or 2 (all images – default), for example, when automatically downloading images you might only want to return the first result so the user doesn’t have to provide input, whereas with a manual download you might want the user to see all the options.</param>
/// <returns></returns>
public void GetMovieInfo(FanartTVRequest Request, Action<FanartTVAsyncResult<FanartTVMovie>> callback)
{
//ProcessAsyncRequest<FanartTVMovie>(BuildGetMovieInfoRequest(MovieID, language, UserState), callback);
ProcessAsyncRequest<FanartTVMovie>(Generator.GetMovieInfo(Request), callback);
}
#endregion
}
}
77 changes: 77 additions & 0 deletions FanartTVAPI/FanartTV/FanartTV.Sync.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RestSharp;
using System.Net;

namespace FanartTV.V1
{
public partial class FanartTV
{
#region Process Execution

private T ProcessRequest<T>(RestRequest request)
where T : new()
{
var client = new RestClient(BASE_URL);
client.AddHandler("application/json", new WatJsonDeserializer());
client.AddHandler("application/json charset=utf-8", new WatJsonDeserializer());

if (Timeout.HasValue)
client.Timeout = Timeout.Value;

#if !WINDOWS_PHONE
if (Proxy != null)
client.Proxy = Proxy;
#endif

var resp = client.Execute<T>(request);

ResponseContent = resp.Content;
ResponseHeaders = resp.Headers.ToDictionary(k => k.Name, v => v.Value);

if (resp.ResponseStatus == ResponseStatus.Completed)
{
if (resp.Content.Contains("status_message"))
Error = resp.Content;

return resp.Data;
}
else
{
if (resp.Content.Contains("status_message"))
Error = resp.Content;
else if (resp.ErrorException != null)
throw resp.ErrorException;
else
Error = resp.ErrorMessage;
}

return default(T);
}

#endregion


#region Movie Info
/// <summary>
/// Retrieve all the basic movie information for a particular movie by FanartTV reference.
/// http://fanart.tv/api-docs/movie-api/
/// </summary>
/// <param name="apikey">FanartTV movie id</param>
/// <param name="id">optional - ISO 639-1 language code</param>
/// The following parameters are optional but if you want to change any from the default value you must specify all optional parameters before the one you are changing (so if you are changing just format you don’t have to specify type, but if you want to change the sort you MUST also specify the format and type)</param>
/// <param name="format">Returns the results in the requested format - json (default) / php (returns a php serialized object)</param>
/// <param name="type">Returns the requested image types - all (default) / movielogo / movieart / moviedisc</param>
/// <param name="sort">1 – Sorted by most popular image then newest(default) / 2 – Sorted by newest uploaded image / 3 – Sorted by oldest uploaded image</param>
/// <param name="limit">Value is either 1 (1 image) or 2 (all images – default), for example, when automatically downloading images you might only want to return the first result so the user doesn’t have to provide input, whereas with a manual download you might want the user to see all the options.</param>
/// <returns></returns>
public FanartTVMovie GetMovieInfo(FanartTVRequest Request)
{
//return ProcessRequest<FanartTVMovie>(BuildGetMovieInfoRequest(MovieID, language));
return ProcessRequest<FanartTVMovie>(Generator.GetMovieInfo(Request));
}
#endregion
}
}
78 changes: 78 additions & 0 deletions FanartTVAPI/FanartTV/FanartTV.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RestSharp.Deserializers;
using System.Net;
using RestSharp;
using FanartTV.Utilities;

namespace FanartTV.V1
{
public partial class FanartTV
{
private const string BASE_URL = "http://api.fanart.tv/webservice/";

public FanartTV(string apiKey)
{
ApiKey = apiKey;
Error = null;
Timeout = null;

Deserializer = new JsonDeserializer();
Generator = new RequestGenerator(apiKey);
}

#region Properties

private RequestGenerator Generator { get; set; }

private RequestGenerator ETagGenerator { get; set; }

private string ApiKey { get; set; }

private string Language { get; set; }

private JsonDeserializer Deserializer;

#endregion

/// <summary>
/// Current count of outstanding Async calls awaiting callback response
/// </summary>
public int AsyncCount = 0;

/// <summary>
/// Error message
/// </summary>
public string Error { get; set; }

/// <summary>
/// String representation of response content
/// </summary>
public string ResponseContent { get; set; }

/// <summary>
/// Dictionary of Header values in response
/// http://fanart.tv/api-docs/movie-api/
/// </summary>
public Dictionary<string, object> ResponseHeaders { get; set; }


#if !WINDOWS_PHONE
/// <summary>
/// Proxy to use for requests made. Passed on to underying WebRequest if set.
/// </summary>
public IWebProxy Proxy { get; set; }
#endif
/// <summary>
/// Timeout in milliseconds to use for requests made.
/// </summary>
public int? Timeout { get; set; }




}

}
73 changes: 73 additions & 0 deletions FanartTVAPI/FanartTVAPI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{70F651C6-6BB4-4E4D-AD6C-25C36CA1E9E6}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FanartTVAPI</RootNamespace>
<AssemblyName>FanartTVAPI</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="RestSharp">
<HintPath>..\packages\RestSharp.104.1\lib\net35\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="V1\FanartTVRequest.cs" />
<Compile Include="V1\FanartTVAsyncResult.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="FanartTV\FanartTV.Async.cs" />
<Compile Include="FanartTV\FanartTV.cs" />
<Compile Include="FanartTV\FanartTV.Sync.cs" />
<Compile Include="Utilities\Constants.cs" />
<Compile Include="Utilities\RequestBuilder.cs" />
<Compile Include="Utilities\RequestGenerator.cs" />
<Compile Include="Utilities\Utility.cs" />
<Compile Include="V1\FanartTVError.cs" />
<Compile Include="V1\FanartTVMovie.cs" />
<Compile Include="V1\WatJsonDeserializer.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Loading

0 comments on commit 70d2d9d

Please sign in to comment.