Skip to content

Commit

Permalink
#23 cache api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
csomakk committed Aug 24, 2014
1 parent b6cba28 commit b4979ce
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
Binary file modified install/IWatchSeriez.air
Binary file not shown.
3 changes: 3 additions & 0 deletions src/Context.as
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import components.fileList.MainView;
import core.FileMetaDataBase;
import core.LocationDataBase;

import movieServices.InfoQueryCache;

import utils.VLCManager;

public class Context {
Expand All @@ -13,6 +15,7 @@ public class Context {

public var fileMetaDB:FileMetaDataBase = new FileMetaDataBase();
public var vlcManager:VLCManager = new VLCManager();
public var infoQueryCache:InfoQueryCache = new InfoQueryCache();
public var mainView:MainView;

}
Expand Down
24 changes: 3 additions & 21 deletions src/components/fileList/MainView.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,8 @@
isCreated = true;
}
public function alert(text:String = "", title:String = "",
flags:uint = 0x4 /* Alert.OK */,
parent:Sprite = null,
closeHandler:Function = null,
iconClass:Class = null,
defaultButtonFlag:uint = 0x4 /* Alert.OK */,
moduleFactory:IFlexModuleFactory = null):Alert {
return Alert.show(text, title, flags, parent, closeHandler, iconClass, defaultButtonFlag, moduleFactory );
public function alert(text:String = "", title:String = "", flags:uint = 0x4 /* Alert.OK */, parent:Sprite = null, closeHandler:Function = null, iconClass:Class = null, defaultButtonFlag:uint = 0x4 /* Alert.OK */, moduleFactory:IFlexModuleFactory = null):Alert {
return Alert.show(text, title, flags, parent, closeHandler, iconClass, defaultButtonFlag, moduleFactory);
}
public function openFile(file:File):void {
Expand Down Expand Up @@ -87,19 +81,7 @@
}
private function getInfo():void {
var parts:Array = output.text.split(/\\/);
var query:String = parts.pop();
query = query.replace(/\.|\(|\)|\-/gi, " "); //replace (.) to spaces
//query = query.replace(/\-/gi, " "); //replace (-) to spaces
var find:int = query.search(/S[0-9][0-9]/gi);
query = find > 10 ? query.slice(0, find) : query; //slice after season
find = query.search(/(19|20)\d{2}/gi);
query = find > 4 ? query.slice(0, find) : query; //slice after year 1900-2099
query = query.slice(0, 30);
trace("MainView.getInfo", query);
currentInfo = new MovieData();
OmdbApi.getInfo(query, currentInfo);
IWatchSeriez.CONTEXT.infoQueryCache.getInfo(output.text);
}
private function handleFolderChange():void {
Expand Down
46 changes: 46 additions & 0 deletions src/movieServices/InfoQueryCache.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package movieServices {
import flash.utils.Dictionary;

import model.MovieData;

public class InfoQueryCache {

public var cache:Dictionary;

public function InfoQueryCache() {
cache = new Dictionary();
}

public function getInfo(folderName:String):void {
var query:String = getQuery(folderName);
var movieData:MovieData;

if (!cache[query]) {
movieData = new MovieData();
cache[query] = movieData;
OmdbApi.getInfo(query, movieData);
}

IWatchSeriez.CONTEXT.mainView.currentInfo = cache[query];
}

public static function getQuery(folderName:String):String {
var parts:Array = folderName.split(/\\/);
var query:String = parts.pop();
var find:int;

query = query.replace(/\.|\(|\)|\-/gi, " "); //replace (.) to spaces
//query = query.replace(/\-/gi, " "); //replace (-) to spaces

find = query.search(/S[0-9][0-9]/gi); //Ex. S03, S10
query = find > 10 ? query.slice(0, find) : query; //slice after season

find = query.search(/(19|20)\d{2}/gi); //Ex. 1921, 2013
query = find > 4 ? query.slice(0, find) : query; //slice after year 1900-2099

query = query.slice(0, 30); //length check
return query;
}

}
}

0 comments on commit b4979ce

Please sign in to comment.