[banshee: 23/61] [InternetArchive] Add offline testing mode
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [banshee: 23/61] [InternetArchive] Add offline testing mode
- Date: Tue, 3 Nov 2009 06:29:46 +0000 (UTC)
commit e414602d32d10b826c4e9d388a3395bb07690d53
Author: Gabriel Burt <gabriel burt gmail com>
Date: Sat Oct 10 15:19:01 2009 -0700
[InternetArchive] Add offline testing mode
.../Banshee.InternetArchive/Item.cs | 46 ++++++++------------
.../Banshee.InternetArchive/Source.cs | 4 +-
.../InternetArchive/JsonExtensions.cs | 6 +++
.../Banshee.InternetArchive/InternetArchive/README | 4 ++
4 files changed, 31 insertions(+), 29 deletions(-)
---
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Item.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Item.cs
index 7afe6e0..46374bf 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Item.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Item.cs
@@ -211,37 +211,27 @@ namespace Banshee.InternetArchive
}*/
- /*details = new Hyena.Json.Deserializer (System.IO.File.ReadAllText ("item.json")).Deserialize () as JsonObject;
- details.Dump ();
- metadata = details["metadata"] as JsonObject;
- misc = details["misc"] as JsonObject;
- item = details["item"] as JsonObject;
- var r = details["reviews"] as JsonObject;
- if (r != null) {
- reviews = r["reviews"] as JsonArray;
- review_info = r["info"] as JsonObject;
+ // Hack to load JSON data from local file instead of from archive.org
+ if (Id == "banshee-internet-archive-offline-mode") {
+ details = new Hyena.Json.Deserializer (System.IO.File.ReadAllText ("item2.json")).Deserialize () as JsonObject;
+ } else {
+ // We don't; grab it from archive.org and parse it
+ string json_str = IA.Item.GetDetails (Id);
+
+ if (json_str != null) {
+ details = new Hyena.Json.Deserializer (json_str).Deserialize () as JsonObject;
+ JsonDetails = json_str;
+ }
}
- return details != null;*/
-
- // We don't; grab it from archive.org and parse it
- string json_str = IA.Item.GetDetails (Id);
-
- if (json_str != null) {
- details = new Hyena.Json.Deserializer (json_str).Deserialize () as JsonObject;
- metadata = details["metadata"] as JsonObject;
- misc = details["misc"] as JsonObject;
- item = details["item"] as JsonObject;
- var r = details["reviews"] as JsonObject;
+ if (details != null) {
+ metadata = details.Get<JsonObject> ("metadata");
+ misc = details.Get<JsonObject> ("misc");
+ item = details.Get<JsonObject> ("item");
+ var r = details.Get<JsonObject> ("reviews");
if (r != null) {
- reviews = r["reviews"] as JsonArray;
- review_info = r["info"] as JsonObject;
- }
-
- if (details != null) {
- JsonDetails = json_str;
- //Save ();
- return true;
+ reviews = r.Get<JsonArray> ("reviews");
+ review_info = r.Get<JsonObject> ("info");
}
}
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Source.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Source.cs
index 35fb46b..6d3872a 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Source.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/Source.cs
@@ -133,7 +133,9 @@ namespace Banshee.InternetArchive
Properties.Set<Gtk.Widget> ("Nereid.SourceContents.HeaderWidget", header_widget);
}
- //AddChildSource (new ItemSource ("Fooz", "fooz"));
+ if (ApplicationContext.CommandLine.Contains ("internet-archive-offline-mode")) {
+ AddChildSource (new ItemSource ("Local H Live at Levis L2 Lazer Rock Stage [Summerfest 1999] on 1999-06-24", "banshee-internet-archive-offline-mode"));
+ }
}
public override void Reload ()
diff --git a/src/Extensions/Banshee.InternetArchive/InternetArchive/JsonExtensions.cs b/src/Extensions/Banshee.InternetArchive/InternetArchive/JsonExtensions.cs
index efe8822..891ab9a 100644
--- a/src/Extensions/Banshee.InternetArchive/InternetArchive/JsonExtensions.cs
+++ b/src/Extensions/Banshee.InternetArchive/InternetArchive/JsonExtensions.cs
@@ -38,6 +38,9 @@ namespace InternetArchive
{
public static T Get<T> (this JsonObject item, string key)
{
+ if (item == null)
+ return default (T);
+
object result;
if (item.TryGetValue (key, out result)) {
try {
@@ -82,6 +85,9 @@ namespace InternetArchive
public static string GetJoined (this JsonObject item, string key, string with)
{
+ if (item == null)
+ return null;
+
var ary = item.Get<System.Collections.IEnumerable> (key);
if (ary != null) {
return String.Join (with, ary.Cast<object> ().Select (o => o.ToString ()).ToArray ());
diff --git a/src/Extensions/Banshee.InternetArchive/InternetArchive/README b/src/Extensions/Banshee.InternetArchive/InternetArchive/README
index 8f045da..b94ead1 100644
--- a/src/Extensions/Banshee.InternetArchive/InternetArchive/README
+++ b/src/Extensions/Banshee.InternetArchive/InternetArchive/README
@@ -1,2 +1,6 @@
There is documentation of the Internet Archive's APIs at
http://www.archive.org/help/
+
+Since that page mentions that JSON is the preferred format
+moving forward, this API wrapper uses the JSON APIs wherever
+possible.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]