/// <summary> /// Handle lyric source removal. /// </summary> /// <param name="e">Param for removal operation.</param> private void OnRemoveLrcSourceButtonClicked(RoutedEventArgs e) { var ctx = (LrcSourceModel)((Button)e.OriginalSource).DataContext; SourceScriptManager.RemoveScript(ctx.Name); LrcSources.Remove(ctx); }
/// <summary> /// Fetch lyrics from either local file cache or Internet. /// </summary> /// <param name="candidates"> /// A list collection receiving online lyrics candidates. /// </param> /// <param name="ignoreCache">Do not read local cache.</param> /// <returns>Parsed lyrics</returns> public static async Task <ParsedLrc> FetchLyricsAsync(string title, string artist, IList <ExternalLrcInfo> candidates, string cacheName, bool ignoreCache = false) { if (candidates == null) { throw new ArgumentNullException(nameof(candidates)); } var lrcFolder = await GetLyricsSaveFolderAsync(); if (lrcFolder != null) { var existentFile = (await lrcFolder.TryGetItemAsync(cacheName)) as IStorageFile; if (existentFile != null && !ignoreCache) { return(LrcParser.Parse(await existentFile.OpenStreamForReadAsync(), false)); } } // No existent lrc file. Query for it on Internet. List <ExternalLrcInfo> sorted = new List <ExternalLrcInfo>(); foreach (var s in SourceScriptManager.GetAllScripts()) { var infos = (await s.LookupLrcAsync(title, artist)); sorted.AddRange(infos); } sorted.Sort(new SimilarityComparer(title, artist)); sorted.ForEach((info) => candidates.Add(info)); return(candidates.Count > 0 ? await FetchLyricsAsync(candidates[0], cacheName) : null); }
/// <summary> /// Fetch lyrics by <see cref="ExternalLrcInfo"/> from /// previous call of <see cref="FetchLyricsAsync(string, string, IList{ExternalLrcInfo})"/>. /// </summary> /// <param name="info">Obtained from previous call</param> /// <returns>Parsed lyrics</returns> public static async Task <ParsedLrc> FetchLyricsAsync(ExternalLrcInfo info, string cacheName) { if (info == null) { throw new ArgumentNullException(nameof(info)); } var source = info.Source; if (string.IsNullOrEmpty(source)) { throw new ArgumentNullException(nameof(info.Source), "Where do you come from?"); } var s = SourceScriptManager.GetScript(source); var lrcText = await s.DownloadLrcAsync(info); await SaveLyricsInternalAsync( await GetLyricsSaveFolderAsync(), cacheName, lrcText); if (!string.IsNullOrEmpty(lrcText)) { try { return(LrcParser.Parse(lrcText)); } catch { } } return(null); }
/// <summary> /// Method for loading lyric sources. /// </summary> public void LoadLyricsSources() { var scripts = SourceScriptManager.GetAllScripts(); foreach (var s in scripts) { LrcSources.Add(new LrcSourceModel { Name = s.Name, RemoveLrcSourceButtonClickedRelayCommand = _removeLrcSourceButtonClickedRelayCommand }); } }
async void OnFinishedSettingsButtonClicked(object sender, RoutedEventArgs e) { if (EnableThirdPartyLyricsToggle.IsOn) { var assembly = GetType().GetTypeInfo().Assembly; var predefinedResources = new List <string> { "netease", "qqmusic", "ttlyrics", "xiami" }; foreach (var res in predefinedResources) { try { using (var resource = assembly.GetManifestResourceStream($"Light.Resource.{res}.js")) using (var sr = new StreamReader(resource)) { var content = await sr.ReadToEndAsync(); SourceScriptManager.AddScript(res, content); } } catch { } } } // Provision OOBE Experience Step 2. if (!SettingsManager.Instance.ContainsKey("InitialOOBEExperience.Settings.v3")) { SettingsManager.Instance.Add("InitialOOBEExperience.Settings.v3", 1); } if (PlatformInfo.CurrentPlatform == Platform.WindowsMobile) { Frame.Navigate(typeof(MobileFrameView), _filePassThru); } else { Frame.Navigate(typeof(FrameView), _filePassThru); } // Set flag OnlineServicingManager.Commit(); // Start indexing library await LibraryService.IndexAsync(new ThumbnailOperations()); }
/// <summary> /// Handle adding lyric source. /// </summary> private async void AddLrcSourceStub() { try { FileOpenPicker picker = new FileOpenPicker { ViewMode = PickerViewMode.List, SuggestedStartLocation = PickerLocationId.DocumentsLibrary, }; picker.FileTypeFilter.Add(CommonSharedStrings.JavaScriptFileFormatSuffix); var files = await picker.PickMultipleFilesAsync(); foreach (var file in files) { var name = file.DisplayName; if (LrcSources.Any(source => source.Name == name)) { // TODO: let user choose to rename or overwrite. } var text = await FileIO.ReadTextAsync(file); SourceScriptManager.AddScript(name, text); LrcSources.Add(new LrcSourceModel { Name = name, RemoveLrcSourceButtonClickedRelayCommand = _removeLrcSourceButtonClickedRelayCommand }); } } catch (SecurityException) { // Ignore, notify user } catch (COMException) { // Ignore, notify user } catch (FileNotFoundException) { // Ignore, notify user } }
private async void OnAddLyricsExtensionClick(Hyperlink sender, HyperlinkClickEventArgs args) { try { FileOpenPicker picker = new FileOpenPicker { ViewMode = PickerViewMode.List, SuggestedStartLocation = PickerLocationId.DocumentsLibrary, }; picker.FileTypeFilter.Add(CommonSharedStrings.JavaScriptFileFormatSuffix); var files = await picker.PickMultipleFilesAsync(); foreach (var file in files) { var name = file.DisplayName; var text = await FileIO.ReadTextAsync(file); SourceScriptManager.AddScript(name, text); } await _vm.LrcAutoSearch(); } catch (SecurityException) { // Ignore, notify user } catch (COMException) { // Ignore, notify user } catch (FileNotFoundException) { // Ignore, notify user } }