📄 searchservice.as
字号:
} break; case SearchResultEvent.SONG_DOWNLOAD_LOCATION_SEARCH_RESULT: for each (resultNode in inXML.children()) { var songDownloadSearchResult:MediaSearchResult = new MediaSearchResult(); // SearchResult Properties songDownloadSearchResult.index = resultNode.childIndex() + len; songDownloadSearchResult.name = resultNode.NAMESPACE_AUDIO_ALT::Url; songDownloadSearchResult.url = resultNode.NAMESPACE_AUDIO_ALT::Url; songDownloadSearchResult.publisher = resultNode.NAMESPACE_AUDIO_ALT::Source; songDownloadSearchResult.fileFormat = resultNode.NAMESPACE_AUDIO_ALT::Format; songDownloadSearchResult.restrictions = resultNode.NAMESPACE_AUDIO_ALT::Restrictions; songDownloadSearchResult.duration = resultNode.NAMESPACE_AUDIO_ALT::Length; songDownloadSearchResult.quality = resultNode.NAMESPACE_AUDIO_ALT::Quality; songDownloadSearchResult.price = resultNode.NAMESPACE_AUDIO_ALT::Price; songDownloadSearchResult.numChannels = resultNode.NAMESPACE_AUDIO_ALT::Channels; // Add the SearchResult Object to our Data Array. resultsArray.push(songDownloadSearchResult); } break; case SearchResultEvent.SONG_SEARCH_RESULT: for each (resultNode in inXML.children()) { var songSearchResult:Song = new Song(); // SearchResult Properties songSearchResult.index = resultNode.NAMESPACE_AUDIO_ALT::Track; songSearchResult.name = resultNode.NAMESPACE_AUDIO_ALT::Title; songSearchResult.id = resultNode.@id; songSearchResult.album = new Album(); songSearchResult.album.name = resultNode.NAMESPACE_AUDIO_ALT::Album; songSearchResult.album.id = resultNode.NAMESPACE_AUDIO_ALT::Album.@id; songSearchResult.duration = resultNode.NAMESPACE_AUDIO_ALT::Length; songSearchResult.publisher = resultNode.NAMESPACE_AUDIO_ALT::Publisher; songSearchResult.thumbnail = new Thumbnail(resultNode.NAMESPACE_AUDIO_ALT::Thumbnail.NAMESPACE_AUDIO_ALT::Url); songSearchResult.thumbnail.height = resultNode.NAMESPACE_AUDIO_ALT::Thumbnail.NAMESPACE_AUDIO_ALT::Height as Number; songSearchResult.thumbnail.width = resultNode.NAMESPACE_AUDIO_ALT::Thumbnail.NAMESPACE_AUDIO_ALT::Width as Number; songSearchResult.releaseDate = resultNode.NAMESPACE_AUDIO_ALT::ReleaseDate; // Add the SearchResult Object to our Data Array. resultsArray.push(songSearchResult); } break; case SearchResultEvent.ALBUM_SEARCH_RESULT: for each (resultNode in inXML.children()) { var albumSearchResult:AlbumSearchResult = new AlbumSearchResult(); // SearchResult Properties albumSearchResult.index = resultNode.childIndex() + len; albumSearchResult.name = resultNode.NAMESPACE_AUDIO_ALT::Title; albumSearchResult.id = resultNode.@id; albumSearchResult.artist = new Artist(); albumSearchResult.artist.name = resultNode.NAMESPACE_AUDIO_ALT::Artist; albumSearchResult.artist.id = resultNode.NAMESPACE_AUDIO_ALT::Artist.@id; albumSearchResult.publisher = resultNode.NAMESPACE_AUDIO_ALT::Publisher; albumSearchResult.thumbnail = new Thumbnail(resultNode.NAMESPACE_AUDIO_ALT::Thumbnail.NAMESPACE_AUDIO_ALT::Url); albumSearchResult.thumbnail.height = resultNode.NAMESPACE_AUDIO_ALT::Thumbnail.NAMESPACE_AUDIO_ALT::Height as Number; albumSearchResult.thumbnail.width = resultNode.NAMESPACE_AUDIO_ALT::Thumbnail.NAMESPACE_AUDIO_ALT::Width as Number; albumSearchResult.releaseDate = resultNode.NAMESPACE_AUDIO_ALT::ReleaseDate; albumSearchResult.relatedAlbums = []; for each(var a:XML in resultNode.NAMESPACE_AUDIO_ALT::RelatedAlbums.NAMESPACE_AUDIO_ALT::Album) { var album:Album = new Album(); album.name = a.toString(); album.id = a.@id; albumSearchResult.relatedAlbums.push(album); } // Add the SearchResult Object to our Data Array. resultsArray.push(albumSearchResult); } break; case SearchResultEvent.ARTIST_SEARCH_RESULT: for each (resultNode in inXML.children()) { var artistSearchResult:ArtistSearchResult = new ArtistSearchResult(); // SearchResult Properties artistSearchResult.index = resultNode.childIndex() + len; artistSearchResult.name = resultNode.NAMESPACE_AUDIO_ALT::Name; artistSearchResult.url = resultNode.NAMESPACE_AUDIO_ALT::YahooMusicPage; artistSearchResult.thumbnail = new Thumbnail(resultNode.NAMESPACE_AUDIO_ALT::Thumbnail.NAMESPACE_AUDIO_ALT::Url); artistSearchResult.thumbnail.height = resultNode.NAMESPACE_AUDIO_ALT::Thumbnail.NAMESPACE_AUDIO_ALT::Height as Number; artistSearchResult.thumbnail.width = resultNode.NAMESPACE_AUDIO_ALT::Thumbnail.NAMESPACE_AUDIO_ALT::Width as Number; artistSearchResult.relatedArtists = []; for each(var aXML:XML in resultNode.NAMESPACE_AUDIO_ALT::RelatedArtists.NAMESPACE_AUDIO_ALT::Artist) { var artist:Artist = new Artist(); artist.name = aXML.toString(); artist.id = aXML.@id; artistSearchResult.relatedArtists.push(artist); } artistSearchResult.popularSongs = []; for each(var s:XML in resultNode.NAMESPACE_AUDIO_ALT::PopularSongs.NAMESPACE_AUDIO_ALT::Song) { var song:Song = new Song(); song.name = s.toString(); song.id = s.@id; artistSearchResult.popularSongs.push(song); } // Add the SearchResult Object to our Data Array. resultsArray.push(artistSearchResult); } break; case SearchResultEvent.AUDIO_SEARCH_RESULT: for each (resultNode in inXML.children()) { var audioSearchResult:MediaSearchResult = new MediaSearchResult(); // SearchResult Properties audioSearchResult.index = resultNode.childIndex() + len; audioSearchResult.name = resultNode.NAMESPACE_AUDIO::Title; if(audioSearchResult.name == "") audioSearchResult.name = resultNode.NAMESPACE_AUDIO::Url; audioSearchResult.url = resultNode.NAMESPACE_AUDIO::Url; audioSearchResult.clickURL = resultNode.NAMESPACE_AUDIO::ClickUrl; audioSearchResult.referrerURL = resultNode.NAMESPACE_AUDIO::ReferrerUrl; audioSearchResult.isStreaming = resultNode.NAMESPACE_AUDIO::Streaming as Boolean; audioSearchResult.duration = resultNode.NAMESPACE_AUDIO::Duration; audioSearchResult.numChannels = resultNode.NAMESPACE_AUDIO::Channels; // Add the SearchResult Object to our Data Array. resultsArray.push(audioSearchResult); } break; case SearchResultEvent.PODCAST_SEARCH_RESULT: for each (resultNode in inXML.children()) { var podcastSearchResult:MediaSearchResult = new MediaSearchResult(); // SearchResult Properties podcastSearchResult.index = resultNode.childIndex() + len; podcastSearchResult.name = resultNode.NAMESPACE_SEARCH::Title; podcastSearchResult.url = resultNode.NAMESPACE_SEARCH::Url; podcastSearchResult.clickURL = resultNode.NAMESPACE_SEARCH::ClickUrl; podcastSearchResult.referrerURL = resultNode.NAMESPACE_SEARCH::ReferrerUrl; podcastSearchResult.isStreaming = resultNode.NAMESPACE_SEARCH::Streaming as Boolean; podcastSearchResult.duration = resultNode.NAMESPACE_SEARCH::Duration; podcastSearchResult.numChannels = resultNode.NAMESPACE_SEARCH::Channels; // Add the SearchResult Object to our Data Array. resultsArray.push(podcastSearchResult); } break; case SearchResultEvent.VIDEO_SEARCH_RESULT: for each (resultNode in inXML.children()) { var videoSearchResult:MediaSearchResult = new MediaSearchResult(); // SearchResult Properties videoSearchResult.index = resultNode.childIndex() + len; videoSearchResult.name = resultNode.NAMESPACE_VIDEO::Title; videoSearchResult.url = resultNode.NAMESPACE_VIDEO::Url; videoSearchResult.clickURL = resultNode.NAMESPACE_VIDEO::ClickUrl; videoSearchResult.referrerURL = resultNode.NAMESPACE_VIDEO::ReferrerUrl; videoSearchResult.thumbnail = new Thumbnail(resultNode.NAMESPACE_VIDEO::Thumbnail.NAMESPACE_VIDEO::Url); videoSearchResult.thumbnail.height = resultNode.NAMESPACE_VIDEO::Thumbnail.NAMESPACE_VIDEO::Height; videoSearchResult.thumbnail.width = resultNode.NAMESPACE_VIDEO::Thumbnail.NAMESPACE_VIDEO::Width; videoSearchResult.isStreaming = resultNode.NAMESPACE_VIDEO::Streaming as Boolean; videoSearchResult.duration = resultNode.NAMESPACE_VIDEO::Duration; videoSearchResult.numChannels = resultNode.NAMESPACE_VIDEO::Channels; // Add the SearchResult Object to our Data Array. resultsArray.push(videoSearchResult); } break; case SearchResultEvent.NEWS_SEARCH_RESULT: for each (resultNode in inXML.children()) { var newsSearchResult:NewsSearchResult = new NewsSearchResult(); // SearchResult Properties newsSearchResult.index = resultNode.childIndex() + len; newsSearchResult.name = resultNode.NAMESPACE_NEWS::Title; newsSearchResult.language = resultNode.NAMESPACE_NEWS::Language; newsSearchResult.url = resultNode.NAMESPACE_NEWS::Url; newsSearchResult.clickURL = resultNode.NAMESPACE_NEWS::ClickUrl; newsSearchResult.sourceURL = resultNode.NAMESPACE_NEWS::NewsSourceURL; newsSearchResult.newsSource = resultNode.NAMESPACE_NEWS::NewsSource; //convert string to number to date newsSearchResult.modificationDate = new Date(resultNode.NAMESPACE_NEWS::ModificationDate as Number); newsSearchResult.publicationDate = new Date(resultNode.NAMESPACE_NEWS::PublicationDate as Number); // Add the SearchResult Object to our Data Array. resultsArray.push(newsSearchResult); } break; case SearchResultEvent.IMAGE_SEARCH_RESULT: for each (resultNode in inXML.children()) { var imageSearchResult:MediaSearchResult = new MediaSearchResult(); // SearchResult Properties imageSearchResult.index = resultNode.childIndex() + len; imageSearchResult.name = resultNode.NAMESPACE_IMAGE::Title; imageSearchResult.summary = resultNode.NAMESPACE_IMAGE::Summary; imageSearchResult.url = resultNode.NAMESPACE_IMAGE::Url; imageSearchResult.thumbnail = new Thumbnail(resultNode.NAMESPACE_IMAGE::Thumbnail.NAMESPACE_IMAGE::Url); imageSearchResult.thumbnail.height = resultNode.NAMESPACE_IMAGE::Thumbnail.NAMESPACE_IMAGE::Height as Number; imageSearchResult.thumbnail.width = resultNode.NAMESPACE_IMAGE::Thumbnail.NAMESPACE_IMAGE::Width as Number; imageSearchResult.clickURL = resultNode.NAMESPACE_IMAGE::ClickUrl; imageSearchResult.referrerURL = resultNode.NAMESPACE_IMAGE::ReferrerUrl; imageSearchResult.fileSize = resultNode.NAMESPACE_IMAGE::FileSize as uint; imageSearchResult.fileFormat = resultNode.NAMESPACE_IMAGE::FileFormat; imageSearchResult.restrictions = resultNode.NAMESPACE_IMAGE::Restrictions; imageSearchResult.publisher = resultNode.NAMESPACE_IMAGE::Publisher; imageSearchResult.copyright = resultNode.NAMESPACE_IMAGE::Copyright; imageSearchResult.height = resultNode.NAMESPACE_IMAGE::Height; imageSearchResult.width = resultNode.NAMESPACE_IMAGE::Width; // Add the SearchResult Object to our Data Array. resultsArray.push(imageSearchResult); } break; //default web search default: for each (resultNode in inXML.children()) { var resultObject:WebSearchResult = new WebSearchResult(); // WebSearchResult Properties //index is the current index in this set of results added to what has already been returned, if anything resultObject.index = resultNode.childIndex() + len; resultObject.name = resultNode.NAMESPACE_SEARCH::Title; resultObject.summary = resultNode.NAMESPACE_SEARCH::Summary; resultObject.url = resultNode.NAMESPACE_SEARCH::Url; resultObject.clickURL = resultNode.NAMESPACE_SEARCH::ClickUrl; resultObject.displayURL = resultNode.NAMESPACE_SEARCH::DisplayUrl; resultObject.mimeType = resultNode.NAMESPACE_SEARCH::MimeType; resultObject.cache = new Cache(resultNode.NAMESPACE_SEARCH::Cache.NAMESPACE_SEARCH::Url, resultNode.NAMESPACE_SEARCH::Cache.NAMESPACE_SEARCH::Size as uint); //convert string to number to date resultObject.modificationDate = new Date(resultNode.NAMESPACE_SEARCH::ModificationDate as Number); /* The following are not implemented in the current XML API */ //resultObject.category //resultObject.internalSearchURL "More fromt this site" link // Add the WebSearchResult Object to our Data Array. resultsArray.push(resultObject); } } //if this search is being continued, add these to what we already have if(increment > 0) { lastResult = lastResult.concat(resultsArray); } else { lastResult = resultsArray; } if(firstResultPosition + lastResult.length >= numResultsAvailable) { hasResultsPending = false; } //Dispatch result dispatchResult(resultsArray, dispatchType); } /** * @private * Internal method for dispatching Events. * * @param result The Object containing the result * @param dispatchType The Event Type */ protected function dispatchResult(result:Object, dispatchType:String):void { //Dispatch a general Result event, passing along the type of result it is var aResults:SearchResultEvent = new SearchResultEvent(SearchResultEvent.RESULT, result, dispatchType); dispatchEvent(aResults); } /** * @private * Internal method for dispatching Fault Events. * * @param fault The Fault */ protected function dispatchFault(fault:com.yahoo.webapis.ServiceFault):void { var ServiceFault:SearchFaultEvent = new SearchFaultEvent(SearchFaultEvent.FAULT, fault); dispatchEvent(ServiceFault); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -