Section 1
//AbstractData (ca.newcommerce.youtube.data.AbstractData)
package ca.newcommerce.youtube.data {
public class AbstractData {
public function AbstractData(){
super();
}
protected function fromObj(data:Object, index:String):String{
if (data[index] == null){
return ("");
};
if ((data[index] as String) != null){
return (data[index]);
};
return (data[index].$t);
}
}
}//package ca.newcommerce.youtube.data
Section 2
//AuthorData (ca.newcommerce.youtube.data.AuthorData)
package ca.newcommerce.youtube.data {
public class AuthorData extends AbstractData {
protected var _data:Object;
public function AuthorData(data:Object){
super();
_data = data;
}
public function get username():String{
var lclUri:String = uri;
return (lclUri.substr((lclUri.lastIndexOf("/") + 1)));
}
public function get name():String{
return (fromObj(_data, "name"));
}
public function get uri():String{
return (fromObj(_data, "uri"));
}
}
}//package ca.newcommerce.youtube.data
Section 3
//CategoryData (ca.newcommerce.youtube.data.CategoryData)
package ca.newcommerce.youtube.data {
public class CategoryData extends AbstractData {
protected var _data:Object;
public function CategoryData(data:Object){
super();
_data = data;
}
public function get label():String{
return (_data.label);
}
public function get scheme():String{
var scheme:String = fromObj(_data, "scheme");
if (scheme.indexOf("#") != -1){
return (scheme.substr((scheme.indexOf("#") + 1)));
};
return (scheme.substr((scheme.lastIndexOf("/") + 1), (scheme.lastIndexOf(".") - (scheme.lastIndexOf("/") + 1))));
}
public function get term():String{
var term:String = fromObj(_data, "term");
if (term.indexOf("#") != -1){
return (term.substr((term.lastIndexOf("#") + 1)));
};
return (term);
}
public function get text():String{
return (((_data.$t)!="") ? _data.$t : ((_data.label)!="") ? label : term);
}
}
}//package ca.newcommerce.youtube.data
Section 4
//CommentData (ca.newcommerce.youtube.data.CommentData)
package ca.newcommerce.youtube.data {
import ca.newcommerce.youtube.iterators.*;
public class CommentData extends AbstractData {
protected var _data:Object;
public function CommentData(data:Object){
super();
_data = data;
}
public function get links():LinkIterator{
return (new LinkIterator(_data.link));
}
public function get authors():AuthorIterator{
return (new AuthorIterator(_data.author));
}
public function get content():String{
return (fromObj(_data, "content"));
}
public function get updated():String{
return (fromObj(_data, "updated"));
}
public function get id():String{
return (fromObj(_data, "id"));
}
public function get categories():CategoryIterator{
return (new CategoryIterator(_data.category));
}
public function get published():String{
return (fromObj(_data, "published"));
}
public function get title():String{
return (fromObj(_data, "title"));
}
}
}//package ca.newcommerce.youtube.data
Section 5
//ContactData (ca.newcommerce.youtube.data.ContactData)
package ca.newcommerce.youtube.data {
import ca.newcommerce.youtube.iterators.*;
public class ContactData extends AbstractData {
protected var _data:Object;
public function ContactData(data:Object){
super();
_data = data;
}
public function get links():LinkIterator{
return (new LinkIterator(_data.link));
}
public function get status():String{
return (fromObj(_data, "yt$status"));
}
public function get username():String{
return (fromObj(_data, "yt$username"));
}
public function get title():String{
return (fromObj(_data, "title"));
}
public function get updated():String{
return (fromObj(_data, "updated"));
}
public function get id():String{
return (fromObj(_data, "id"));
}
public function get categories():CategoryIterator{
return (new CategoryIterator(_data.category));
}
public function get published():String{
return (fromObj(_data, "published"));
}
}
}//package ca.newcommerce.youtube.data
Section 6
//FeedLinkData (ca.newcommerce.youtube.data.FeedLinkData)
package ca.newcommerce.youtube.data {
public class FeedLinkData extends AbstractData {
protected var _data:Object;
public function FeedLinkData(data:Object){
super();
_data = data;
}
public function get countHint():Number{
return (parseInt(fromObj(_data, "countHint")));
}
public function get rel():String{
var rel:String = fromObj(_data, "rel");
if (rel.indexOf("#") != -1){
return (rel.substr((rel.lastIndexOf("#") + 1)));
};
return (rel);
}
public function get href():String{
return (fromObj(_data, "href"));
}
}
}//package ca.newcommerce.youtube.data
Section 7
//GeneratorData (ca.newcommerce.youtube.data.GeneratorData)
package ca.newcommerce.youtube.data {
public class GeneratorData {
protected var _data:Object;
public function GeneratorData(data:Object){
super();
_data = data;
}
public function get version():String{
return (_data.version);
}
public function get uri():String{
return (_data.uri);
}
public function get text():String{
return (_data.$t);
}
}
}//package ca.newcommerce.youtube.data
Section 8
//LinkData (ca.newcommerce.youtube.data.LinkData)
package ca.newcommerce.youtube.data {
public class LinkData extends AbstractData {
protected var _data:Object;
public function LinkData(data:Object){
super();
_data = data;
}
public function get rel():String{
var rel:String = fromObj(_data, "rel");
if (rel.indexOf("#") != -1){
return (rel.substr((rel.lastIndexOf("#") + 1)));
};
return (rel);
}
public function get type():String{
return (fromObj(_data, "type"));
}
public function get href():String{
return (fromObj(_data, "href"));
}
}
}//package ca.newcommerce.youtube.data
Section 9
//MediaContentData (ca.newcommerce.youtube.data.MediaContentData)
package ca.newcommerce.youtube.data {
public class MediaContentData {
protected var _data:Object;
public function MediaContentData(data:Object){
super();
_data = data;
}
public function get duration():Number{
return (parseInt(_data.duration));
}
public function get isDefault():Boolean{
return ((_data.isDefault == "true"));
}
public function get expression():String{
return (_data.expression);
}
public function get type():String{
return (_data.type);
}
public function get format():Number{
return (parseInt(_data.yt$format));
}
public function get url():String{
return (_data.url);
}
}
}//package ca.newcommerce.youtube.data
Section 10
//MediaGroupData (ca.newcommerce.youtube.data.MediaGroupData)
package ca.newcommerce.youtube.data {
import ca.newcommerce.youtube.iterators.*;
public class MediaGroupData extends AbstractData {
protected var _data:Object;
public function MediaGroupData(data:Object){
super();
_data = data;
}
public function get keywords():Array{
var key:String = _data.media$keywords;
return (key.split(", "));
}
public function get duration():Number{
return (parseInt(_data.yt$duration.seconds));
}
public function get thumbnails():ThumbnailIterator{
return (new ThumbnailIterator(_data.media$thumbnail));
}
public function get title():String{
return (_data.media$title.$t);
}
public function get contents():MediaContentIterator{
return (new MediaContentIterator(_data.media$content));
}
public function get categories():CategoryIterator{
return (new CategoryIterator(_data.media$category));
}
public function get description():String{
return (_data.media$description.$t);
}
public function get mediaPlayerUri():String{
return (_data.media$player[0].url);
}
}
}//package ca.newcommerce.youtube.data
Section 11
//PlaylistData (ca.newcommerce.youtube.data.PlaylistData)
package ca.newcommerce.youtube.data {
import ca.newcommerce.youtube.iterators.*;
public class PlaylistData extends AbstractData {
protected var _data:Object;
public function PlaylistData(data:Object){
super();
_data = data;
}
public function get links():LinkIterator{
return (new LinkIterator(_data.link));
}
public function get id():String{
return (fromObj(_data, "id"));
}
public function get categories():CategoryIterator{
return (new CategoryIterator(_data.category));
}
public function get authors():AuthorIterator{
return (new AuthorIterator(_data.author));
}
public function get actualId():String{
var id:String = this.id;
return (id.substr((id.lastIndexOf("/") + 1)));
}
public function get published():String{
return (fromObj(_data, "published"));
}
public function get title():String{
return (fromObj(_data, "title"));
}
public function get content():String{
return (fromObj(_data, "content"));
}
public function get updated():String{
return (fromObj(_data, "updated"));
}
public function get description():String{
return (fromObj(_data, "yt$description"));
}
public function get feedLink():FeedLinkData{
return (new FeedLinkData(_data.gd$feedLink));
}
}
}//package ca.newcommerce.youtube.data
Section 12
//ProfileData (ca.newcommerce.youtube.data.ProfileData)
package ca.newcommerce.youtube.data {
import ca.newcommerce.youtube.iterators.*;
public class ProfileData extends AbstractData {
protected var _data:Object;
public function ProfileData(data:Object){
super();
_data = data;
}
public function get gender():String{
return (fromObj(_data, "yt$gender"));
}
public function get feedLinks():FeedLinkIterator{
return (new FeedLinkIterator(_data.gd$feedLink));
}
public function get movies():String{
return (fromObj(_data, "yt$movies"));
}
public function get updated():String{
return (fromObj(_data, "updated"));
}
public function get author():AuthorIterator{
return (new AuthorIterator(_data.author));
}
public function get username():String{
return (fromObj(_data, "yt$username"));
}
public function get title():String{
return (fromObj(_data, "title"));
}
public function get occupation():String{
return (fromObj(_data, "yt$occupation"));
}
public function get id():String{
return (fromObj(_data, "id"));
}
public function get categories():CategoryIterator{
return (new CategoryIterator(_data.category));
}
public function get lastname():String{
return (fromObj(_data, "yt$lastname"));
}
public function get statistics():StatisticsData{
return (new StatisticsData(_data.yt$statistics));
}
public function get music():String{
return (fromObj(_data, "yt$music"));
}
public function get books():String{
return (fromObj(_data, "yt$books"));
}
public function get thumbnail():String{
return (_data.media$thumbnail.url);
}
public function get published():String{
return (fromObj(_data, "published"));
}
public function get hobbies():String{
return (fromObj(_data, "yt$hobbies"));
}
public function get hometown():String{
return (fromObj(_data, "yt$hometown"));
}
public function get school():String{
return (fromObj(_data, "yt$school"));
}
public function get location():String{
return (fromObj(_data, "yt$location"));
}
public function get relationship():String{
return (fromObj(_data, "yt$relationship"));
}
public function get links():LinkIterator{
return (new LinkIterator(_data.link));
}
public function get firstname():String{
return (fromObj(_data, "yt$firstname"));
}
public function get company():String{
return (fromObj(_data, "yt$company"));
}
public function get age():Number{
return (parseInt(fromObj(_data, "yt$age")));
}
}
}//package ca.newcommerce.youtube.data
Section 13
//RatingData (ca.newcommerce.youtube.data.RatingData)
package ca.newcommerce.youtube.data {
public class RatingData {
protected var _data:Object;
public function RatingData(data:Object){
super();
_data = data;
}
public function get min():Number{
return (parseInt(_data.min));
}
public function get max():Number{
return (parseInt(_data.max));
}
public function get numRaters():Number{
return (parseInt(_data.numRaters));
}
public function get average():Number{
return (parseInt(_data.average));
}
}
}//package ca.newcommerce.youtube.data
Section 14
//StatisticsData (ca.newcommerce.youtube.data.StatisticsData)
package ca.newcommerce.youtube.data {
public class StatisticsData extends AbstractData {
protected var _data:Object;
public function StatisticsData(data:Object){
super();
_data = data;
}
public function get lastWebAccess():String{
return (_data.lastWebAccess);
}
public function get viewCount():Number{
return (parseInt(_data.viewCount));
}
public function get videoWatchCount():Number{
return (parseInt(_data.videoWatchCount));
}
}
}//package ca.newcommerce.youtube.data
Section 15
//SubscriptionData (ca.newcommerce.youtube.data.SubscriptionData)
package ca.newcommerce.youtube.data {
import ca.newcommerce.youtube.iterators.*;
public class SubscriptionData extends AbstractData {
protected var _data:Object;
public static const FAVORITE_SUBSCRIPTION:String = "favorite";
public static const QUERY_SUBSCRIPTION:String = "query";
public static const CHANNEL_SUBSCRIPTION:String = "channel";
public static const UNKNOWN_SUBSCRIPTION:String = "unknown";
public function SubscriptionData(data:Object){
super();
_data = data;
}
public function get links():LinkIterator{
return (new LinkIterator(_data.link));
}
public function get updated():String{
return (fromObj(_data, "updated"));
}
public function get authors():AuthorIterator{
return (new AuthorIterator(_data.author));
}
public function get published():String{
return (fromObj(_data, "published"));
}
public function get username():String{
return (fromObj(_data, "yt$username"));
}
public function get title():String{
return (fromObj(_data, "title"));
}
public function get queryString():String{
return (fromObj(_data, "yt$queryString"));
}
public function get type():String{
var categories:CategoryIterator;
var category:CategoryData;
while ((category = categories.next())) {
if (category.scheme == "subscriptiontypes"){
if (category.term == FAVORITE_SUBSCRIPTION){
return (FAVORITE_SUBSCRIPTION);
};
if (category.term == CHANNEL_SUBSCRIPTION){
return (CHANNEL_SUBSCRIPTION);
};
if (category.term == QUERY_SUBSCRIPTION){
return (QUERY_SUBSCRIPTION);
};
};
};
return (UNKNOWN_SUBSCRIPTION);
}
public function get id():String{
return (fromObj(_data, "id"));
}
public function get categories():CategoryIterator{
return (new CategoryIterator(_data.category));
}
public function get feedLink():FeedLinkData{
return (new FeedLinkData(_data.gd$feedLink));
}
}
}//package ca.newcommerce.youtube.data
Section 16
//ThumbnailData (ca.newcommerce.youtube.data.ThumbnailData)
package ca.newcommerce.youtube.data {
public class ThumbnailData {
protected var _data:Object;
public function ThumbnailData(data:Object){
super();
_data = data;
}
public function get width():Number{
return (parseInt(_data.width));
}
public function get height():Number{
return (parseInt(_data.height));
}
public function get time():String{
return (_data.time);
}
public function get url():String{
return (_data.url);
}
}
}//package ca.newcommerce.youtube.data
Section 17
//VideoData (ca.newcommerce.youtube.data.VideoData)
package ca.newcommerce.youtube.data {
import ca.newcommerce.youtube.iterators.*;
public class VideoData extends AbstractData {
protected var _data:Object;
public function VideoData(data:Object){
super();
_data = data;
}
public function get links():LinkIterator{
return (new LinkIterator(_data.link));
}
public function get id():String{
return (fromObj(_data, "id"));
}
public function get duration():Number{
return (media.duration);
}
public function get media():MediaGroupData{
return (new MediaGroupData(_data.media$group));
}
public function get authors():AuthorIterator{
return (new AuthorIterator(_data.author));
}
public function get viewCount():Number{
return (parseInt(_data.yt$statistics.viewCount));
}
public function get categorywords():Array{
return (categories.categorywords);
}
public function get swfUrl():String{
var content:MediaContentData;
var contents:MediaContentIterator = this.media.contents;
while ((content = contents.next())) {
if (content.type == "application/x-shockwave-flash"){
return (content.url);
};
};
return ("");
}
public function get published():String{
return (fromObj(_data, "published"));
}
public function get commentFeedUri():String{
if (((((_data.gd$comments) && (_data.gd$comments.gd$feedLink))) && (_data.gd$comments.gd$feedLink.href))){
return (_data.gd$comments.gd$feedLink.href);
};
return (null);
}
public function get actualId():String{
var id:String = this.id;
return (id.substr((id.lastIndexOf("/") + 1)));
}
public function get keywords():Array{
return (categories.keywords);
}
public function get mobileUrl():String{
var content:MediaContentData;
var contents:MediaContentIterator = this.media.contents;
while ((content = contents.next())) {
if ((((content.type == "video/3gpp")) && ((content.format == 6)))){
return (content.url);
};
};
return ("");
}
public function get commentCount():Number{
if (((((_data.gd$comments) && (_data.gd$comments.gd$feedLink))) && (_data.gd$comments.gd$feedLink.countHint))){
return (parseInt(_data.gd$comments.gd$feedLink.countHint));
};
return (0);
}
public function get title():String{
return (fromObj(_data, "title"));
}
public function get content():String{
return (fromObj(_data, "content"));
}
public function get updated():String{
return (fromObj(_data, "updated"));
}
public function get categories():CategoryIterator{
return (new CategoryIterator(_data.category));
}
public function get rating():RatingData{
return (new RatingData(_data.gd$rating));
}
}
}//package ca.newcommerce.youtube.data
Section 18
//CommentFeedEvent (ca.newcommerce.youtube.events.CommentFeedEvent)
package ca.newcommerce.youtube.events {
import flash.events.*;
import ca.newcommerce.youtube.feeds.*;
public class CommentFeedEvent extends Event {
protected var _requestId:Number;
protected var _feed:CommentFeed;
public static const COMMENT_DATA_RECEIVED:String = "comments_data_received";
public function CommentFeedEvent(type:String, requestId:Number, feed:CommentFeed){
super(type);
_requestId = requestId;
_feed = feed;
}
public function get requestId():Number{
return (_requestId);
}
public function get feed():CommentFeed{
return (_feed);
}
}
}//package ca.newcommerce.youtube.events
Section 19
//ContactFeedEvent (ca.newcommerce.youtube.events.ContactFeedEvent)
package ca.newcommerce.youtube.events {
import flash.events.*;
import ca.newcommerce.youtube.feeds.*;
public class ContactFeedEvent extends Event {
protected var _requestId:Number;
protected var _feed:ContactFeed;
public static const USER_DATA_RECEIVED:String = "user_data_received";
public static const USER_FEED_READY:String = "user_feed_ready";
public function ContactFeedEvent(type:String, requestId:Number, feed:ContactFeed){
super(type);
_feed = feed;
_requestId = requestId;
}
public function get requestId():Number{
return (_requestId);
}
public function get feed():ContactFeed{
return (_feed);
}
}
}//package ca.newcommerce.youtube.events
Section 20
//PlaylistFeedEvent (ca.newcommerce.youtube.events.PlaylistFeedEvent)
package ca.newcommerce.youtube.events {
import flash.events.*;
import ca.newcommerce.youtube.feeds.*;
public class PlaylistFeedEvent extends Event {
protected var _username:String;
protected var _requestId:Number;
protected var _feed:PlaylistFeed;
public static const PLAYLIST_DATA_RECEIVED:String = "playlist_data_received";
public function PlaylistFeedEvent(type:String, requestId:Number, username:String, feed:PlaylistFeed){
super(type);
_feed = feed;
_requestId = requestId;
_username = username;
}
public function get username():String{
return (_username);
}
public function get requestId():Number{
return (_requestId);
}
public function get feed():PlaylistFeed{
return (_feed);
}
}
}//package ca.newcommerce.youtube.events
Section 21
//ProfileEvent (ca.newcommerce.youtube.events.ProfileEvent)
package ca.newcommerce.youtube.events {
import flash.events.*;
import ca.newcommerce.youtube.data.*;
public class ProfileEvent extends Event {
protected var _profile:ProfileData;
protected var _requestId:Number;
public static const PROFILE_DATA_RECEIVED:String = "profile_data_received";
public function ProfileEvent(type:String, requestId:Number, profile:ProfileData){
super(type);
_requestId = requestId;
_profile = profile;
}
public function get requestId():Number{
return (_requestId);
}
public function get profile():ProfileData{
return (_profile);
}
override public function toString():String{
return ("ca.newcommerce.youtube.events.ProfileEvent");
}
}
}//package ca.newcommerce.youtube.events
Section 22
//ResponseFeedEvent (ca.newcommerce.youtube.events.ResponseFeedEvent)
package ca.newcommerce.youtube.events {
import flash.events.*;
import ca.newcommerce.youtube.feeds.*;
public class ResponseFeedEvent extends Event {
protected var _videoId:String;
protected var _requestId:Number;
protected var _feed:VideoFeed;
public static const RESPONSES_DATA_RECEIVED:String = "responses_data_received";
public function ResponseFeedEvent(type:String, requestId:Number, videoId:String, feed:VideoFeed){
super(type);
_requestId = requestId;
_videoId = videoId;
_feed = feed;
}
public function get requestId():Number{
return (_requestId);
}
public function get feed():VideoFeed{
return (_feed);
}
public function get videoId():String{
return (_videoId);
}
}
}//package ca.newcommerce.youtube.events
Section 23
//StandardVideoFeedEvent (ca.newcommerce.youtube.events.StandardVideoFeedEvent)
package ca.newcommerce.youtube.events {
import flash.events.*;
import ca.newcommerce.youtube.feeds.*;
public class StandardVideoFeedEvent extends Event {
protected var _feedType:String;
protected var _requestId:Number;
protected var _feed:VideoFeed;
public static const STANDARD_VIDEO_DATA_RECEIVED:String = "standard_video_data_received";
public function StandardVideoFeedEvent(type:String, requestId:Number, feedType:String, feed:VideoFeed){
super(type);
_feedType = feedType;
_feed = feed;
_requestId = requestId;
}
public function get requestId():Number{
return (_requestId);
}
public function get feed():VideoFeed{
return (_feed);
}
public function get feedType():String{
return (_feedType);
}
}
}//package ca.newcommerce.youtube.events
Section 24
//SubscriptionFeedEvent (ca.newcommerce.youtube.events.SubscriptionFeedEvent)
package ca.newcommerce.youtube.events {
import flash.events.*;
import ca.newcommerce.youtube.feeds.*;
public class SubscriptionFeedEvent extends Event {
protected var _requestId:Number;
protected var _feed:SubscriptionFeed;
public static const SUBSCRIPTION_DATA_RECEIVED:String = "subscription_data_received";
public function SubscriptionFeedEvent(type:String, requestId:Number, feed:SubscriptionFeed){
super(type);
_requestId = requestId;
_feed = feed;
}
public function get requestId():Number{
return (_requestId);
}
public function get feed():SubscriptionFeed{
return (_feed);
}
}
}//package ca.newcommerce.youtube.events
Section 25
//VideoDataEvent (ca.newcommerce.youtube.events.VideoDataEvent)
package ca.newcommerce.youtube.events {
import flash.events.*;
import ca.newcommerce.youtube.data.*;
public class VideoDataEvent extends Event {
protected var _requestId:Number;
protected var _video:VideoData;
public static const VIDEO_INFO_RECEIVED:String = "video_info_received";
public function VideoDataEvent(type:String, requestId:Number, video:VideoData){
super(type);
_video = video;
_requestId = requestId;
}
public function get video():VideoData{
return (_video);
}
override public function toString():String{
return ("ca.newcommerce.youtube.events.VideoDataEvent");
}
public function get requestId():Number{
return (_requestId);
}
}
}//package ca.newcommerce.youtube.events
Section 26
//VideoFeedEvent (ca.newcommerce.youtube.events.VideoFeedEvent)
package ca.newcommerce.youtube.events {
import flash.events.*;
import ca.newcommerce.youtube.feeds.*;
public class VideoFeedEvent extends Event {
protected var _requestId:Number;
protected var _feed:VideoFeed;
public static const RELATED_VIDEOS_DATA_RECEIVED:String = "related_videos_data_received";
public static const VIDEO_PLAYLIST_DATA_RECEIVED:String = "video_playlist_data_received";
public static const VIDEO_FEED_READY:String = "video_feed_ready";
public static const VIDEO_DATA_RECEIVED:String = "video_data_received";
public static const USER_FAVORITES_DATA_RECEIVED:String = "user_favorites_data_received";
public static const VIDEO_RESPONSE_DATA_RECEIVED:String = "video_response_data_received";
public function VideoFeedEvent(type:String, requestId:Number, feed:VideoFeed){
super(type);
_feed = feed;
_requestId = requestId;
}
public function get requestId():Number{
return (_requestId);
}
override public function toString():String{
return ("ca.newcommerce.youtube.events.VideoFeedEvent");
}
public function get feed():VideoFeed{
return (_feed);
}
}
}//package ca.newcommerce.youtube.events
Section 27
//YouTubeEvent (ca.newcommerce.youtube.events.YouTubeEvent)
package ca.newcommerce.youtube.events {
import flash.events.*;
public class YouTubeEvent extends Event {
protected var _requestWrapper:Object;
protected var _requestId:Number;// = -1
public static const RATING_SUCCESSFUL:String = "rating_successful";
public static const FAVORITE_FAILED:String = "favorite_failed";
public static const UNFAVORITE_FAILED:String = "unfavorite_failed";
public static const RATING_SUCCESSFULL:String = "rating_successfull";
public static const SUBSCRIPTION_DELETED:String = "subscription_deleted";
public static const LOGIN_CAPTCHA_REQUIRED:String = "login_captcha_required";
public static const FAVORITE_SUCCESSFUL:String = "favorite_successful";
public static const SUBSCRIPTION_FAILED:String = "subscription_failed";
public static const UNFAVORITE_SUCCESSFUL:String = "unfavorite_successful";
public static const SEARCH_SUBSCRIPTION_SUCCESSFUL:String = "search_subscription_successful";
public static const CHANNEL_SUBSCRIPTION_SUCCESSFUL:String = "channel_subscription_successful";
public static const RAW_URL_DATA_RECEIVED:String = "raw_url_data_received";
public static const LOGIN_FAILED:String = "login_failed";
public static const FAVORITES_SUBSCRIPTION_SUCCESSFUL:String = "favorites_subscription_successful";
public static const LOGIN_SUCCESSFULL:String = "login_successfull";
public function YouTubeEvent(type:String, requestWrapper:Object){
super(type);
_requestId = requestWrapper.id;
_requestWrapper = requestWrapper;
}
public function get requestWrapper():Object{
return (_requestWrapper);
}
public function get requestId():Number{
return (_requestId);
}
}
}//package ca.newcommerce.youtube.events
Section 28
//AbstractFeed (ca.newcommerce.youtube.feeds.AbstractFeed)
package ca.newcommerce.youtube.feeds {
import ca.newcommerce.youtube.data.*;
import ca.newcommerce.youtube.iterators.*;
import com.adobe.serialization.json.*;
public class AbstractFeed extends AbstractData {
protected var _feedPointer:Number;// = -1
protected var _data:Object;
protected var _entries:Array;
public function AbstractFeed(data:String){
super();
_data = JSON.decode(data).feed;
_entries = _data.entry;
}
public function get authors():AuthorIterator{
return (new AuthorIterator(_data.author));
}
public function get updated():String{
return (fromObj(_data, "updated"));
}
public function get logo():String{
return (fromObj(_data, "logo"));
}
public function get itemsPerPage():Number{
return (parseInt(fromObj(_data, "openSearch$itemsPerPage")));
}
public function get count():Number{
if (_entries){
return (_entries.length);
};
return (0);
}
public function get startIndex():Number{
return (parseInt(fromObj(_data, "openSearch$startIndex")));
}
public function get totalResults():Number{
return (parseInt(fromObj(_data, "openSearch$totalResults")));
}
public function get title():String{
return (fromObj(_data, "title"));
}
public function get links():LinkIterator{
return (new LinkIterator(_data.link));
}
public function get generator():GeneratorData{
return (new GeneratorData(_data.generator));
}
public function get id():String{
return (fromObj(_data, "id"));
}
public function get categories():CategoryIterator{
return (new CategoryIterator(_data.category));
}
}
}//package ca.newcommerce.youtube.feeds
Section 29
//CommentFeed (ca.newcommerce.youtube.feeds.CommentFeed)
package ca.newcommerce.youtube.feeds {
import ca.newcommerce.youtube.data.*;
public class CommentFeed extends AbstractFeed {
public function CommentFeed(rawData:String){
super(rawData);
}
public function first():CommentData{
return (getAt((_feedPointer = 0)));
}
public function getAt(pos:Number):CommentData{
if ((((pos >= 0)) && ((pos < count)))){
return (new CommentData(_entries[pos]));
};
return (null);
}
public function next():CommentData{
return (getAt(++_feedPointer));
}
public function last():CommentData{
return (getAt((_feedPointer = (count - 1))));
}
public function previous():CommentData{
return (getAt(--_feedPointer));
}
}
}//package ca.newcommerce.youtube.feeds
Section 30
//ContactFeed (ca.newcommerce.youtube.feeds.ContactFeed)
package ca.newcommerce.youtube.feeds {
import ca.newcommerce.youtube.data.*;
public class ContactFeed extends AbstractFeed {
public function ContactFeed(rawData:String){
super(rawData);
}
public function first():ContactData{
return (getAt((_feedPointer = 0)));
}
public function getAt(pos:Number):ContactData{
if ((((pos >= 0)) && ((pos < count)))){
return (new ContactData(_entries[pos]));
};
return (null);
}
public function next():ContactData{
return (getAt(++_feedPointer));
}
public function last():ContactData{
return (getAt((_feedPointer = (count - 1))));
}
public function previous():ContactData{
return (getAt(--_feedPointer));
}
}
}//package ca.newcommerce.youtube.feeds
Section 31
//PlaylistFeed (ca.newcommerce.youtube.feeds.PlaylistFeed)
package ca.newcommerce.youtube.feeds {
import ca.newcommerce.youtube.data.*;
public class PlaylistFeed extends AbstractFeed {
public function PlaylistFeed(rawData:String){
super(rawData);
}
public function first():PlaylistData{
return (getAt((_feedPointer = 0)));
}
public function getAt(pos:Number):PlaylistData{
if ((((pos >= 0)) && ((pos < count)))){
return (new PlaylistData(_entries[pos]));
};
return (null);
}
public function next():PlaylistData{
return (getAt(++_feedPointer));
}
public function last():PlaylistData{
return (getAt((_feedPointer = (count - 1))));
}
public function previous():PlaylistData{
return (getAt(--_feedPointer));
}
}
}//package ca.newcommerce.youtube.feeds
Section 32
//SubscriptionFeed (ca.newcommerce.youtube.feeds.SubscriptionFeed)
package ca.newcommerce.youtube.feeds {
import ca.newcommerce.youtube.data.*;
public class SubscriptionFeed extends AbstractFeed {
public function SubscriptionFeed(rawData:String){
super(rawData);
}
public function first():SubscriptionData{
return (getAt((_feedPointer = 0)));
}
public function getAt(pos:Number):SubscriptionData{
if ((((count >= 0)) && ((pos < count)))){
return (new SubscriptionData(_entries[pos]));
};
return (null);
}
public function next():SubscriptionData{
return (getAt(++_feedPointer));
}
public function last():SubscriptionData{
return (getAt((_feedPointer = (count - 1))));
}
}
}//package ca.newcommerce.youtube.feeds
Section 33
//VideoFeed (ca.newcommerce.youtube.feeds.VideoFeed)
package ca.newcommerce.youtube.feeds {
import ca.newcommerce.youtube.data.*;
public class VideoFeed extends AbstractFeed {
public function VideoFeed(rawData:String){
super(rawData);
}
public function first():VideoData{
return (getAt((_feedPointer = 0)));
}
public function getAt(pos:Number):VideoData{
if ((((pos >= 0)) && ((pos < count)))){
return (new VideoData(_entries[pos]));
};
return (null);
}
public function next():VideoData{
return (getAt(++_feedPointer));
}
public function last():VideoData{
return (getAt((_feedPointer = (count - 1))));
}
public function previous():VideoData{
return (getAt(--_feedPointer));
}
}
}//package ca.newcommerce.youtube.feeds
Section 34
//AuthorIterator (ca.newcommerce.youtube.iterators.AuthorIterator)
package ca.newcommerce.youtube.iterators {
import ca.newcommerce.youtube.data.*;
public class AuthorIterator {
protected var _feedPointer:Number;// = -1
protected var _data:Array;
public function AuthorIterator(data:Array){
super();
_data = data;
}
public function getAt(pos:Number):AuthorData{
if (count > pos){
return (new AuthorData(_data[pos]));
};
return (null);
}
public function last():AuthorData{
return (getAt((_feedPointer = (count - 1))));
}
public function first():AuthorData{
return (getAt((_feedPointer = 0)));
}
public function next():AuthorData{
return (getAt(++_feedPointer));
}
public function get count():Number{
return (_data.length);
}
}
}//package ca.newcommerce.youtube.iterators
Section 35
//CategoryIterator (ca.newcommerce.youtube.iterators.CategoryIterator)
package ca.newcommerce.youtube.iterators {
import ca.newcommerce.youtube.data.*;
public class CategoryIterator {
protected var _feedPointer;// = -1
protected var _data:Array;
public function CategoryIterator(data:Array){
super();
_data = data;
}
public function getAt(pos:Number):CategoryData{
if ((((pos >= 0)) && ((pos < count)))){
return (new CategoryData(_data[pos]));
};
return (null);
}
public function get keywords():Array{
var category:CategoryData;
var lastPointer:* = _feedPointer;
_feedPointer = -1;
var keywords:Array = [];
while ((category = next())) {
if (category.scheme == "keywords"){
keywords.push(category.term);
};
};
_feedPointer = lastPointer;
return (keywords);
}
public function get categorywords():Array{
var category:CategoryData;
var lastPointer:* = _feedPointer;
_feedPointer = -1;
var catwords:Array = [];
while ((category = next())) {
if (category.scheme == "categories"){
catwords.push(category.label);
};
};
_feedPointer = lastPointer;
return (catwords);
}
public function get count():Number{
return (_data.length);
}
public function last():CategoryData{
return (getAt((_feedPointer = (count - 1))));
}
public function first():CategoryData{
return (getAt((_feedPointer = 0)));
}
public function next():CategoryData{
return (getAt(++_feedPointer));
}
public function previous():CategoryData{
return (getAt(--_feedPointer));
}
}
}//package ca.newcommerce.youtube.iterators
Section 36
//FeedLinkIterator (ca.newcommerce.youtube.iterators.FeedLinkIterator)
package ca.newcommerce.youtube.iterators {
import ca.newcommerce.youtube.data.*;
public class FeedLinkIterator {
protected var _feedPointer;// = -1
protected var _data:Array;
public function FeedLinkIterator(data:Array){
super();
_data = data;
}
public function last():FeedLinkData{
return (getAt((_feedPointer = (count - 1))));
}
public function getAt(pos:Number):FeedLinkData{
if ((((pos >= 0)) && ((pos < count)))){
return (new FeedLinkData(_data[pos]));
};
return (null);
}
public function next():FeedLinkData{
return (getAt(++_feedPointer));
}
public function first():FeedLinkData{
return (getAt((_feedPointer = 0)));
}
public function previous():FeedLinkData{
return (getAt(--_feedPointer));
}
public function get count():Number{
return (_data.length);
}
}
}//package ca.newcommerce.youtube.iterators
Section 37
//LinkIterator (ca.newcommerce.youtube.iterators.LinkIterator)
package ca.newcommerce.youtube.iterators {
import ca.newcommerce.youtube.data.*;
public class LinkIterator {
protected var _feedPointer;// = -1
protected var _data:Array;
public function LinkIterator(data:Array){
super();
_data = data;
}
public function last():LinkData{
return (getAt((_feedPointer = (count - 1))));
}
public function getAt(pos:Number):LinkData{
if ((((pos >= 0)) && ((pos < count)))){
return (new LinkData(_data[pos]));
};
return (null);
}
public function next():LinkData{
return (getAt(++_feedPointer));
}
public function first():LinkData{
return (getAt((_feedPointer = 0)));
}
public function previous():LinkData{
return (getAt(--_feedPointer));
}
public function get count():Number{
return (_data.length);
}
}
}//package ca.newcommerce.youtube.iterators
Section 38
//MediaContentIterator (ca.newcommerce.youtube.iterators.MediaContentIterator)
package ca.newcommerce.youtube.iterators {
import ca.newcommerce.youtube.data.*;
public class MediaContentIterator {
protected var _feedPointer;// = -1
protected var _data:Array;
public function MediaContentIterator(data:Array){
super();
_data = data;
}
public function last():MediaContentData{
return (getAt((_feedPointer = (count - 1))));
}
public function getAt(pos:Number):MediaContentData{
if ((((pos >= 0)) && ((pos < count)))){
return (new MediaContentData(_data[pos]));
};
return (null);
}
public function next():MediaContentData{
return (getAt(++_feedPointer));
}
public function first():MediaContentData{
return (getAt((_feedPointer = 0)));
}
public function previous():MediaContentData{
return (getAt(--_feedPointer));
}
public function get count():Number{
return (((_data)!=null) ? _data.length : 0);
}
}
}//package ca.newcommerce.youtube.iterators
Section 39
//ThumbnailIterator (ca.newcommerce.youtube.iterators.ThumbnailIterator)
package ca.newcommerce.youtube.iterators {
import ca.newcommerce.youtube.data.*;
public class ThumbnailIterator {
protected var _feedPointer:Number;// = -1
protected var _data:Array;
public function ThumbnailIterator(data:Array){
super();
_data = data;
}
public function last():ThumbnailData{
return (getAt((_feedPointer = (count - 1))));
}
public function getAt(pos:Number):ThumbnailData{
if ((((pos >= 0)) && ((pos < count)))){
return (new ThumbnailData(_data[pos]));
};
return (null);
}
public function next():ThumbnailData{
return (getAt(++_feedPointer));
}
public function first():ThumbnailData{
return (getAt((_feedPointer = 0)));
}
public function previous():ThumbnailData{
return (getAt(--_feedPointer));
}
public function get count():Number{
return (_data.length);
}
}
}//package ca.newcommerce.youtube.iterators
Section 40
//YouTubeFeedClient (ca.newcommerce.youtube.webservice.YouTubeFeedClient)
package ca.newcommerce.youtube.webservice {
import ca.newcommerce.youtube.events.*;
import flash.events.*;
import flash.net.*;
import ca.newcommerce.youtube.data.*;
import ca.newcommerce.youtube.feeds.*;
import com.adobe.serialization.json.*;
public class YouTubeFeedClient extends EventDispatcher {
protected const _developerKey:String = "AI39si5ojvdQW_7wzbgApyTS1EMXiEfRVZtq4usxFYDFq6ZqEDiaSsPrkNLdFPwy97z9wyGtk6FPrc35H5B9LjugSQG5duueYg";
protected const _clientId:String = "ytapi-MartinLegris-YoutubeDiscovery-rn7ifdis-0";
protected var _auth:String;// = ""
protected var _requestId:Number;// = 0
protected var _sessionId:String;
protected var _requestQueue:Array;
protected var _username:String;// = ""
public static const ORDER_BY_RELEVANCE:String = "relevance";
public static const STD_MOST_VIEWED:String = "most_viewed";
public static const TIME_ALL:String = "all_time";
public static const ORDER_BY_PUBLISHED:String = "published";
public static const STD_MOBILE_VIDEOS:String = "watch_on_mobile";
public static const STD_TOP_RATED:String = "top_rated";
public static const STD_MOST_DISCUSSED:String = "most_discussed";
public static const STD_MOST_LINKED:String = "most_linked";
public static const STD_MOST_RESPONSED:String = "most_responded";
public static const TIME_WEEK:String = "this_week";
public static const RACY_EXCLUDE:String = "exclude";
public static const TIME_MONTH:String = "this_month";
public static const TIME_TODAY:String = "today";
public static const STD_RECENTLY_FEATURED:String = "recently_featured";
public static const STD_TOP_FAVORITES:String = "top_favorites";
public static const ORDER_BY_VIEWCOUNT:String = "viewCount";
public static const RACY_INCLUDE:String = "include";
private static var _instance:YouTubeFeedClient;
public function YouTubeFeedClient(){
super();
_requestQueue = [];
}
protected function doVideosLoaded(evt:Event):void{
trace("doVideosLoaded");
var wrapper:Object = getWrapper((evt.target as URLLoader));
var feed:VideoFeed = new VideoFeed(evt.target.data);
dispatchEvent(new VideoFeedEvent(VideoFeedEvent.VIDEO_DATA_RECEIVED, wrapper.id, feed));
}
protected function doProfileLoaded(evt:Event):void{
trace("doProfileLoaded");
var wrapper:Object = getWrapper((evt.target as URLLoader));
var profile:ProfileData = new ProfileData(JSON.decode((evt.target.data as String)).entry);
dispatchEvent(new ProfileEvent(ProfileEvent.PROFILE_DATA_RECEIVED, wrapper.id, profile));
}
protected function doCommentsLoaded(evt:Event):void{
trace("doCommentsLoaded");
var wrapper:Object = getWrapper((evt.target as URLLoader));
var feed:CommentFeed = new CommentFeed((evt.target.data as String));
dispatchEvent(new CommentFeedEvent(CommentFeedEvent.COMMENT_DATA_RECEIVED, wrapper.id, feed));
}
public function getVideo(videoId:String):Number{
var url = (("http://gdata.youtube.com/feeds/api/videos/" + videoId) + "?alt=json");
var request:URLRequest = new URLRequest(url);
return (runLoader(request, doVideoLoaded, {comment:"video", videoId:videoId}));
}
public function getPlaylist(playlistId:String, startIndex:Number=1, maxResults:Number=50):Number{
var request:URLRequest = new URLRequest(((((("http://gdata.youtube.com/feeds/api/playlists/" + playlistId) + "?alt=json&start-index=") + startIndex) + "&max-results=") + maxResults));
return (runLoader(request, doPlaylistLoaded, {comment:"playlist", playlistId:playlistId}));
}
protected function getLoaderIndex(loader:URLLoader):Number{
var i:Number = 0;
while (i < _requestQueue.length) {
if (_requestQueue[i].loader == loader){
return (i);
};
i++;
};
return (-1);
}
protected function doHttpStatus(evt:HTTPStatusEvent):void{
var wrapper:Object;
trace(("WSClient.doHttpStatus:" + evt.status));
if (evt.status == 201){
evt.stopImmediatePropagation();
wrapper = getWrapper((evt.target as URLLoader));
trace(("wrapper.videoId:" + wrapper.videoId));
wrapper.success = true;
trace(evt.target.data);
};
}
public function getVideoResponses(videoId:String):Number{
var request:URLRequest = new URLRequest((("http://gdata.youtube.com/feeds/api/videos/" + videoId) + "/responses?alt=json"));
return (runLoader(request, doResponsesLoaded, {comment:"responses", videoId:videoId}));
}
public function getVideos(search:String="", author:String="", categories:Array=null, negativeCategories:Array=null, keywords:Array=null, negativeKeywords:Array=null, orderBy:String="relevance", racy:String="exclude", startIndex:Number=1, maxResults:Number=50):Number{
var url:String = "http://gdata.youtube.com/feeds/api/videos";
if ((((categories is Array)) && ((categories.length > 0)))){
url = (url + ("/-/" + categories.join("%7C")));
};
if ((((keywords is Array)) && ((keywords.length > 0)))){
if (url.indexOf("/-/") == -1){
url = (url + "/-");
};
url = (url + ("/" + keywords.join("%7C")));
};
url = (url + ((((((("?alt=json&orderby=" + orderBy) + "&racy=") + racy) + "&start-index=") + startIndex) + "&max-results=") + maxResults));
if (search.length > 0){
url = (url + ("&vq=" + search));
};
if (author.length > 0){
url = (url + ("&author=" + author));
};
var request:URLRequest = new URLRequest(url);
return (runLoader(request, doVideosLoaded, {comment:"videos", search:search, author:author, categories:categories, keywords:keywords, orderBy:orderBy, racy:racy, startIndex:startIndex, maxResults:maxResults}));
}
protected function doSubscriptionsLoaded(evt:Event):void{
trace("doSubscriptionsLoaded");
var wrapper:Object = getWrapper((evt.target as URLLoader));
var feed:SubscriptionFeed = new SubscriptionFeed((evt.target.data as String));
dispatchEvent(new SubscriptionFeedEvent(SubscriptionFeedEvent.SUBSCRIPTION_DATA_RECEIVED, wrapper.id, feed));
}
protected function doUserFavoritesLoaded(evt:Event):void{
trace("doUserFavoritesLoaded");
var wrapper:Object = getWrapper((evt.target as URLLoader));
var feed:VideoFeed = new VideoFeed((evt.target.data as String));
dispatchEvent(new VideoFeedEvent(VideoFeedEvent.USER_FAVORITES_DATA_RECEIVED, wrapper.id, feed));
}
protected function doIOError(evt:IOErrorEvent):void{
var wrapper:Object = getWrapper((evt.target as URLLoader));
if (!wrapper.success){
trace(("WSClient.doIOError(" + evt.toString()));
} else {
trace("success!");
};
}
protected function handleProgress(evt:ProgressEvent):void{
var percent:Number = Math.round(((evt.bytesLoaded / evt.bytesTotal) * 100));
var idx:Number = getLoaderIndex((evt.target as URLLoader));
}
public function getVideoComments(videoId:String, startIndex:Number=1, maxResults:Number=50):Number{
var request:URLRequest = new URLRequest(((((("http://gdata.youtube.com/feeds/api/videos/" + videoId) + "/comments?alt=json&start-index=") + startIndex) + "&max-results=") + maxResults));
return (runLoader(request, doCommentsLoaded, {comment:"comments", videoId:videoId}));
}
protected function handleIOError(evt:IOErrorEvent):void{
trace(("ioError on loader:" + getLoaderIndex((evt.target as URLLoader))));
}
protected function doVideoLoaded(evt:Event):void{
trace("doVideoLoaded");
var wrapper:Object = getWrapper((evt.target as URLLoader));
var entry:Object = JSON.decode((evt.target.data as String));
var video:VideoData = new VideoData(entry.entry);
dispatchEvent(new VideoDataEvent(VideoDataEvent.VIDEO_INFO_RECEIVED, wrapper.id, video));
}
protected function getWrapper(loader:URLLoader):Object{
return (_requestQueue[getLoaderIndex(loader)]);
}
public function getUserPlaylists(username:String, startIndex:Number=1, maxResults:Number=50):Number{
var request:URLRequest = new URLRequest(((((("http://gdata.youtube.com/feeds/api/users/" + username) + "/playlists?alt=json&start-index=") + startIndex) + "&max-results=") + maxResults));
return (runLoader(request, doUserPlaylistsLoaded, {comment:"user_playlist", username:username}));
}
protected function doPlaylistLoaded(evt:Event):void{
trace("doPlaylistLoaded");
var wrapper:Object = getWrapper((evt.target as URLLoader));
var feed:VideoFeed = new VideoFeed((evt.target.data as String));
dispatchEvent(new VideoFeedEvent(VideoFeedEvent.VIDEO_PLAYLIST_DATA_RECEIVED, wrapper.id, feed));
}
protected function doUserContactsLoaded(evt:Event):void{
trace("doUserContactsLoaded");
var wrapper:Object = getWrapper((evt.target as URLLoader));
var feed:ContactFeed = new ContactFeed((evt.target.data as String));
dispatchEvent(new ContactFeedEvent(ContactFeedEvent.USER_DATA_RECEIVED, wrapper.id, feed));
}
public function rawUrl(url:String):Number{
var request:URLRequest = new URLRequest(url);
return (runLoader(request, doRawUrlLoaded, {comment:"rawUrl", url:url}));
}
public function doResponsesLoaded(evt:Event):void{
trace("doResponsesLoaded");
var wrapper:Object = getWrapper((evt.target as URLLoader));
var feed:VideoFeed = new VideoFeed((evt.target.data as String));
dispatchEvent(new ResponseFeedEvent(ResponseFeedEvent.RESPONSES_DATA_RECEIVED, wrapper.id, wrapper.videoId, feed));
}
public function getRelatedVideos(videoId:String, startIndex:Number=1, maxResults:Number=50):Number{
var request:URLRequest = new URLRequest(((((("http://gdata.youtube.com/feeds/api/videos/" + videoId) + "/related?alt=json&start-index=") + startIndex) + "&max-results=") + maxResults));
return (runLoader(request, doRelatedVideosLoaded, {comments:"related_videos", videoId:videoId}));
}
public function getUserFavorites(username:String, categories:Array=null, keywords:Array=null, startIndex:Number=1, maxResults:Number=50):Number{
var url = (("http://gdata.youtube.com/feeds/api/users/" + username) + "/favorites");
if ((((categories is Array)) && ((categories.length > 0)))){
url = (url + ("/-/" + categories.join("%7C")));
};
if ((((keywords is Array)) && ((keywords.length > 0)))){
if (url.indexOf("/-/") == -1){
url = (url + "/-");
};
url = (url + ("/" + keywords.join("%7C")));
};
url = (url + ((("?alt=json&start-index=" + startIndex) + "&max-results=") + maxResults));
var request:URLRequest = new URLRequest(url);
return (runLoader(request, doUserFavoritesLoaded, {comment:"favorites", username:username}));
}
public function getUserProfile(username:String):Number{
var request:URLRequest = new URLRequest((("http://gdata.youtube.com/feeds/api/users/" + username) + "?alt=json"));
return (runLoader(request, doProfileLoaded, {comment:"profile", username:username}));
}
protected function doUserPlaylistsLoaded(evt:Event):void{
trace("doUserPlaylistsLoaded");
var wrapper:Object = getWrapper((evt.target as URLLoader));
var feed:PlaylistFeed = new PlaylistFeed((evt.target.data as String));
dispatchEvent(new PlaylistFeedEvent(PlaylistFeedEvent.PLAYLIST_DATA_RECEIVED, wrapper.id, wrapper.username, feed));
}
public function getStandardFeed(type:String, time:String="", startIndex:Number=1, maxResults:Number=50):Number{
var url:String = ((((("http://gdata.youtube.com/feeds/api/standardfeeds/" + type) + "?alt=json&start-index=") + startIndex) + "&max-results=") + maxResults);
if ((((((type == STD_TOP_RATED)) && ((type == STD_MOST_VIEWED)))) && ((time.length > 0)))){
url = (url + ("&time=" + time));
};
var request:* = new URLRequest(url);
return (runLoader(request, doStdFeedLoaded, {comment:"standard_feed", type:type, time:time}));
}
public function getUserContacts(username:String, categories:Array=null, startIndex:Number=1, maxResults:Number=50):Number{
var url = (("http://gdata.youtube.com/feeds/api/users/" + username) + "/contacts");
if (((!((categories == null))) && ((categories.length > 0)))){
url = (url + ("/-/" + categories.join("%7C")));
};
url = (url + ((("?alt=json&start-index=" + startIndex) + "&max-results=") + maxResults));
var request:URLRequest = new URLRequest(url);
return (runLoader(request, doUserContactsLoaded, {comment:"contacts", username:username, categories:categories, startIndex:startIndex, maxResults:maxResults}));
}
protected function doRawUrlLoaded(evt:Event):void{
trace("doRawUrlLoaded");
var wrapper:Object = getWrapper((evt.target as URLLoader));
dispatchEvent(new YouTubeEvent(YouTubeEvent.RAW_URL_DATA_RECEIVED, wrapper));
}
protected function doStdFeedLoaded(evt:Event):void{
trace("doStdFeedLoaded");
var wrapper:Object = getWrapper((evt.target as URLLoader));
var feed:VideoFeed = new VideoFeed((evt.target.data as String));
dispatchEvent(new StandardVideoFeedEvent(StandardVideoFeedEvent.STANDARD_VIDEO_DATA_RECEIVED, wrapper.id, wrapper.type, feed));
}
public function getUserSubscriptions(username:String, categories:Array=null, startIndex:Number=1, maxResults:Number=50):Number{
var url = (("http://gdata.youtube.com/feeds/api/users/" + username) + "/subscriptions");
if (((!((categories == null))) && ((categories.length > 0)))){
url = (url + ("/-/" + categories.join("%7C")));
};
url = (url + ((("?alt=json&start-index=" + startIndex) + "&max-results=") + maxResults));
var request:URLRequest = new URLRequest(url);
return (runLoader(request, doSubscriptionsLoaded, {comment:"subscriptions", username:username}));
}
protected function doRelatedVideosLoaded(evt:Event):void{
trace("doRelatedVideosLoaded");
var wrapper:Object = getWrapper((evt.target as URLLoader));
var feed:VideoFeed = new VideoFeed((evt.target.data as String));
dispatchEvent(new VideoFeedEvent(VideoFeedEvent.RELATED_VIDEOS_DATA_RECEIVED, wrapper.id, feed));
}
protected function runLoader(request:URLRequest, doComplete:Function, wrapper:Object):Number{
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, doHttpStatus);
loader.addEventListener(IOErrorEvent.IO_ERROR, doIOError);
loader.addEventListener(ProgressEvent.PROGRESS, handleProgress);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, doSecurityError);
loader.addEventListener(Event.COMPLETE, doComplete);
loader.load(request);
wrapper.id = _requestId++;
wrapper.success = false;
wrapper.loader = loader;
_requestQueue.push(wrapper);
return ((_requestId - 1));
}
protected function doSecurityError(evt:SecurityErrorEvent):void{
trace(("WSClient.doSecurityError(" + evt.toString()));
}
public static function getInstance():YouTubeFeedClient{
if (_instance == null){
_instance = new (YouTubeFeedClient);
};
return (_instance);
}
public static function fromURL(url:String):Number{
return (-1);
}
}
}//package ca.newcommerce.youtube.webservice
Section 41
//JSON (com.adobe.serialization.json.JSON)
package com.adobe.serialization.json {
public class JSON {
public function JSON(){
super();
}
public static function decode(s:String){
var decoder:JSONDecoder = new JSONDecoder(s);
return (decoder.getValue());
}
public static function encode(o:Object):String{
var encoder:JSONEncoder = new JSONEncoder(o);
return (encoder.getString());
}
}
}//package com.adobe.serialization.json
Section 42
//JSONDecoder (com.adobe.serialization.json.JSONDecoder)
package com.adobe.serialization.json {
public class JSONDecoder {
private var value;
private var tokenizer:JSONTokenizer;
private var token:JSONToken;
public function JSONDecoder(s:String){
super();
tokenizer = new JSONTokenizer(s);
nextToken();
value = parseValue();
}
private function parseObject():Object{
var key:String;
var o:Object = new Object();
nextToken();
if (token.type == JSONTokenType.RIGHT_BRACE){
return (o);
};
while (true) {
if (token.type == JSONTokenType.STRING){
key = String(token.value);
nextToken();
if (token.type == JSONTokenType.COLON){
nextToken();
o[key] = parseValue();
nextToken();
if (token.type == JSONTokenType.RIGHT_BRACE){
return (o);
};
if (token.type == JSONTokenType.COMMA){
nextToken();
} else {
tokenizer.parseError(("Expecting } or , but found " + token.value));
};
} else {
tokenizer.parseError(("Expecting : but found " + token.value));
};
} else {
tokenizer.parseError(("Expecting string but found " + token.value));
};
};
return (null);
}
private function parseValue():Object{
switch (token.type){
case JSONTokenType.LEFT_BRACE:
return (parseObject());
case JSONTokenType.LEFT_BRACKET:
return (parseArray());
case JSONTokenType.STRING:
case JSONTokenType.NUMBER:
case JSONTokenType.TRUE:
case JSONTokenType.FALSE:
case JSONTokenType.NULL:
return (token.value);
default:
tokenizer.parseError(("Unexpected " + token.value));
};
return (null);
}
private function nextToken():JSONToken{
return ((token = tokenizer.getNextToken()));
}
public function getValue(){
return (value);
}
private function parseArray():Array{
var a:Array = new Array();
nextToken();
if (token.type == JSONTokenType.RIGHT_BRACKET){
return (a);
};
while (true) {
a.push(parseValue());
nextToken();
if (token.type == JSONTokenType.RIGHT_BRACKET){
return (a);
};
if (token.type == JSONTokenType.COMMA){
nextToken();
} else {
tokenizer.parseError(("Expecting ] or , but found " + token.value));
};
};
return (null);
}
}
}//package com.adobe.serialization.json
Section 43
//JSONEncoder (com.adobe.serialization.json.JSONEncoder)
package com.adobe.serialization.json {
import flash.utils.*;
public class JSONEncoder {
private var jsonString:String;
public function JSONEncoder(value){
super();
jsonString = convertToString(value);
}
private function escapeString(str:String):String{
var ch:String;
var hexCode:String;
var zeroPad:String;
var s:String = "";
var len:Number = str.length;
var i:int;
while (i < len) {
ch = str.charAt(i);
switch (ch){
case "\"":
s = (s + "\\\"");
break;
case "\\":
s = (s + "\\\\");
break;
case "\b":
s = (s + "\\b");
break;
case "\f":
s = (s + "\\f");
break;
case "\n":
s = (s + "\\n");
break;
case "\r":
s = (s + "\\r");
break;
case "\t":
s = (s + "\\t");
break;
default:
if (ch < " "){
hexCode = ch.charCodeAt(0).toString(16);
zeroPad = ((hexCode.length == 2)) ? "00" : "000";
s = (s + (("\\u" + zeroPad) + hexCode));
} else {
s = (s + ch);
};
};
i++;
};
return ((("\"" + s) + "\""));
}
private function arrayToString(a:Array):String{
var s:String = "";
var i:int;
while (i < a.length) {
if (s.length > 0){
s = (s + ",");
};
s = (s + convertToString(a[i]));
i++;
};
return ((("[" + s) + "]"));
}
public function getString():String{
return (jsonString);
}
private function objectToString(o:Object):String{
var value:Object;
var key:String;
var v:XML;
var o = o;
var s = "";
var classInfo:XML = describeType(o);
if (classInfo.@name.toString() == "Object"){
for (key in o) {
value = o[key];
if ((value is Function)){
} else {
if (s.length > 0){
s = (s + ",");
};
s = (s + ((escapeString(key) + ":") + convertToString(value)));
};
};
} else {
for each (v in classInfo..*.(((name() == "variable")) || ((name() == "accessor")))) {
if (s.length > 0){
s = (s + ",");
};
s = (s + ((escapeString(v.@name.toString()) + ":") + convertToString(o[v.@name])));
};
};
return ((("{" + s) + "}"));
}
private function convertToString(value):String{
if ((value is String)){
return (escapeString((value as String)));
};
if ((value is Number)){
return ((isFinite((value as Number))) ? value.toString() : "null");
} else {
if ((value is Boolean)){
return ((value) ? "true" : "false");
} else {
if ((value is Array)){
return (arrayToString((value as Array)));
};
if ((((value is Object)) && (!((value == null))))){
return (objectToString(value));
};
};
};
return ("null");
}
}
}//package com.adobe.serialization.json
Section 44
//JSONParseError (com.adobe.serialization.json.JSONParseError)
package com.adobe.serialization.json {
public class JSONParseError extends Error {
private var _location:int;
private var _text:String;
public function JSONParseError(message:String="", location:int=0, text:String=""){
super(message);
_location = location;
_text = text;
}
public function get location():int{
return (_location);
}
public function get text():String{
return (_text);
}
}
}//package com.adobe.serialization.json
Section 45
//JSONToken (com.adobe.serialization.json.JSONToken)
package com.adobe.serialization.json {
public class JSONToken {
private var _value:Object;
private var _type:int;
public function JSONToken(type:int=-1, value:Object=null){
super();
_type = type;
_value = value;
}
public function get value():Object{
return (_value);
}
public function get type():int{
return (_type);
}
public function set type(value:int):void{
_type = value;
}
public function set value(v:Object):void{
_value = v;
}
}
}//package com.adobe.serialization.json
Section 46
//JSONTokenizer (com.adobe.serialization.json.JSONTokenizer)
package com.adobe.serialization.json {
public class JSONTokenizer {
private var loc:int;
private var ch:String;
private var obj:Object;
private var jsonString:String;
public function JSONTokenizer(s:String){
super();
jsonString = s;
loc = 0;
nextChar();
}
private function skipComments():void{
if (ch == "/"){
nextChar();
switch (ch){
case "/":
do {
nextChar();
} while (((!((ch == "\n"))) && (!((ch == "")))));
nextChar();
break;
case "*":
nextChar();
while (true) {
if (ch == "*"){
nextChar();
if (ch == "/"){
nextChar();
break;
};
} else {
nextChar();
};
if (ch == ""){
parseError("Multi-line comment not closed");
};
};
break;
default:
parseError((("Unexpected " + ch) + " encountered (expecting '/' or '*' )"));
};
};
}
private function isDigit(ch:String):Boolean{
return ((((ch >= "0")) && ((ch <= "9"))));
}
private function readString():JSONToken{
var _local5:String;
var i:int;
var token:JSONToken = new JSONToken();
token.type = JSONTokenType.STRING;
var string:String = "";
nextChar();
while (((!((ch == "\""))) && (!((ch == ""))))) {
if (ch == "\\"){
nextChar();
switch (ch){
case "\"":
string = (string + "\"");
break;
case "/":
string = (string + "/");
break;
case "\\":
string = (string + "\\");
break;
case "b":
string = (string + "\b");
break;
case "f":
string = (string + "\f");
break;
case "n":
string = (string + "\n");
break;
case "r":
string = (string + "\r");
break;
case "t":
string = (string + "\t");
break;
case "u":
_local5 = "";
i = 0;
while (i < 4) {
if (!isHexDigit(nextChar())){
parseError((" Excepted a hex digit, but found: " + ch));
};
_local5 = (_local5 + ch);
i++;
};
string = (string + String.fromCharCode(parseInt(_local5, 16)));
break;
default:
string = (string + ("\\" + ch));
};
} else {
string = (string + ch);
};
nextChar();
};
if (ch == ""){
parseError("Unterminated string literal");
};
nextChar();
token.value = string;
return (token);
}
private function nextChar():String{
return ((ch = jsonString.charAt(loc++)));
}
public function getNextToken():JSONToken{
var _local2:String;
var _local3:String;
var _local4:String;
var token:JSONToken = new JSONToken();
skipIgnored();
switch (ch){
case "{":
token.type = JSONTokenType.LEFT_BRACE;
token.value = "{";
nextChar();
break;
case "}":
token.type = JSONTokenType.RIGHT_BRACE;
token.value = "}";
nextChar();
break;
case "[":
token.type = JSONTokenType.LEFT_BRACKET;
token.value = "[";
nextChar();
break;
case "]":
token.type = JSONTokenType.RIGHT_BRACKET;
token.value = "]";
nextChar();
break;
case ",":
token.type = JSONTokenType.COMMA;
token.value = ",";
nextChar();
break;
case ":":
token.type = JSONTokenType.COLON;
token.value = ":";
nextChar();
break;
case "t":
_local2 = ((("t" + nextChar()) + nextChar()) + nextChar());
if (_local2 == "true"){
token.type = JSONTokenType.TRUE;
token.value = true;
nextChar();
} else {
parseError(("Expecting 'true' but found " + _local2));
};
break;
case "f":
_local3 = (((("f" + nextChar()) + nextChar()) + nextChar()) + nextChar());
if (_local3 == "false"){
token.type = JSONTokenType.FALSE;
token.value = false;
nextChar();
} else {
parseError(("Expecting 'false' but found " + _local3));
};
break;
case "n":
_local4 = ((("n" + nextChar()) + nextChar()) + nextChar());
if (_local4 == "null"){
token.type = JSONTokenType.NULL;
token.value = null;
nextChar();
} else {
parseError(("Expecting 'null' but found " + _local4));
};
break;
case "\"":
token = readString();
break;
default:
if (((isDigit(ch)) || ((ch == "-")))){
token = readNumber();
} else {
if (ch == ""){
return (null);
};
parseError((("Unexpected " + ch) + " encountered"));
};
};
return (token);
}
private function skipWhite():void{
while (isWhiteSpace(ch)) {
nextChar();
};
}
public function parseError(message:String):void{
throw (new JSONParseError(message, loc, jsonString));
}
private function isWhiteSpace(ch:String):Boolean{
return ((((((ch == " ")) || ((ch == "\t")))) || ((ch == "\n"))));
}
private function skipIgnored():void{
skipWhite();
skipComments();
skipWhite();
}
private function isHexDigit(ch:String):Boolean{
var uc:String = ch.toUpperCase();
return (((isDigit(ch)) || ((((uc >= "A")) && ((uc <= "F"))))));
}
private function readNumber():JSONToken{
var token:JSONToken = new JSONToken();
token.type = JSONTokenType.NUMBER;
var input:String = "";
if (ch == "-"){
input = (input + "-");
nextChar();
};
if (!isDigit(ch)){
parseError("Expecting a digit");
};
if (ch == "0"){
input = (input + ch);
nextChar();
if (isDigit(ch)){
parseError("A digit cannot immediately follow 0");
};
} else {
while (isDigit(ch)) {
input = (input + ch);
nextChar();
};
};
if (ch == "."){
input = (input + ".");
nextChar();
if (!isDigit(ch)){
parseError("Expecting a digit");
};
while (isDigit(ch)) {
input = (input + ch);
nextChar();
};
};
if ((((ch == "e")) || ((ch == "E")))){
input = (input + "e");
nextChar();
if ((((ch == "+")) || ((ch == "-")))){
input = (input + ch);
nextChar();
};
if (!isDigit(ch)){
parseError("Scientific notation number needs exponent value");
};
while (isDigit(ch)) {
input = (input + ch);
nextChar();
};
};
var num:Number = Number(input);
if (((isFinite(num)) && (!(isNaN(num))))){
token.value = num;
return (token);
};
parseError((("Number " + num) + " is not valid!"));
return (null);
}
}
}//package com.adobe.serialization.json
Section 47
//JSONTokenType (com.adobe.serialization.json.JSONTokenType)
package com.adobe.serialization.json {
public class JSONTokenType {
public static const NUMBER:int = 11;
public static const FALSE:int = 8;
public static const RIGHT_BRACKET:int = 4;
public static const NULL:int = 9;
public static const TRUE:int = 7;
public static const RIGHT_BRACE:int = 2;
public static const UNKNOWN:int = -1;
public static const COMMA:int = 0;
public static const LEFT_BRACKET:int = 3;
public static const STRING:int = 10;
public static const LEFT_BRACE:int = 1;
public static const COLON:int = 6;
public function JSONTokenType(){
super();
}
}
}//package com.adobe.serialization.json
Section 48
//AMFPHPEvent (com.dontsave.amfphp.events.AMFPHPEvent)
package com.dontsave.amfphp.events {
import flash.events.*;
public class AMFPHPEvent extends Event {
public var resultObj:Object;
public static const FAULT:String = "on_fault";
public static const RESULT:String = "on_result";
public function AMFPHPEvent(type:String, resultObj:Object=null, bubbles:Boolean=false, cancelable:Boolean=false){
this.resultObj = resultObj;
super(type, bubbles, cancelable);
}
override public function clone():Event{
return (new AMFPHPEvent(type, resultObj, bubbles, cancelable));
}
}
}//package com.dontsave.amfphp.events
Section 49
//AbstractAmfWrapper (com.dontsave.amfphp.AbstractAmfWrapper)
package com.dontsave.amfphp {
import flash.events.*;
import flash.net.*;
import com.dontsave.amfphp.events.*;
public class AbstractAmfWrapper extends EventDispatcher {
protected var _responder:Responder;
protected var _gateway:String;
protected var _connection:NetConnection;
public function AbstractAmfWrapper(gateway:String=null, connection:NetConnection=null){
super();
if (gateway){
connect(gateway, connection);
};
}
protected function onAMFFault(resultObj:Object=null):void{
dispatchEvent(new AMFPHPEvent(AMFPHPEvent.FAULT, resultObj));
}
protected function onAMFResult(resultObj:Object=null):void{
dispatchEvent(new AMFPHPEvent(AMFPHPEvent.RESULT, resultObj));
}
public function connect(gateway:String, connection:NetConnection=null):void{
if (connection){
_connection = connection;
} else {
_connection = new NetConnection();
};
_gateway = gateway;
_responder = new Responder(onAMFResult, onAMFFault);
if (!_connection.connected){
_connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, connectionEventHandler);
_connection.addEventListener(IOErrorEvent.IO_ERROR, connectionEventHandler);
_connection.addEventListener(NetStatusEvent.NET_STATUS, connectionEventHandler);
_connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, connectionEventHandler);
_connection.connect(_gateway);
};
}
public function disconnect():void{
_connection.removeEventListener(AsyncErrorEvent.ASYNC_ERROR, connectionEventHandler);
_connection.removeEventListener(IOErrorEvent.IO_ERROR, connectionEventHandler);
_connection.removeEventListener(NetStatusEvent.NET_STATUS, connectionEventHandler);
_connection.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, connectionEventHandler);
_connection.close();
_connection = null;
}
protected function connectionEventHandler(event:Event):void{
dispatchEvent(event);
}
}
}//package com.dontsave.amfphp
Section 50
//RESTProxy (com.dontsave.amfphp.RESTProxy)
package com.dontsave.amfphp {
import flash.net.*;
public class RESTProxy extends AbstractAmfWrapper {
public static const REQUEST:String = "RestProxy.request";
public function RESTProxy(gateway:String, connection:NetConnection=null){
super(gateway, connection);
}
public function request(uri:String, method:String="GET", getVars:Array=null, postVars:Array=null, headers:Array=null, requestID:uint=0):void{
if (!getVars){
getVars = [];
};
if (!postVars){
postVars = [];
};
if (!headers){
headers = [];
};
_connection.call(REQUEST, _responder, uri, method, getVars, postVars, headers, requestID);
}
}
}//package com.dontsave.amfphp
Section 51
//YouTubeCacheLocator (com.dontsave.amfphp.YouTubeCacheLocator)
package com.dontsave.amfphp {
import flash.net.*;
public class YouTubeCacheLocator extends AbstractAmfWrapper {
public static const GET_CACHE_URL:String = "YouTubeCacheLocator.getCacheURL";
public function YouTubeCacheLocator(gateway:String=null, connection:NetConnection=null){
super(gateway, connection);
}
public function getCacheURL(youTubeURL:String):void{
_connection.call(GET_CACHE_URL, this._responder, youTubeURL);
}
}
}//package com.dontsave.amfphp
Section 52
//DSMath (com.dontsave.math.DSMath)
package com.dontsave.math {
public class DSMath {
public function DSMath(){
super();
}
public static function randRange(min:Number, max:Number):Number{
return (((Math.random() * (max - min)) + min));
}
public static function randInt(min:int, max:int):int{
return (int(Math.floor(randRange(min, (max + 1)))));
}
}
}//package com.dontsave.math
Section 53
//YoutubeFlvParserError (com.dontsave.video.services.errors.YoutubeFlvParserError)
package com.dontsave.video.services.errors {
public class YoutubeFlvParserError extends Error {
private const ERROR_MESSAGES:Array;
public static const CANT_PARSE_T:uint = 1;
public static const CANT_PARSE_VIDEO_ID:uint = 2;
public function YoutubeFlvParserError(id:uint){
ERROR_MESSAGES = new Array("Unable to parse T parameter.", "Unable to parse VIDEO_ID parameter.");
name = "FLVLocatorError";
super(((("ERROR #" + id) + ": ") + ERROR_MESSAGES[id]), id);
}
}
}//package com.dontsave.video.services.errors
Section 54
//YouTubeFlvParserEvent (com.dontsave.video.services.events.YouTubeFlvParserEvent)
package com.dontsave.video.services.events {
import flash.events.*;
public class YouTubeFlvParserEvent extends Event {
private var _flvURL:String;
public static const FLV_LOCATED:String = "flv_located";
public static const URL_LOADED:String = "url_loaded";
public static const PARSE_ERROR:String = "parse_error";
public function YouTubeFlvParserEvent(type:String, flvURL:String=null, bubbles:Boolean=false, cancelable:Boolean=false){
this._flvURL = flvURL;
super(type, bubbles, cancelable);
}
override public function clone():Event{
return (new YouTubeFlvParserEvent(type, flvURL, bubbles, cancelable));
}
public function get flvURL():String{
return (_flvURL);
}
}
}//package com.dontsave.video.services.events
Section 55
//YouTubePlayerEvent (com.dontsave.video.services.events.YouTubePlayerEvent)
package com.dontsave.video.services.events {
import flash.events.*;
public class YouTubePlayerEvent extends Event {
public static const STARTED:String = "started";
public static const STOPPED:String = "stopped";
public function YouTubePlayerEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false){
super(type, bubbles, cancelable);
}
}
}//package com.dontsave.video.services.events
Section 56
//YouTubeFlvParser (com.dontsave.video.services.YouTubeFlvParser)
package com.dontsave.video.services {
import com.dontsave.video.services.events.*;
import flash.events.*;
import com.dontsave.amfphp.events.*;
import com.dontsave.amfphp.*;
import com.dontsave.video.services.errors.*;
public class YouTubeFlvParser extends EventDispatcher {
private var _gatewayUri:String;
private var _proxyUri:String;
private var _highQuality:Boolean;
public function YouTubeFlvParser(youtubeURL:String=null, amfPhpGateway:String=null, highQuality:Boolean=false, proxyUri:String=null){
super();
_gatewayUri = amfPhpGateway;
_highQuality = highQuality;
_proxyUri = proxyUri;
if (youtubeURL){
locateFLV(youtubeURL);
};
}
private function parseFLVURL(page:String):void{
var t:String;
var videoID:String;
var url:String;
var cacheLocator:YouTubeCacheLocator;
var regex:RegExp = /"t": "(.*?)"/;
var resultArr:Array = page.match(regex);
if (((!(resultArr)) || ((resultArr.length < 2)))){
throw (new YoutubeFlvParserError(YoutubeFlvParserError.CANT_PARSE_T));
};
t = String(resultArr[1]);
regex = /"video_id": "(.*?)"/;
resultArr = page.match(regex);
if (resultArr.length < 2){
throw (new YoutubeFlvParserError(YoutubeFlvParserError.CANT_PARSE_VIDEO_ID));
};
videoID = String(resultArr[1]);
url = ((("http://www.youtube.com/get_video.php?video_id=" + videoID) + "&t=") + t);
if (_highQuality){
if (_proxyUri){
url = (url + escape("&fmt=18"));
} else {
url = (url + "&fmt=18");
};
};
cacheLocator = new YouTubeCacheLocator(_gatewayUri);
cacheLocator.addEventListener(AMFPHPEvent.RESULT, onCacheFound);
cacheLocator.getCacheURL(url);
}
private function onProxyFail(event:AMFPHPEvent):void{
dispatchEvent(event);
RESTProxy(event.target).disconnect();
}
private function locateFLV(youtubeUrl:String):void{
var restProxy:RESTProxy = new RESTProxy(_gatewayUri);
restProxy.request(youtubeUrl);
restProxy.addEventListener(AMFPHPEvent.RESULT, onRESTProxyResult);
restProxy.addEventListener(AMFPHPEvent.FAULT, onProxyFail);
}
private function onRESTProxyResult(event:AMFPHPEvent):void{
var event = event;
dispatchEvent(new YouTubeFlvParserEvent(YouTubeFlvParserEvent.URL_LOADED));
parseFLVURL(String(event.resultObj["content"]));
//unresolved jump
var _slot1 = e;
dispatchEvent(new YouTubeFlvParserEvent(YouTubeFlvParserEvent.PARSE_ERROR));
RESTProxy(event.target).disconnect();
}
private function onCacheFound(event:AMFPHPEvent):void{
var url:String;
if (_proxyUri){
url = ((_proxyUri + "?mimeType=video/x-flv&url=") + escape(String(event.resultObj)));
} else {
url = String(event.resultObj);
};
dispatchEvent(new YouTubeFlvParserEvent(YouTubeFlvParserEvent.FLV_LOCATED, String(url)));
}
}
}//package com.dontsave.video.services
Section 57
//YouTubePlayer (com.dontsave.video.services.YouTubePlayer)
package com.dontsave.video.services {
import com.dontsave.video.services.events.*;
import flash.events.*;
import flash.net.*;
import flash.media.*;
import com.dontsave.amfphp.events.*;
import flash.display.*;
public class YouTubePlayer extends Sprite {
protected var _highQuality:Boolean;
protected var _amfPhpGateway:String;
protected var _video:Video;
protected var _connection:NetConnection;
protected var _nStream:NetStream;
protected var _autoPlay:Boolean;// = true
public var loop:Boolean;// = false
protected var _client:Object;
public var bufferTime:Number;// = 0.1
protected var _volume:Number;// = 1
protected var _proxyUri:String;
protected var _flvURL:String;
public function YouTubePlayer(amfPhpGateway:String=null, proxyUri:String=null){
_connection = new NetConnection();
_video = new Video();
super();
_amfPhpGateway = amfPhpGateway;
_proxyUri = proxyUri;
}
public function startVideo(beginTime:Number=0):void{
_connection.connect(null);
_nStream = new NetStream(_connection);
_nStream.client = this;
_nStream.play(((_flvURL + "&begin=") + beginTime));
_nStream.client = (_client = new YouTubePlayerClient());
volume = _volume;
_video.attachNetStream(_nStream);
addChild(_video);
_nStream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
}
public function get videoHeight():Number{
return (this._video.height);
}
public function findVideo(youTubeId:String, highQuality:Boolean=false, autoPlay:Boolean=true):void{
_highQuality = highQuality;
_autoPlay = autoPlay;
var parser:YouTubeFlvParser = new YouTubeFlvParser(((("http://www.youtube.com/watch?v=" + youTubeId) + "&rand=") + Math.random()), _amfPhpGateway, _highQuality, _proxyUri);
parser.addEventListener(YouTubeFlvParserEvent.FLV_LOCATED, onFLVLocated);
parser.addEventListener(YouTubeFlvParserEvent.PARSE_ERROR, onFLVError);
parser.addEventListener(AMFPHPEvent.FAULT, onFLVError);
}
protected function onNetStatus(e:NetStatusEvent):void{
if (e["info"]["code"] == "NetStream.Play.Stop"){
if (loop){
_nStream.seek(0);
};
dispatchEvent(new YouTubePlayerEvent(YouTubePlayerEvent.STOPPED));
};
if (e["info"]["code"] == "NetStream.Play.Start"){
dispatchEvent(new YouTubePlayerEvent(YouTubePlayerEvent.STARTED));
};
if (e["info"]["code"] == "NetStream.Play.FileStructureInvalid"){
dispatchEvent(new YouTubeFlvParserEvent(YouTubeFlvParserEvent.PARSE_ERROR));
};
}
public function togglePause():void{
_nStream.togglePause();
}
public function get videoWidth():Number{
return (this._video.width);
}
protected function onFLVLocated(event:YouTubeFlvParserEvent):void{
_flvURL = event.flvURL;
if (_autoPlay){
startVideo();
};
dispatchEvent(event);
}
public function get volume():Number{
return (_volume);
}
public function getVideo():Video{
return (_video);
}
public function stopVideo():void{
_nStream.close();
}
public function setVideoDimensions(w:Number, h:Number):void{
_video.width = w;
_video.height = h;
}
public function set smoothing(b:Boolean):void{
_video.smoothing = b;
}
public function unloadVideo():void{
if (_nStream){
_nStream.close();
};
_nStream = null;
_video.attachNetStream(null);
if (contains(_video)){
removeChild(_video);
};
}
public function set volume(volume:Number):void{
_volume = volume;
if (_nStream){
_nStream.soundTransform = new SoundTransform(volume);
};
}
protected function onFLVError(event:YouTubeFlvParserEvent):void{
dispatchEvent(event);
}
public function get smoothing():Boolean{
return (_video.smoothing);
}
public function seek(time:Number):void{
if (_nStream){
_nStream.seek(time);
};
}
}
}//package com.dontsave.video.services
Section 58
//YouTubePlayerClient (com.dontsave.video.services.YouTubePlayerClient)
package com.dontsave.video.services {
public class YouTubePlayerClient {
public function YouTubePlayerClient(){
super();
}
public function onMetaData(infoObj:Object):void{
}
}
}//package com.dontsave.video.services
Section 59
//FramesUI (com.dontsave.youtube.FramesUI)
package com.dontsave.youtube {
import flash.events.*;
import fl.transitions.*;
import flash.net.*;
import com.dontsave.video.services.*;
import ws.tink.events.*;
import ws.tink.managers.*;
import ws.tink.core.*;
import flash.display.*;
import fl.transitions.easing.*;
import flash.utils.*;
import flash.external.*;
import flash.ui.*;
public class FramesUI extends Sprite {
private var _player:YouTubePlayer;
public var volume:Number;
private var _volume:MovieClip;
private var _shuffle:Boolean;
private var _lib:Library;
private var FramesUISWF:Class;
private var _timer:Timer;
private var _videoThumbH:Number;
private var _fadeTween:Tween;
private var _zoom:MovieClip;
private var _startVideo:Boolean;
private var _dragNotifier:MovieClip;
private var _videoThumbW:Number;
private var _contact:MovieClip;
private var _startZoomed:Boolean;
private var _videoPlayer:MovieClip;
public static const TIMEOUT:uint = 3;
public static const START_TRACK:String = "start_track";
public static const HEIGHT:uint = 23;
public static const ZOOM_OUT:String = "zoom_out";
public static const VOLUME_CHANGE:String = "volume_change";
public static const PAN:String = "pan";
public function FramesUI(player:YouTubePlayer, startZoomed:Boolean=false, startVideo:Boolean=false){
FramesUISWF = FramesUI_FramesUISWF;
super();
_startZoomed = startZoomed;
_startVideo = startVideo;
_player = player;
_lib = LibraryManager.libraryManager.createLibrary("lib");
_lib.embedSWFS(FramesUISWF);
_lib.addEventListener(LibraryEvent.EMBED_COMPLETE, onEmbedComplete);
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function showVideo(event:MouseEvent=null):void{
_videoPlayer.gotoAndStop(2);
MovieClip(_videoPlayer.bg).removeEventListener(MouseEvent.CLICK, showVideo);
MovieClip(_videoPlayer.bg).addEventListener(MouseEvent.CLICK, hideVideo);
MovieClip(_videoPlayer.watchOnYouTube).addEventListener(MouseEvent.CLICK, watchOnYouTube);
MovieClip(_videoPlayer.watchOnYouTube).buttonMode = true;
var holder:MovieClip = MovieClip(_videoPlayer["videoHolder"]);
if (!_videoThumbW){
_videoThumbW = holder.holderBG.width;
};
if (!_videoThumbH){
_videoThumbH = holder.holderBG.height;
};
if (holder.contains(holder.holderBG)){
holder.removeChild(holder.holderBG);
};
holder.addChild(_player);
holder.width = _videoThumbW;
holder.height = _videoThumbH;
arrange();
_timer.stop();
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function enableTrack():void{
MovieClip(_zoom.track).buttonMode = true;
MovieClip(_zoom.track).addEventListener(MouseEvent.CLICK, startTrack);
MovieClip(_zoom.track).alpha = 1;
MovieClip(_zoom.zoomOut).buttonMode = true;
MovieClip(_zoom.zoomOut).addEventListener(MouseEvent.CLICK, zoomOut);
MovieClip(_zoom.zoomOut).alpha = 1;
}
private function startTrack(event:MouseEvent=null):void{
dispatchEvent(new Event(START_TRACK, false, false));
if (_zoom.currentFrame == 2){
disableAll();
} else {
MovieClip(_zoom.zoomIn).buttonMode = false;
MovieClip(_zoom.zoomIn).removeEventListener(MouseEvent.CLICK, startTrack);
MovieClip(_zoom.zoomIn).alpha = 0.2;
};
}
private function contactOut(event:MouseEvent):void{
_contact.gotoAndStop(1);
arrange();
}
private function moveSlider(event:Event):void{
var slider:MovieClip = MovieClip(_volume.slider);
volume = (MovieClip(slider["fill"]).scaleX = (((slider.mouseX / slider.width))<0) ? 0 : (slider.mouseX / slider.width));
dispatchEvent(new Event(VOLUME_CHANGE, false, false));
}
private function contactOver(event:MouseEvent):void{
_contact.gotoAndStop(2);
arrange();
}
private function disableAll():void{
MovieClip(_zoom.pan).buttonMode = false;
MovieClip(_zoom.pan).removeEventListener(MouseEvent.CLICK, startPan);
MovieClip(_zoom.pan).alpha = 0.2;
MovieClip(_zoom.track).buttonMode = false;
MovieClip(_zoom.track).removeEventListener(MouseEvent.CLICK, startTrack);
MovieClip(_zoom.track).alpha = 0.2;
MovieClip(_zoom.zoomOut).buttonMode = false;
MovieClip(_zoom.zoomOut).removeEventListener(MouseEvent.CLICK, zoomOut);
MovieClip(_zoom.zoomOut).alpha = 0.2;
}
private function enablePan():void{
MovieClip(_zoom.pan).buttonMode = true;
MovieClip(_zoom.pan).addEventListener(MouseEvent.CLICK, startPan);
MovieClip(_zoom.pan).alpha = 1;
MovieClip(_zoom.zoomOut).buttonMode = true;
MovieClip(_zoom.zoomOut).addEventListener(MouseEvent.CLICK, zoomOut);
MovieClip(_zoom.zoomOut).alpha = 1;
}
private function onAddedToStage(event:Event):void{
stage.addEventListener(Event.RESIZE, onStageResize);
_timer = new Timer((TIMEOUT * 1000));
_timer.start();
_timer.addEventListener(TimerEvent.TIMER, onTimer);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
stage.addEventListener(Event.RESIZE, onStageResize);
_shuffle = YouTubeFrames(parent).shuffle;
}
public function onZoomOut():void{
if (!_shuffle){
MovieClip(_zoom).gotoAndStop(1);
MovieClip(_zoom.zoomIn).addEventListener(MouseEvent.CLICK, startTrack);
MovieClip(_zoom.zoomIn).buttonMode = true;
MovieClip(_zoom.zoomIn).alpha = 1;
} else {
MovieClip(_zoom).gotoAndStop(1);
MovieClip(_zoom.zoomIn).addEventListener(MouseEvent.CLICK, startPan);
MovieClip(_zoom.zoomIn).buttonMode = true;
MovieClip(_zoom.zoomIn).alpha = 1;
};
arrange();
}
private function onTimer(event:TimerEvent):void{
fadeOut();
}
private function onSliderMouseDown(event:MouseEvent):void{
stage.addEventListener(MouseEvent.MOUSE_UP, onSliderMouseUp);
MovieClip(_volume.slider).addEventListener(Event.ENTER_FRAME, moveSlider);
}
private function onEmbedComplete(event:LibraryEvent):void{
var Asset:Class;
Asset = _lib.getDefinition("ShowVideoUI");
_videoPlayer = new (Asset);
addChild(_videoPlayer);
_videoPlayer.stop();
MovieClip(_videoPlayer.bg).addEventListener(MouseEvent.CLICK, showVideo);
MovieClip(_videoPlayer.bg).buttonMode = true;
Asset = _lib.getDefinition("VolumeUI");
_volume = new (Asset);
addChild(_volume);
MovieClip(_volume.slider).addEventListener(MouseEvent.MOUSE_DOWN, onSliderMouseDown);
MovieClip(_volume.slider).buttonMode = true;
Asset = _lib.getDefinition("ZoomUI");
_zoom = new (Asset);
addChild(_zoom);
_zoom.stop();
if (_shuffle){
MovieClip(_zoom.zoomIn).addEventListener(MouseEvent.CLICK, startPan);
} else {
MovieClip(_zoom.zoomIn).addEventListener(MouseEvent.CLICK, startTrack);
};
MovieClip(_zoom.zoomIn).buttonMode = true;
Asset = _lib.getDefinition("ContactUI");
_contact = new (Asset);
addChild(_contact);
_contact.stop();
MovieClip(_contact).addEventListener(MouseEvent.MOUSE_UP, contactClick);
MovieClip(_contact).addEventListener(MouseEvent.MOUSE_OVER, contactOver);
MovieClip(_contact).addEventListener(MouseEvent.MOUSE_OUT, contactOut);
_contact.buttonMode = true;
alignToStage();
arrange();
if (_startZoomed){
if (_shuffle){
startPan();
} else {
startTrack();
};
};
if (_startVideo){
showVideo();
};
}
private function arrange():void{
_volume.x = ((_videoPlayer.x + _videoPlayer.bg.width) + 4);
_zoom.x = ((_volume.x + _volume.bg.width) + 4);
_contact.x = ((stage.stageWidth - _contact.bg.width) - x);
}
private function moveSliderTo(ratio:Number){
var slider:MovieClip = MovieClip(_volume.slider);
volume = (MovieClip(slider["fill"]).scaleX = ratio);
}
private function fadeOut():void{
_fadeTween = new Tween(this, "alpha", None.easeNone, this.alpha, 0, 0.5, true);
_fadeTween.addEventListener(TweenEvent.MOTION_FINISH, onFadeOut);
Mouse.hide();
}
private function contactClick(event:MouseEvent):void{
navigateToURL(new URLRequest("mailto:you@yooouuutuuube.com"), "_self");
}
private function onFadeOut(event:TweenEvent):void{
this.visible = false;
}
private function watchOnYouTube(event:MouseEvent):void{
ExternalInterface.call("watchOnYouTube", YouTubeFrames(parent).url);
}
public function onStartTrack(event:MouseEvent=null):void{
if (_zoom.currentFrame != 2){
_zoom.gotoAndStop(2);
arrange();
disableAll();
};
enablePan();
}
public function onStartPan(event:MouseEvent=null):void{
if (!_shuffle){
enableTrack();
} else {
_zoom.gotoAndStop(3);
MovieClip(_zoom.zoomOut).buttonMode = true;
MovieClip(_zoom.zoomOut).addEventListener(MouseEvent.CLICK, zoomOut);
MovieClip(_zoom.zoomOut).alpha = 1;
};
var Asset:Class = _lib.getDefinition("DragNotifier");
_dragNotifier = new (Asset);
centerDragNotifier();
parent.addChild(_dragNotifier);
}
private function startPan(event:MouseEvent=null):void{
if (!_shuffle){
disableAll();
} else {
MovieClip(_zoom.zoomIn).buttonMode = false;
MovieClip(_zoom.zoomIn).removeEventListener(MouseEvent.CLICK, startTrack);
MovieClip(_zoom.zoomIn).alpha = 0.2;
};
dispatchEvent(new Event(PAN));
}
private function onSliderMouseUp(event:MouseEvent):void{
MovieClip(_volume.slider).removeEventListener(Event.ENTER_FRAME, moveSlider);
stage.removeEventListener(MouseEvent.MOUSE_UP, onSliderMouseUp);
}
private function hideVideo(event:MouseEvent):void{
MovieClip(_videoPlayer["videoHolder"]).removeChild(_player);
_videoPlayer.gotoAndStop(1);
MovieClip(_videoPlayer.bg).removeEventListener(MouseEvent.CLICK, hideVideo);
MovieClip(_videoPlayer.bg).addEventListener(MouseEvent.CLICK, showVideo);
arrange();
_timer.start();
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function centerDragNotifier():void{
if (_dragNotifier){
_dragNotifier.x = ((stage.stageWidth / 2) - (_dragNotifier.width / 2));
_dragNotifier.y = ((stage.stageHeight / 2) - (_dragNotifier.height / 2));
};
}
private function onStageResize(event:Event):void{
alignToStage();
arrange();
centerDragNotifier();
}
private function onMouseMove(event:MouseEvent):void{
_timer.reset();
_timer.start();
if (_fadeTween){
_fadeTween.stop();
};
alpha = 1;
visible = true;
Mouse.show();
}
private function zoomOut(event:MouseEvent):void{
dispatchEvent(new Event(ZOOM_OUT));
if (!_shuffle){
disableAll();
} else {
MovieClip(_zoom.zoomOut).buttonMode = false;
MovieClip(_zoom.zoomOut).removeEventListener(MouseEvent.CLICK, zoomOut);
MovieClip(_zoom.zoomOut).alpha = 0.2;
};
}
private function alignToStage():void{
x = 0;
y = (stage.stageHeight - HEIGHT);
}
}
}//package com.dontsave.youtube
Section 60
//FramesUI_FramesUISWF (com.dontsave.youtube.FramesUI_FramesUISWF)
package com.dontsave.youtube {
import mx.core.*;
public class FramesUI_FramesUISWF extends ByteArrayAsset {
}
}//package com.dontsave.youtube
Section 61
//KeepVidPlayer (com.dontsave.youtube.KeepVidPlayer)
package com.dontsave.youtube {
import com.dontsave.video.services.events.*;
import flash.events.*;
import flash.net.*;
import com.dontsave.video.services.*;
import newcommerce.keepvid.*;
public class KeepVidPlayer extends YouTubePlayer {
private var _hackStream:NetStream;
protected var _kvClient:KeepVidClient;
private var _beginTime:Number;
public function KeepVidPlayer(amfPhpGateway:String=null, proxyUri:String=null){
super(amfPhpGateway, proxyUri);
}
public function removeHackStream():void{
_video.attachNetStream(_nStream);
}
public function attachHackStream():void{
_video.attachNetStream(_hackStream);
}
override protected function onNetStatus(e:NetStatusEvent):void{
if (e["info"]["code"] == "NetStream.Play.Stop"){
if (loop){
_nStream.seek(0);
};
dispatchEvent(new YouTubePlayerEvent(YouTubePlayerEvent.STOPPED));
};
if (e["info"]["code"] == "NetStream.Play.Start"){
dispatchEvent(new YouTubePlayerEvent(YouTubePlayerEvent.STARTED));
};
if (e["info"]["code"] == "NetStream.Play.FileStructureInvalid"){
dispatchEvent(new YouTubeFlvParserEvent(YouTubeFlvParserEvent.PARSE_ERROR));
};
}
private function onHackStatus(e:NetStatusEvent):void{
startRealVideo();
}
override public function startVideo(beginTime:Number=0):void{
_beginTime = beginTime;
_connection.connect(null);
_hackStream = new NetStream(_connection);
_hackStream.checkPolicyFile = true;
_hackStream.play("HACK");
_hackStream.client = new YouTubePlayerClient();
_hackStream.addEventListener(NetStatusEvent.NET_STATUS, onHackStatus);
}
public function startRealVideo():void{
_nStream = new NetStream(_connection);
_nStream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
_nStream.client = (_client = new YouTubePlayerClient());
_nStream.bufferTime = this.bufferTime;
if (_proxyUri){
_nStream.play(((_proxyUri + "?mimeType=video/x-flv&url=") + escape(((_flvURL + "&begin=") + _beginTime))));
} else {
_nStream.play(((_flvURL + "&begin=") + _beginTime));
};
volume = _volume;
_video.attachNetStream(_nStream);
addChild(_video);
}
}
}//package com.dontsave.youtube
Section 62
//YouTubeFrames (com.dontsave.youtube.YouTubeFrames)
package com.dontsave.youtube {
import ca.newcommerce.youtube.events.*;
import com.dontsave.video.services.events.*;
import flash.events.*;
import fl.transitions.*;
import ca.newcommerce.youtube.webservice.*;
import ca.newcommerce.youtube.data.*;
import flash.display.*;
import flash.text.*;
import fl.transitions.easing.*;
import flash.utils.*;
import com.dontsave.math.*;
import flash.external.*;
import flash.geom.*;
public class YouTubeFrames extends Sprite {
private const FOCUS_TRANSITION_FRAMES:uint = 90;
private const START_VOL:Number = 1;
private const PROXY:String = "/api/proxy.php";
private const PLAYER_ALPHA:Number = 1;
private const AMFPHP_GATEWAY:String = "/api/amfphp/gateway.php";
private const MAX_BMPDATA_W:uint = 2880;
private const DEFAULT_YOUTUBE_ID:String = "rand";
private var _player:KeepVidPlayer;
private var _notifier:TextField;
private var _grid:Bitmap;
private var _hasWrapped:Boolean;
private var _gridHolder:Sprite;
private var _ui:FramesUI;
private var _dragPoint:Object;
private var _currentRow:uint;
private var _tween0:Tween;
private var _tween1:Tween;
private var _height:Number;
private var _tween3:Tween;
private var _tween2:Tween;
private var _videoData:VideoData;
private var _gotoPoint:Object;
private var _fc:YouTubeFeedClient;
private var _grid0:Bitmap;
private var _grid3:Bitmap;
private var _url:String;
private var _grid1:Bitmap;
private var _rows:uint;
private var _shuffle:Boolean;// = false
private var _dragging:Boolean;
private var _shuffleArray:Array;
private var _width:Number;
private var _search:String;
private var _cols:uint;
private var _index:uint;// = 0
private var _zoomedIn:Boolean;// = false
private var _currentCol:uint;
private var _divisors:Array;
private var _startZoomed:Boolean;// = false
private var _showVideo:Boolean;// = false
public function YouTubeFrames(){
super();
_url = this.root.loaderInfo.parameters["id"];
if (((!(_url)) || ((_url == "")))){
_url = DEFAULT_YOUTUBE_ID;
};
_search = this.root.loaderInfo.parameters["search"];
if ((((_search == "")) || (!(_search)))){
_search = "";
};
if (((((this.root.loaderInfo.parameters["rows"]) && (!((this.root.loaderInfo.parameters["rows"] == ""))))) && ((Number(this.root.loaderInfo.parameters["rows"]) > 0)))){
if (this.root.loaderInfo.parameters["rows"] == "rand"){
_rows = getRandAmt();
} else {
_rows = Math.round(this.root.loaderInfo.parameters["rows"]);
};
} else {
_rows = getRandAmt();
if (_rows == MAX_BMPDATA_W){
_cols = 1;
};
};
if (((((this.root.loaderInfo.parameters["cols"]) && (!((this.root.loaderInfo.parameters["cols"] == ""))))) && ((Number(this.root.loaderInfo.parameters["cols"]) > 0)))){
if (this.root.loaderInfo.parameters["cols"] == "rand"){
if (this.root.loaderInfo.parameters["rows"] == "rand"){
_cols = _rows;
} else {
_cols = getRandAmt();
};
} else {
_cols = Math.round(this.root.loaderInfo.parameters["cols"]);
};
} else {
_cols = getRandAmt();
if (_cols == MAX_BMPDATA_W){
_rows = 1;
};
};
if ((((this.root.loaderInfo.parameters["shuffle"] == "true")) || ((this.root.loaderInfo.parameters["shuffle"] == "1")))){
_shuffle = true;
} else {
if (this.root.loaderInfo.parameters["shuffle"] == "rand"){
_shuffle = ((Math.random())<0.5) ? true : false;
};
};
if ((((this.root.loaderInfo.parameters["startZoom"] == "true")) || ((this.root.loaderInfo.parameters["startZoom"] == "1")))){
_startZoomed = true;
};
if ((((this.root.loaderInfo.parameters["showVideo"] == "true")) || ((this.root.loaderInfo.parameters["showVideo"] == "1")))){
_showVideo = true;
};
if (_rows > MAX_BMPDATA_W){
_rows = MAX_BMPDATA_W;
};
if (_cols > MAX_BMPDATA_W){
_cols = MAX_BMPDATA_W;
};
_width = (MAX_BMPDATA_W / _cols);
_height = (MAX_BMPDATA_W / _rows);
if (_width < 1){
_width = 1;
};
if (_height < 1){
_height = 1;
};
if ((((_url == "rand")) || (!((_search == ""))))){
getRandID();
} else {
initPlayer();
};
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
createGrid();
var f:TextFormat = new TextFormat("Arial", 10, 0xFFFFFF, false);
_notifier = new TextField();
_notifier.autoSize = TextFieldAutoSize.LEFT;
_notifier.text = "LOADING...";
_notifier.setTextFormat(f);
addChild(_notifier);
}
private function doStopDrag(event:Event):void{
_dragging = false;
}
private function allocateShuffle(e:Event=null):void{
var rnd:uint;
var tmp:uint;
if (_notifier){
_notifier.removeEventListener(Event.RENDER, allocateShuffle);
};
var i:uint;
while (i < (_rows * _cols)) {
rnd = DSMath.randInt(0, (_shuffleArray.length - 1));
tmp = _shuffleArray[rnd];
_shuffleArray[rnd] = i;
_shuffleArray[i] = tmp;
i++;
};
}
private function onVideoFound(event:YouTubeFlvParserEvent):void{
}
private function onVideoStarted(event:YouTubePlayerEvent):void{
if (contains(_notifier)){
removeChild(_notifier);
};
addEventListener(Event.ENTER_FRAME, updateFrames);
_player.setVideoDimensions(_width, _height);
_player.alpha = PLAYER_ALPHA;
_player.smoothing = true;
_player.width = _width;
_player.height = _height;
_player.volume = START_VOL;
_ui = new FramesUI(_player, _startZoomed, _showVideo);
addChild(_ui);
_ui.addEventListener(FramesUI.VOLUME_CHANGE, onVolumeChange);
_ui.addEventListener(FramesUI.PAN, startPan);
_ui.addEventListener(FramesUI.START_TRACK, startTrack);
_ui.addEventListener(FramesUI.ZOOM_OUT, zoomOut);
}
private function onFindTitle(event:VideoDataEvent):void{
_videoData = event.video;
ExternalInterface.call("setTitle", _videoData.title, _videoData.authors.first().username, _rows, _cols, Math.round(_width), Math.round(_height), _shuffle);
}
private function startTrack(e:Event=null):void{
var xPoint:Number;
var yPoint:Number;
disableDrag();
removeEventListener(Event.ENTER_FRAME, dragGrid);
_zoomedIn = true;
_tween0 = new Tween(_gridHolder, "scaleX", Strong.easeInOut, _gridHolder.scaleX, 1, FOCUS_TRANSITION_FRAMES, false);
_tween1 = new Tween(_gridHolder, "scaleY", Strong.easeInOut, _gridHolder.scaleY, 1, FOCUS_TRANSITION_FRAMES, false);
var index:uint = ((_index + FOCUS_TRANSITION_FRAMES) % (_rows * _cols));
var row:uint = Math.floor((index / _cols));
var col:uint = (index % _cols);
xPoint = (((((_gridHolder.width * (1 / _gridHolder.scaleX)) / 2) - (col * _width)) + stage.stageWidth) - _width);
yPoint = (((((_gridHolder.height * (1 / _gridHolder.scaleY)) / 2) - (row * _height)) + stage.stageHeight) - _height);
_tween2 = new Tween(_gridHolder, "x", Strong.easeInOut, _gridHolder.x, xPoint, FOCUS_TRANSITION_FRAMES, false);
_tween3 = new Tween(_gridHolder, "y", Strong.easeInOut, _gridHolder.y, yPoint, FOCUS_TRANSITION_FRAMES, false);
_tween3.addEventListener(TweenEvent.MOTION_FINISH, onStartTrack);
_gridHolder.addChild(_grid0);
_grid0.x = (_grid.x - _grid0.width);
_grid0.y = (_grid.y - _grid0.height);
_gridHolder.addChild(_grid1);
_grid1.x = _grid.x;
_grid1.y = (_grid.y - _grid1.height);
_gridHolder.addChild(_grid3);
_grid3.x = (_grid.x - _grid3.width);
_grid3.y = _grid.y;
}
private function initPlayer():void{
_player = new KeepVidPlayer(AMFPHP_GATEWAY);
_player.findVideo(_url, false, true);
_player.addEventListener(YouTubeFlvParserEvent.FLV_LOCATED, onVideoFound);
_player.addEventListener(YouTubePlayerEvent.STARTED, onVideoStarted);
_player.addEventListener(YouTubeFlvParserEvent.PARSE_ERROR, onFLVERROR);
_player.loop = true;
findTitle();
}
private function findTitle():void{
_fc = YouTubeFeedClient.getInstance();
_fc.addEventListener(VideoDataEvent.VIDEO_INFO_RECEIVED, onFindTitle);
_fc.getVideo(_url);
}
private function getRandAmt():uint{
var i:uint;
if (!_divisors){
_divisors = new Array();
i = 0;
while (i <= 2880) {
if ((2880 % i) == 0){
_divisors.push(i);
};
i++;
};
};
return (uint(_divisors[DSMath.randInt(0, (_divisors.length - 1))]));
}
private function disableDrag():void{
_gridHolder.removeEventListener(MouseEvent.MOUSE_DOWN, doStartDrag);
_gridHolder.removeEventListener(MouseEvent.MOUSE_UP, doStopDrag);
stage.removeEventListener(Event.MOUSE_LEAVE, doStopDrag);
_gridHolder.buttonMode = false;
}
private function onStartTrack(event:TweenEvent=null):void{
this.addEventListener(Event.ENTER_FRAME, lockOn);
_ui.onStartTrack();
}
private function fitGridToStage():void{
_gridHolder.width = stage.stageWidth;
_gridHolder.height = stage.stageHeight;
_gridHolder.x = (stage.stageWidth / 2);
_gridHolder.y = (stage.stageHeight / 2);
}
private function createGrid():void{
var gridData:BitmapData = new BitmapData(MAX_BMPDATA_W, MAX_BMPDATA_W, true, 4278190080);
var gridData0:BitmapData = gridData.clone();
_grid = new Bitmap(gridData, "auto", true);
_grid1 = new Bitmap(gridData, "auto", true);
_grid0 = new Bitmap(gridData0, "auto", true);
_grid3 = new Bitmap(gridData0, "auto", true);
_gridHolder = new Sprite();
_gridHolder.addChild(_grid);
addChildAt(_gridHolder, 0);
_gridHolder.x = (stage.stageWidth / 2);
_gridHolder.y = (stage.stageHeight / 2);
_grid.x = (-(_grid.width) / 2);
_grid.y = (-(_grid.height) / 2);
stage.addEventListener(Event.RESIZE, onStageResize);
fitGridToStage();
if (_shuffle){
createShuffleArray();
};
}
private function lockOn(event:Event):void{
var xPoint:Number;
var yPoint:Number;
xPoint = ((((_grid.width / 2) - (_currentCol * _width)) + stage.stageWidth) - _width);
yPoint = ((((_grid.height / 2) - (_currentRow * _height)) + stage.stageHeight) - _height);
_gridHolder.x = Math.round(xPoint);
_gridHolder.y = Math.round(yPoint);
}
private function doStartDrag(event:MouseEvent):void{
_dragging = true;
_dragPoint = {x:_gridHolder.mouseX, y:_gridHolder.mouseY};
removeEventListener(Event.ENTER_FRAME, dragGrid);
addEventListener(Event.ENTER_FRAME, dragGrid);
}
public function get url():String{
return (_url);
}
private function onFLVERROR(event:YouTubeFlvParserEvent):void{
if (contains(_notifier)){
removeChild(_notifier);
};
var f:TextFormat = new TextFormat("Arial", 10, 0xFFFFFF, false);
_notifier = new TextField();
_notifier.autoSize = TextFieldAutoSize.LEFT;
if (_search != ""){
_notifier.text = "THERE WAS AN ERROR GETTING THIS RESULT. GO BACK AND USE A DIFFERENT SEARCH FOR NOW, FRIEND.";
} else {
_notifier.text = "FRIEND, THERE WAS AN ERROR CONNECTING TO THIS VIDEO ON YOUTUBE. GO BACK AND TRY ANOTHER.";
};
_notifier.setTextFormat(f);
addChild(_notifier);
}
private function zoomOut(event:Event):void{
disableDrag();
removeEventListener(Event.ENTER_FRAME, dragGrid);
this.removeEventListener(Event.ENTER_FRAME, lockOn);
var sX:Number = (stage.stageWidth / _grid.width);
var sY:Number = (stage.stageHeight / _grid.height);
_tween0 = new Tween(_gridHolder, "x", Strong.easeOut, _gridHolder.x, (stage.stageWidth / 2), 1, true);
_tween1 = new Tween(_gridHolder, "y", Strong.easeOut, _gridHolder.y, (stage.stageHeight / 2), 1, true);
_tween2 = new Tween(_gridHolder, "scaleX", Strong.easeOut, _gridHolder.scaleX, sX, 1, true);
_tween3 = new Tween(_gridHolder, "scaleY", Strong.easeOut, _gridHolder.scaleY, sY, 1, true);
_tween2.addEventListener(TweenEvent.MOTION_FINISH, onZoomOut);
}
private function dragGrid(event:Event):void{
if (_dragging){
_gotoPoint = new Object();
_gotoPoint.x = (_gridHolder.x + (-(_dragPoint.x) + _gridHolder.mouseX));
_gotoPoint.y = (_gridHolder.y + (-(_dragPoint.y) + _gridHolder.mouseY));
};
_gridHolder.x = (_gridHolder.x + ((-(_gridHolder.x) + _gotoPoint.x) / 5));
_gridHolder.y = (_gridHolder.y + ((-(_gridHolder.y) + _gotoPoint.y) / 5));
if ((((((Math.round(_gridHolder.x) == Math.round(_gotoPoint.x))) && ((Math.round(_gridHolder.y) == Math.round(_gotoPoint.y))))) && ((_dragging == false)))){
removeEventListener(Event.ENTER_FRAME, dragGrid);
};
boundGrid();
}
private function onAddedToStage(event:Event):void{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
}
private function onZoomOut(event:TweenEvent):void{
_ui.onZoomOut();
_zoomedIn = false;
if (_gridHolder.contains(_grid0)){
_gridHolder.removeChild(_grid0);
_gridHolder.removeChild(_grid1);
_gridHolder.removeChild(_grid3);
};
fitGridToStage();
}
private function updateFrames(event:Event):void{
var frameData:BitmapData = new BitmapData((_width + 0.5), (_height + 0.5), false, 0);
var index:uint = (_shuffleArray) ? _shuffleArray[_index] : _index;
var row:uint = Math.floor((index / _cols));
var col:uint = (index % _cols);
_currentRow = row;
_currentCol = col;
var x:Number = (col * _width);
var y:Number = (row * _height);
var m:Matrix = new Matrix();
m.tx = x;
m.ty = y;
_player.attachHackStream();
frameData.draw(_player);
_player.removeHackStream();
_grid.bitmapData.draw(frameData, m, null, null, null, true);
m.ty = ((row)==(_rows - 1)) ? 0 : (m.ty + _height);
_grid0.bitmapData.draw(frameData, m, null, null, null, true);
if (++_index >= (_rows * _cols)){
_hasWrapped = true;
_index = 0;
};
}
private function onGetRandID(event:VideoFeedEvent):void{
var f:TextFormat;
var event = event;
_url = event.feed.next().actualId;
//unresolved jump
var _slot1 = error;
if (contains(_notifier)){
removeChild(_notifier);
};
f = new TextFormat("Arial", 10, 0xFFFFFF, false);
_notifier = new TextField();
_notifier.autoSize = TextFieldAutoSize.LEFT;
if (_search != ""){
_notifier.text = "FRIEND, THERE WERE NO RESULTS FOUND. GO BACK AND TRY AGAIN.";
} else {
_notifier.text = "FRIEND, THERE WAS AN ERROR CONNECTING TO YOUTUBE. GO BACK AND TRY AGAIN.";
};
_notifier.setTextFormat(f);
addChild(_notifier);
initPlayer();
}
private function onStartPan(event:TweenEvent):void{
if (_gridHolder.contains(_grid0)){
_gridHolder.removeChild(_grid0);
_gridHolder.removeChild(_grid1);
_gridHolder.removeChild(_grid3);
};
_gridHolder.addEventListener(MouseEvent.MOUSE_DOWN, doStartDrag);
_gridHolder.addEventListener(MouseEvent.MOUSE_UP, doStopDrag);
stage.addEventListener(Event.MOUSE_LEAVE, doStopDrag);
_gridHolder.buttonMode = true;
_ui.onStartPan();
}
private function startPan(event:Event=null):void{
if (_shuffle){
_tween0 = new Tween(_gridHolder, "scaleX", Strong.easeInOut, _gridHolder.scaleX, 1, FOCUS_TRANSITION_FRAMES, false);
_tween1 = new Tween(_gridHolder, "scaleY", Strong.easeInOut, _gridHolder.scaleY, 1, FOCUS_TRANSITION_FRAMES, false);
_zoomedIn = true;
_tween0.addEventListener(TweenEvent.MOTION_FINISH, onStartPan);
} else {
this.removeEventListener(Event.ENTER_FRAME, lockOn);
_tween2 = new Tween(_gridHolder, "x", Strong.easeOut, _gridHolder.x, (_grid.width / 2), 1, true);
_tween3 = new Tween(_gridHolder, "y", Strong.easeOut, _gridHolder.y, (_grid.height / 2), 1, true);
_tween2.addEventListener(TweenEvent.MOTION_FINISH, onStartPan);
};
}
private function boundGrid():void{
if ((_gridHolder.x + _grid.x) > 0){
_gridHolder.x = -(_grid.x);
_gotoPoint.x = _gridHolder.x;
} else {
if ((_gridHolder.x + _grid.x) < (-(_grid.width) + stage.stageWidth)){
_gridHolder.x = ((-(_grid.width) + stage.stageWidth) - _grid.x);
_gotoPoint.x = _gridHolder.x;
};
};
if ((_gridHolder.y + _grid.y) > 0){
_gridHolder.y = -(_grid.y);
_gotoPoint.y = _gridHolder.y;
} else {
if ((_gridHolder.y + _grid.x) < (-(_grid.height) + stage.stageHeight)){
_gridHolder.y = ((-(_grid.height) + stage.stageHeight) - _grid.y);
_gotoPoint.y = _gridHolder.y;
};
};
}
private function onVolumeChange(event:Event):void{
_player.volume = _ui.volume;
if (_player.volume > 1){
_player.volume = 1;
};
}
private function onStageResize(event:Event):void{
if (!_zoomedIn){
fitGridToStage();
};
}
private function getRandID():void{
var fc:YouTubeFeedClient = YouTubeFeedClient.getInstance();
var resultNum:uint = ((_search)!="") ? 1 : DSMath.randInt(1, 500);
var sort:String = ((_search)!="") ? YouTubeFeedClient.ORDER_BY_RELEVANCE : YouTubeFeedClient.ORDER_BY_PUBLISHED;
fc.getVideos(_search, "", null, null, null, null, sort, YouTubeFeedClient.RACY_INCLUDE, resultNum, 1);
fc.addEventListener(VideoFeedEvent.VIDEO_DATA_RECEIVED, onGetRandID);
}
public function get shuffle():Boolean{
return (_shuffle);
}
private function createShuffleArray():void{
var f:TextFormat;
var t:Timer;
_shuffleArray = new Array();
var amt:uint = (_rows * _cols);
if (amt >= 1000000){
f = new TextFormat("Arial", 10, 0xFFFFFF, false);
t = new Timer(500, 1);
t.addEventListener(TimerEvent.TIMER, allocateShuffle);
t.start();
} else {
allocateShuffle();
};
}
}
}//package com.dontsave.youtube
Section 63
//None (fl.transitions.easing.None)
package fl.transitions.easing {
public class None {
public function None(){
super();
}
public static function easeOut(t:Number, b:Number, c:Number, d:Number):Number{
return ((((c * t) / d) + b));
}
public static function easeIn(t:Number, b:Number, c:Number, d:Number):Number{
return ((((c * t) / d) + b));
}
public static function easeInOut(t:Number, b:Number, c:Number, d:Number):Number{
return ((((c * t) / d) + b));
}
public static function easeNone(t:Number, b:Number, c:Number, d:Number):Number{
return ((((c * t) / d) + b));
}
}
}//package fl.transitions.easing
Section 64
//Strong (fl.transitions.easing.Strong)
package fl.transitions.easing {
public class Strong {
public function Strong(){
super();
}
public static function easeOut(t:Number, b:Number, c:Number, d:Number):Number{
t = ((t / d) - 1);
return (((c * (((((t * t) * t) * t) * t) + 1)) + b));
}
public static function easeIn(t:Number, b:Number, c:Number, d:Number):Number{
t = (t / d);
return (((((((c * t) * t) * t) * t) * t) + b));
}
public static function easeInOut(t:Number, b:Number, c:Number, d:Number):Number{
t = (t / (d / 2));
if (t < 1){
return ((((((((c / 2) * t) * t) * t) * t) * t) + b));
};
t = (t - 2);
return ((((c / 2) * (((((t * t) * t) * t) * t) + 2)) + b));
}
}
}//package fl.transitions.easing
Section 65
//Tween (fl.transitions.Tween)
package fl.transitions {
import flash.events.*;
import flash.display.*;
import flash.utils.*;
public class Tween extends EventDispatcher {
private var _position:Number;// = NAN
public var prevTime:Number;// = NAN
public var prevPos:Number;// = NAN
public var isPlaying:Boolean;// = false
private var _fps:Number;// = NAN
private var _time:Number;// = NAN
public var begin:Number;// = NAN
private var _finish:Number;// = NAN
public var change:Number;// = NAN
public var looping:Boolean;// = false
private var _intervalID:uint;// = 0
public var func:Function;
private var _timer:Timer;// = null
private var _startTime:Number;// = NAN
public var prop:String;// = ""
private var _duration:Number;// = NAN
public var obj:Object;// = null
public var useSeconds:Boolean;// = false
protected static var _mc:MovieClip = new MovieClip();
public function Tween(obj:Object, prop:String, func:Function, begin:Number, finish:Number, duration:Number, useSeconds:Boolean=false){
func = function (t:Number, b:Number, c:Number, d:Number):Number{
return ((((c * t) / d) + b));
};
super();
if (!arguments.length){
return;
};
this.obj = obj;
this.prop = prop;
this.begin = begin;
this.position = begin;
this.duration = duration;
this.useSeconds = useSeconds;
if ((func is Function)){
this.func = func;
};
this.finish = finish;
this._timer = new Timer(100);
this.start();
}
public function continueTo(finish:Number, duration:Number):void{
this.begin = this.position;
this.finish = finish;
if (!isNaN(duration)){
this.duration = duration;
};
this.start();
}
protected function startEnterFrame():void{
var milliseconds:Number;
if (isNaN(this._fps)){
_mc.addEventListener(Event.ENTER_FRAME, this.onEnterFrame, false, 0, true);
} else {
milliseconds = (1000 / this._fps);
this._timer.delay = milliseconds;
this._timer.addEventListener(TimerEvent.TIMER, this.timerHandler, false, 0, true);
this._timer.start();
};
this.isPlaying = true;
}
public function stop():void{
this.stopEnterFrame();
this.dispatchEvent(new TweenEvent(TweenEvent.MOTION_STOP, this._time, this._position));
}
private function fixTime():void{
if (this.useSeconds){
this._startTime = (getTimer() - (this._time * 1000));
};
}
public function set FPS(fps:Number):void{
var oldIsPlaying:Boolean = this.isPlaying;
this.stopEnterFrame();
this._fps = fps;
if (oldIsPlaying){
this.startEnterFrame();
};
}
public function get finish():Number{
return ((this.begin + this.change));
}
public function get duration():Number{
return (this._duration);
}
protected function stopEnterFrame():void{
if (isNaN(this._fps)){
_mc.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
} else {
this._timer.stop();
};
this.isPlaying = false;
}
public function set time(t:Number):void{
this.prevTime = this._time;
if (t > this.duration){
if (this.looping){
this.rewind((t - this._duration));
this.update();
this.dispatchEvent(new TweenEvent(TweenEvent.MOTION_LOOP, this._time, this._position));
} else {
if (this.useSeconds){
this._time = this._duration;
this.update();
};
this.stop();
this.dispatchEvent(new TweenEvent(TweenEvent.MOTION_FINISH, this._time, this._position));
};
} else {
if (t < 0){
this.rewind();
this.update();
} else {
this._time = t;
this.update();
};
};
}
public function getPosition(t:Number=NaN):Number{
if (isNaN(t)){
t = this._time;
};
return (this.func(t, this.begin, this.change, this._duration));
}
public function set finish(value:Number):void{
this.change = (value - this.begin);
}
public function set duration(d:Number):void{
this._duration = ((d)<=0) ? Infinity : d;
}
public function get position():Number{
return (this.getPosition(this._time));
}
public function setPosition(p:Number):void{
this.prevPos = this._position;
if (this.prop.length){
this.obj[this.prop] = (this._position = p);
};
this.dispatchEvent(new TweenEvent(TweenEvent.MOTION_CHANGE, this._time, this._position));
}
public function resume():void{
this.fixTime();
this.startEnterFrame();
this.dispatchEvent(new TweenEvent(TweenEvent.MOTION_RESUME, this._time, this._position));
}
public function fforward():void{
this.time = this._duration;
this.fixTime();
}
protected function onEnterFrame(event:Event):void{
this.nextFrame();
}
public function yoyo():void{
this.continueTo(this.begin, this.time);
}
public function nextFrame():void{
if (this.useSeconds){
this.time = ((getTimer() - this._startTime) / 1000);
} else {
this.time = (this._time + 1);
};
}
protected function timerHandler(timerEvent:TimerEvent):void{
this.nextFrame();
timerEvent.updateAfterEvent();
}
public function get FPS():Number{
return (this._fps);
}
public function rewind(t:Number=0):void{
this._time = t;
this.fixTime();
this.update();
}
public function set position(p:Number):void{
this.setPosition(p);
}
public function get time():Number{
return (this._time);
}
private function update():void{
this.setPosition(this.getPosition(this._time));
}
public function start():void{
this.rewind();
this.startEnterFrame();
this.dispatchEvent(new TweenEvent(TweenEvent.MOTION_START, this._time, this._position));
}
public function prevFrame():void{
if (!this.useSeconds){
this.time = (this._time - 1);
};
}
}
}//package fl.transitions
Section 66
//TweenEvent (fl.transitions.TweenEvent)
package fl.transitions {
import flash.events.*;
public class TweenEvent extends Event {
public var position:Number;// = NAN
public var time:Number;// = NAN
public static const MOTION_START:String = "motionStart";
public static const MOTION_STOP:String = "motionStop";
public static const MOTION_LOOP:String = "motionLoop";
public static const MOTION_CHANGE:String = "motionChange";
public static const MOTION_FINISH:String = "motionFinish";
public static const MOTION_RESUME:String = "motionResume";
public function TweenEvent(type:String, time:Number, position:Number, bubbles:Boolean=false, cancelable:Boolean=false){
super(type, bubbles, cancelable);
this.time = time;
this.position = position;
}
override public function clone():Event{
return (new TweenEvent(this.type, this.time, this.position, this.bubbles, this.cancelable));
}
}
}//package fl.transitions
Section 67
//ByteArrayAsset (mx.core.ByteArrayAsset)
package mx.core {
import flash.utils.*;
public class ByteArrayAsset extends ByteArray implements IFlexAsset {
mx_internal static const VERSION:String = "3.2.0.3958";
public function ByteArrayAsset(){
super();
}
}
}//package mx.core
Section 68
//IFlexAsset (mx.core.IFlexAsset)
package mx.core {
public interface IFlexAsset {
}
}//package mx.core
Section 69
//mx_internal (mx.core.mx_internal)
package mx.core {
public namespace mx_internal = "http://www.adobe.com/2006/flex/mx/internal";
}//package mx.core
Section 70
//KeepVidClient (newcommerce.keepvid.KeepVidClient)
package newcommerce.keepvid {
import flash.events.*;
import flash.net.*;
public class KeepVidClient extends EventDispatcher {
protected var _proxyUrl:String;
protected var _requestQueue:Array;
protected var _conn:NetConnection;
protected var _requestSequence:Number;// = 0
protected var _baseUrl:String;// = "http://keepvid.com"
private static var _instance:KeepVidClient;
private static var _allowConstructor:Boolean;
public function KeepVidClient(){
super();
if (!_allowConstructor){
throw (new Error("KeepVidClient is a singleton and may not be instantiated. Use KeepVidClient.getInstance()."));
};
}
public function get proxyUrl():String{
return (_proxyUrl);
}
public function set proxyUrl(value:String):void{
_proxyUrl = value;
}
protected function getWrapperFromResult(result:Object):Object{
var requestId:Number = parseInt(result.requestId);
return (getWrapperById(requestId));
}
protected function placeCall(id:Number, responder:Responder, method:String="GET", getVars:Array=null, postVars:Array=null, headers:Array=null):void{
if (getVars == null){
getVars = [];
};
if (postVars == null){
postVars = [];
};
if (headers == null){
headers = [];
};
_conn.call("RESTProxy.request", responder, _baseUrl, method, getVars, postVars, headers, id);
}
protected function doIOError(evt:IOErrorEvent):void{
trace(("doIOError: " + evt.text));
}
public function connect(amfPHPGateway:String):void{
_proxyUrl = amfPHPGateway;
_requestQueue = [];
_conn = new NetConnection();
_conn.addEventListener(AsyncErrorEvent.ASYNC_ERROR, doAsyncError);
_conn.addEventListener(NetStatusEvent.NET_STATUS, doNetStatus);
_conn.addEventListener(IOErrorEvent.IO_ERROR, doIOError);
_conn.addEventListener(SecurityErrorEvent.SECURITY_ERROR, doSecurityError);
_conn.connect(_proxyUrl);
}
protected function doSecurityError(evt:SecurityErrorEvent):void{
trace(("doSecurityError: " + evt.text));
}
protected function getWrapperById(requestId:Number):Object{
var i:Number = 0;
while (i < _requestQueue.length) {
if (_requestQueue[i].id == requestId){
return (_requestQueue[i]);
};
i++;
};
trace((("wrapper with requestId:" + requestId) + " not found. Returning null"));
return (null);
}
protected function doFault(fault:Object):void{
trace(("doFault:" + fault));
}
public function getFLVUrl(watchUrl:String):Number{
var responder:Responder = new Responder(doFLVUrl, doFault);
var wrapper:Object = getWrapper(responder, "FLVUrl");
var getVars:Array = [("url=" + encodeURI(watchUrl)), ("rand=" + Math.random())];
placeCall(wrapper.id, responder, "GET", getVars);
return (wrapper.id);
}
protected function doAsyncError(evt:AsyncErrorEvent):void{
trace(("doAsyncError: " + evt.text));
}
protected function doFLVUrl(result:Object):void{
var ldUrl:String;
var hdUrl:String;
var response:String = result.content;
var wrapper:Object = getWrapperFromResult(result);
var filterFlv:RegExp = /"(\/save-video.flv\?.*)" class="link" target="_blank">›› Download ‹‹<\/a> <em>\(get_video.flv/g;
var filterYTFlv:RegExp = /"(http:\/\/www.youtube.com\/get_video\?.*)" class="link" target="_blank">›› Download ‹‹<\/a> <em>\(get_video.flv/g;
var filterMp4:RegExp = /"(\/save-video.mp4\?.*)" class="link" target="_blank">›› Download ‹‹<\/a> <em>\(video.mp4/g;
var filterVimeoLD:RegExp = /"(http:\/\/www.vimeo.com\/moogaloop\/play\/clip:[0-9]+\/[0-9a-f]+\/[0-9]+\/video\.flv\?q=)"/g;
var filterVimeoHD:RegExp = /"(http:\/\/www.vimeo.com\/moogaloop\/play\/clip:[0-9]+\/[0-9a-f]+\/[0-9]+\/video_hd\.flv\?q=hd)"/g;
var flvResult:Object = filterFlv.exec(response);
var flvYTResult:Object = filterYTFlv.exec(response);
var vimeoLDResult:Object = filterVimeoLD.exec(response);
var mp4Result:Object = filterMp4.exec(response);
var vimeoHDResult:Object = filterVimeoHD.exec(response);
if (flvResult != null){
ldUrl = (_baseUrl + flvResult[1]);
} else {
if (flvYTResult != null){
ldUrl = flvYTResult[1];
} else {
if (vimeoLDResult != null){
ldUrl = vimeoLDResult[1];
};
};
};
if (mp4Result != null){
hdUrl = (_baseUrl + mp4Result[1]);
} else {
if (vimeoHDResult != null){
hdUrl = vimeoHDResult[1];
};
};
dispatchEvent(new KeepVidEvent(KeepVidEvent.FLV_URL_RECEIVED, ldUrl, hdUrl));
}
protected function doNetStatus(evt:NetStatusEvent):void{
trace(("doNetStatus: " + evt.info));
}
protected function getWrapper(responder:Responder, type:String):Object{
var wrapper:Object = {};
wrapper.id = _requestSequence++;
wrapper.success = false;
wrapper.type = type;
wrapper.responder = responder;
_requestQueue.push(wrapper);
return (wrapper);
}
public static function getInstance():KeepVidClient{
if (_instance == null){
_allowConstructor = true;
_instance = new (KeepVidClient);
_allowConstructor = false;
};
return (_instance);
}
}
}//package newcommerce.keepvid
Section 71
//KeepVidEvent (newcommerce.keepvid.KeepVidEvent)
package newcommerce.keepvid {
import flash.events.*;
public class KeepVidEvent extends Event {
protected var _hdUrl:String;
protected var _ldUrl:String;
public static const FLV_URL_RECEIVED:String = "flv_url_received";
public function KeepVidEvent(type:String, ldUrl:String, hdUrl:String){
_ldUrl = ldUrl;
_hdUrl = hdUrl;
super(type);
}
public function get hdUrl():String{
return (_hdUrl);
}
public function get ldUrl():String{
return (_ldUrl);
}
}
}//package newcommerce.keepvid
Section 72
//Library (ws.tink.core.Library)
package ws.tink.core {
import flash.events.*;
import flash.net.*;
import ws.tink.events.*;
import flash.display.*;
import flash.utils.*;
public class Library extends EventDispatcher {
private var _runtimeCompletes:Array;
private var _embeddedComplete:Boolean;
private var _bytesLoaded:Number;// = 0
private var _embeddedLoaders:Array;
private var _enterFrameDispatcher:Sprite;
private var _runtimeLoaders:Array;
private var _name:String;
private var _runtimeComplete:Boolean;
private var _bytesTotal:Number;// = 0
public function Library(name:String){
super();
_name = name;
initialize();
}
public function embedSWFS(... _args):void{
var loader:Loader;
var SWF:Class;
if (_enterFrameDispatcher.hasEventListener(Event.ENTER_FRAME)){
_enterFrameDispatcher.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
};
_embeddedComplete = false;
var num:Number = _args.length;
var i:int;
while (i < num) {
SWF = Class(_args[i]);
loader = new Loader();
loader.loadBytes((new (SWF) as ByteArray));
_embeddedLoaders.push(loader);
i++;
};
_enterFrameDispatcher.addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true);
}
public function get name():String{
return (_name);
}
public function reset():void{
destroy();
initialize();
}
public function get bytesLoaded():Number{
return (_bytesLoaded);
}
public function getDefinition(className:String):Class{
var loader:Loader;
var numLoaders:int;
var i:int;
numLoaders = _embeddedLoaders.length;
i = 0;
while (i < numLoaders) {
loader = Loader(_embeddedLoaders[i]);
if (loader.contentLoaderInfo.applicationDomain.hasDefinition(className)){
return ((loader.contentLoaderInfo.applicationDomain.getDefinition(className) as Class));
};
i++;
};
numLoaders = _runtimeLoaders.length;
i = 0;
while (i < numLoaders) {
loader = Loader(_runtimeLoaders[i]);
if (loader.contentLoaderInfo.applicationDomain.hasDefinition(className)){
return ((loader.contentLoaderInfo.applicationDomain.getDefinition(className) as Class));
};
i++;
};
throw (new ReferenceError((("ReferenceError: Error #1065: Variable " + className) + " is not defined.")));
}
public function get bytesTotal():Number{
return (_bytesTotal);
}
public function loadSWFS(... _args):void{
_runtimeComplete = false;
var num:int = _args.length;
var i:int;
while (i < num) {
loadSWF((_args[i] as String));
i++;
};
}
public function contains(className:String):Boolean{
var loader:Loader;
var numLoaders:Number = _embeddedLoaders.length;
var i:int;
while (i < numLoaders) {
loader = Loader(_embeddedLoaders[i]);
if (loader.contentLoaderInfo.applicationDomain.hasDefinition(className)){
return (true);
};
i++;
};
return (false);
}
public function get embeddedComplete():Boolean{
return (_embeddedComplete);
}
private function checkLoadersProgress(complete:Boolean=false):void{
var loader:Loader;
var bytesTotal:Number = 0;
var bytesLoaded:Number = 0;
complete = true;
var numLoaders:int = _runtimeLoaders.length;
var i:int;
while (i < numLoaders) {
loader = Loader(_runtimeLoaders[i]);
bytesTotal = (bytesTotal + loader.contentLoaderInfo.bytesTotal);
bytesLoaded = (bytesLoaded + loader.contentLoaderInfo.bytesLoaded);
if (!_runtimeCompletes[i]){
complete = false;
};
i++;
};
_bytesLoaded = bytesLoaded;
_bytesTotal = bytesTotal;
if (complete){
_runtimeComplete = true;
dispatchEvent(new LibraryEvent(LibraryEvent.LOAD_COMPLETE, false, false));
} else {
dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS, false, false, bytesLoaded, bytesTotal));
};
}
private function onLoaderProgress(event:ProgressEvent):void{
checkLoadersProgress();
}
private function initialize():void{
_embeddedLoaders = new Array();
_runtimeLoaders = new Array();
_runtimeCompletes = new Array();
_enterFrameDispatcher = new Sprite();
_bytesLoaded = 0;
_bytesTotal = 0;
}
public function embedSWF(ClassName:Class):void{
var loader:Loader = new Loader();
loader.loadBytes((new (ClassName) as ByteArray));
_embeddedLoaders.push(loader);
}
private function onLoaderComplete(event:Event):void{
var loader:Loader = Loader(event.target.loader);
loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onLoaderProgress);
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoaderComplete);
var numLoaders:int = _runtimeLoaders.length;
var i:int;
while (i < numLoaders) {
if (loader == Loader(_runtimeLoaders[i])){
_runtimeCompletes[i] = true;
break;
};
i++;
};
checkLoadersProgress(true);
}
public function get runtimeComplete():Boolean{
return (_runtimeComplete);
}
private function onEnterFrame(event:Event):void{
_enterFrameDispatcher.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
_embeddedComplete = true;
dispatchEvent(new LibraryEvent(LibraryEvent.EMBED_COMPLETE, false, false));
}
public function get complete():Boolean{
return (((_embeddedComplete) && (_runtimeComplete)));
}
public function destroy():void{
var loader:Loader;
var numLoaders:int;
var i:int;
if (_enterFrameDispatcher.hasEventListener(Event.ENTER_FRAME)){
_enterFrameDispatcher.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
};
numLoaders = _runtimeLoaders.length;
i = 0;
while (i < numLoaders) {
loader = Loader(_runtimeLoaders[i]);
if (!_runtimeCompletes[i]){
loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onLoaderProgress);
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoaderComplete);
loader.close();
} else {
loader.unload();
};
i++;
};
numLoaders = _embeddedLoaders.length;
i = 0;
while (i < numLoaders) {
loader = Loader(_embeddedLoaders[i]);
loader.unload();
i++;
};
_embeddedLoaders = null;
_runtimeLoaders = null;
_runtimeCompletes = null;
_enterFrameDispatcher = null;
_name = null;
_bytesLoaded = undefined;
_bytesTotal = undefined;
}
public function loadSWF(url:String):void{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoaderProgress, false, 0, true);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete, false, 0, true);
loader.load(new URLRequest(url));
_runtimeLoaders.push(loader);
_runtimeCompletes.push(false);
}
}
}//package ws.tink.core
Section 73
//LibraryManagerError (ws.tink.errors.LibraryManagerError)
package ws.tink.errors {
public class LibraryManagerError extends Error {
private const ERROR_MSG:Array;
private const BASE_ERROR_CODE:uint = 3000;
public static const LIBRARY_NOT_FOUND:uint = 1000;
public static const DUPLICATE_LIBRARY_NAME:uint = 3002;
public static const FORCE_SINGLETON:uint = 3001;
public function LibraryManagerError(errCode:uint){
ERROR_MSG = new Array("LibraryManager is to be used as a Singleton and should only be accessed through LibraryManager.libraryManager.", "There is already a library with this name. Libraries stored in the LibraryManager must be unique names.", "The supplied library name could not be found in the LibraryManager.");
super(((("Error #" + errCode) + ": ") + ERROR_MSG[(errCode - BASE_ERROR_CODE)]), errCode);
name = "LibraryManagerError";
}
}
}//package ws.tink.errors
Section 74
//LibraryEvent (ws.tink.events.LibraryEvent)
package ws.tink.events {
import flash.events.*;
public class LibraryEvent extends Event {
public static var LOAD_COMPLETE:String = "loadComplete";
public static var EMBED_COMPLETE:String = "embedComplete";
public function LibraryEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false){
super(type, bubbles, cancelable);
}
override public function clone():Event{
return (new LibraryEvent(type, bubbles, cancelable));
}
}
}//package ws.tink.events
Section 75
//LibraryManager (ws.tink.managers.LibraryManager)
package ws.tink.managers {
import ws.tink.core.*;
import ws.tink.errors.*;
public class LibraryManager {
private var _libraries:Array;
private static var _instance:LibraryManager;
private static var _allowConstructor:Boolean;
public function LibraryManager(){
super();
if (!_allowConstructor){
throw (new LibraryManagerError(LibraryManagerError.FORCE_SINGLETON));
};
initialize();
}
private function initialize():void{
_libraries = new Array();
}
public function addLibrary(library:Library, name:String):void{
if (getLibraryIndex(name) == -1){
_libraries.push(library);
};
throw (new LibraryManagerError(LibraryManagerError.DUPLICATE_LIBRARY_NAME));
}
public function getLibrary(name:String):Library{
var libraryIndex:int = getLibraryIndex(name);
return (((libraryIndex)==-1) ? null : Library(_libraries[libraryIndex]));
}
public function contains(name:String):Boolean{
return (!((getLibraryIndex(name) == -1)));
}
public function removeLibrary(name:String, destroy:Boolean=false):void{
var library:Library;
var index:int = getLibraryIndex(name);
if (index != -1){
library = Library(_libraries.splice(index, 1)[0]);
if (destroy){
library.destroy();
};
};
throw (new LibraryManagerError(LibraryManagerError.LIBRARY_NOT_FOUND));
}
private function getLibraryIndex(name:String):int{
var numLibraries:int = _libraries.length;
var i:int;
while (i < numLibraries) {
if (name == Library(_libraries[i]).name){
return (i);
};
i++;
};
return (-1);
}
public function createLibrary(name:String):Library{
var library:Library;
if (getLibraryIndex(name) == -1){
library = new Library(name);
_libraries.push(library);
return (library);
};
throw (new LibraryManagerError(LibraryManagerError.DUPLICATE_LIBRARY_NAME));
}
public static function get libraryManager():LibraryManager{
if (!_instance){
_allowConstructor = true;
_instance = new (LibraryManager);
_allowConstructor = false;
};
return (_instance);
}
}
}//package ws.tink.managers