metadataAdd( data, socket = false, skipMetadata = false ) {
		//debug('Agent grab metadata')
		
		
		// if images is here just return
		if ( data.image !== '' && data.image != null ) {
			//debug('have image', data.image);
			return Promise.resolve({ image: data.image, images: data.images });
		}
		
		if ( skipMetadata ) {
			return Promise.resolve({ image: false, images: [] });
		}
		
		// is cache false
		if( isFalse(data.cache) ) {
			return this.epg.agent.metadata(data)
			.then( results => {
				this.emit(['metadataAdd', data.iden], results, socket);
				this.broadcast(['metadataAdd', data.iden], results, socket);
			});
		}
		
		var Schedules = this.epg.Models.Schedules;
		
		var remember = Object.assign({}, data);
		
		// cache
		return this.epg.agent.metadata( data )
		.then( results => {
			if(typeof results.error === 'object' && results.error.message) {
				debug('Error with metadata result');
				this.emit(['metadataAdd', remember.iden], results, socket)
				debug(result.error.message);
				return false;
			} 
			
			if ( Array.isArray( results ) && results.length > 0 ) {	
				return new Promise( ( resolve, reject ) => {
					let ret = {};
					if ( results[0].programID == data.programID ) {
						ret.images = stringMe( results[0].data );
						if ( typeof results[0].data[0] === 'object' ) {
							ret.image = results[0].data[0].uri
						}
					}
						
					//debug('results celebrityAdd', remember.personId )
					try {
						Schedules.update({ programID: data.programID }, ret, (err, newdoc) => {
							if(err) {
								debug('error adding metadata info', err);
								this.emit('error',{ error: { message: 'Error adding metadata info for ' + remember.name + ' from database' }}, socket);
								resolve(ret)
							} else {
								this.emit(['metadataAdd', remember.iden], newdoc, socket);
								resolve(ret)
							}
						});	
					} catch(e) {
						resolve(ret);
					}							
				});
			} else {
				return {}
			}
		}).catch((e) => { debug(e); return {}; });
	}
/** 
	 * get metadata from source and save to cache
	 * */
get metadata from source and save to cache
get metadata from source and save to cache
metadataAdd( data, socket = false, skipMetadata = false ) {
		if ( data.image !== '' && data.image != null ) {
			return Promise.resolve({ image: data.image, images: data.images });
		}
		if ( skipMetadata ) {
			return Promise.resolve({ image: false, images: [] });
		}
		if( isFalse(data.cache) ) {
			return this.epg.agent.metadata(data)
			.then( results => {
				this.emit(['metadataAdd', data.iden], results, socket);
				this.broadcast(['metadataAdd', data.iden], results, socket);
			});
		}
		var Schedules = this.epg.Models.Schedules;
		var remember = Object.assign({}, data);
		return this.epg.agent.metadata( data )
		.then( results => {
			if(typeof results.error === 'object' && results.error.message) {
				debug('Error with metadata result');
				this.emit(['metadataAdd', remember.iden], results, socket)
				debug(result.error.message);
				return false;
			} 
			if ( Array.isArray( results ) && results.length > 0 ) {	
				return new Promise( ( resolve, reject ) => {
					let ret = {};
					if ( results[0].programID == data.programID ) {
						ret.images = stringMe( results[0].data );
						if ( typeof results[0].data[0] === 'object' ) {
							ret.image = results[0].data[0].uri
						}
					}
					try {
						Schedules.update({ programID: data.programID }, ret, (err, newdoc) => {
							if(err) {
								debug('error adding metadata info', err);
								this.emit('error',{ error: { message: 'Error adding metadata info for ' + remember.name + ' from database' }}, socket);
								resolve(ret)
							} else {
								this.emit(['metadataAdd', remember.iden], newdoc, socket);
								resolve(ret)
							}
						});	
					} catch(e) {
						resolve(ret);
					}							
				});
			} else {
				return {}
			}
		}).catch((e) => { debug(e); return {}; });
	}
metadataAdd ( data , socket = false , skipMetadata = false ) { if ( data . image !== '' && data . image != null ) { return Promise . resolve ( { image : data . image , images : data . images } ) ; } if ( skipMetadata ) { return Promise . resolve ( { image : false , images : [ ] } ) ; } if ( isFalse ( data . cache ) ) { return this . epg . agent . metadata ( data ) . then ( results => { this . emit ( [ 'metadataAdd' , data . iden ] , results , socket ) ; this . broadcast ( [ 'metadataAdd' , data . iden ] , results , socket ) ; } ) ; } var Schedules = this . epg . Models . Schedules ; var remember = Object . assign ( { } , data ) ; return this . epg . agent . metadata ( data ) . then ( results => { if ( typeof results . error === 'object' && results . error . message ) { debug ( 'Error with metadata result' ) ; this . emit ( [ 'metadataAdd' , remember . iden ] , results , socket ) debug ( result . error . message ) ; return false ; } if ( Array . isArray ( results ) && results . length > 0 ) { return new Promise ( ( resolve , reject ) => { let ret = { } ; if ( results [ 0 ] . programID == data . programID ) { ret . images = stringMe ( results [ 0 ] . data ) ; if ( typeof results [ 0 ] . data [ 0 ] === 'object' ) { ret . image = results [ 0 ] . data [ 0 ] . uri } } try { Schedules . update ( { programID : data . programID } , ret , ( err , newdoc ) => { if ( err ) { debug ( 'error adding metadata info' , err ) ; this . emit ( 'error' , { error : { message : 'Error adding metadata info for ' + remember . name + ' from database' } } , socket ) ; resolve ( ret ) } else { this . emit ( [ 'metadataAdd' , remember . iden ] , newdoc , socket ) ; resolve ( ret ) } } ) ; } catch ( e ) { resolve ( ret ) ; } } ) ; } else { return { } } } ) . catch ( ( e ) => { debug ( e ) ; return { } ; } ) ; }
get metadata from source and save to cache
get metadata from source and save to cache
//debug('Agent grab metadata') // if images is here just return //debug('have image', data.image); // is cache false // cache //debug('results celebrityAdd', remember.personId )