コード例 #1
0
        public IEnumerable <NowPlaying> GetTracks(int offset = 0, int limit = 4000)
        {
            string[] tracks;
            _api.NowPlayingList_QueryFilesEx(null, out tracks);

            return(tracks.Select((path, position) =>
            {
                var artist = _api.Library_GetFileTag(path, MetaDataType.Artist);
                var title = _api.Library_GetFileTag(path, MetaDataType.TrackTitle);

                if (string.IsNullOrEmpty(title))
                {
                    var index = path.LastIndexOf('\\');
                    title = path.Substring(index + 1);
                }

                return new NowPlaying
                {
                    Artist = string.IsNullOrEmpty(artist) ? "Unknown Artist" : artist,
                    Title = title,
                    Position = position + 1,
                    Path = path
                };
            }).ToList());
        }
コード例 #2
0
        /// <inheritdoc/>
        public string SetRating(string rating)
        {
            var currentTrack     = _api.NowPlaying_GetFileUrl();
            var decimalSeparator = Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, CultureInfo.CurrentCulture);

            try
            {
                rating = rating.Replace('.', decimalSeparator);
                if (!float.TryParse(rating, out var fRating))
                {
                    fRating = -1;
                }

                if ((fRating >= 0 && fRating <= 5) || string.IsNullOrEmpty(rating))
                {
                    var value = string.IsNullOrEmpty(rating) ? string.Empty : fRating.ToString(CultureInfo.CurrentCulture);
                    _api.Library_SetFileTag(currentTrack, MetaDataType.Rating, value);
                    _api.Library_CommitTagsToFile(currentTrack);
                    _api.Player_GetShowRatingTrack();
                    _api.MB_RefreshPanels();
                }
            }
            catch (Exception)
            {
                // Ignored exception? should log
            }

            return(_api.Library_GetFileTag(currentTrack, MetaDataType.Rating).Replace(decimalSeparator, '.'));
        }
コード例 #3
0
 public void IncrementPlayCount(object sender, EventArgs e)
 {
     string[] mySelectedFiles = new string[] { };
     mbApiInterface.Library_QueryFilesEx("domain=SelectedFiles", ref mySelectedFiles);
     foreach (string myfile in mySelectedFiles)
     {
         string currentValue = mbApiInterface.Library_GetFileTag(myfile, (MetaDataType)FilePropertyType.PlayCount);
         int    newValue     = Int32.Parse(currentValue) + 1;
         mbApiInterface.Library_SetFileTag(myfile, (MetaDataType)FilePropertyType.PlayCount, newValue.ToString());
         mbApiInterface.Library_CommitTagsToFile(myfile);
     }
     mbApiInterface.MB_RefreshPanels();
 }
コード例 #4
0
        public string RetrieveLyrics(string sourceFileUrl, string artist, string trackTitle, string album,
                                     bool synchronisedPreferred, string provider)
        {
            if (provider != ProviderName)
            {
                return(null);
            }

            var id          = 0;
            var specifiedId = _mbApiInterface.Library_GetFileTag(sourceFileUrl, MetaDataType.Custom10)
                              ?? _mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Custom10);

            if (specifiedId != null && specifiedId.StartsWith("netease="))
            {
                specifiedId = specifiedId.Substring("netease=".Length);
                int.TryParse(specifiedId, out id);
            }

            if (id == 0)
            {
                var searchResult = QueryWithFeatRemoved(trackTitle, artist);
                if (searchResult == null)
                {
                    return(null);
                }
                id = searchResult.id;
            }

            if (id == 0)
            {
                return(null);
            }

            var lyricResult = RequestLyric(id);

            if (lyricResult.lrc?.lyric == null)
            {
                return(null);
            }
            if (lyricResult.tlyric?.lyric == null || _config.format == NeteaseConfig.OutputFormat.Original)
            {
                return(lyricResult.lrc.lyric); // No need to process translation
            }
            if (_config.format == NeteaseConfig.OutputFormat.Translation)
            {
                return(lyricResult.tlyric?.lyric ?? lyricResult.lrc.lyric);
            }
            // translation
            return(LyricProcessor.InjectTranslation(lyricResult.lrc.lyric, lyricResult.tlyric.lyric));
        }
コード例 #5
0
        private ObservableCollection <Song> GetNowPlayingList()
        {
            ObservableCollection <Song> instance = new ObservableCollection <Song>();

            string[] fileUrls = new string[0];
            mbApiInterface.NowPlayingList_QueryFilesEx(null, ref fileUrls);

            foreach (var url in fileUrls)
            {
                Song song = new Song
                {
                    Url = url
                };

                song.Name =
                    mbApiInterface.Library_GetFileTag(url, MetaDataType.TrackTitle) +
                    " - " +
                    mbApiInterface.Library_GetFileTag(url, MetaDataType.AlbumArtist) +
                    (mbApiInterface.Library_GetFileTag(url, MetaDataType.RatingLove) == "L" ? " ♥" : "");
                instance.Add(song);
            }

            return(new ObservableCollection <Song>(instance.OrderBy(x => x.Name)));
        }
コード例 #6
0
 // return lyrics for the requested artist/title from the requested provider
 // only required if PluginType = LyricsRetrieval
 // return null if no lyrics are found
 public string RetrieveLyrics(string sourceFileUrl, string artist, string trackTitle, string album, bool synchronisedPreferred, string provider)
 {
     switch (provider)
     {
     case Provider:
         string albumArtist = null;
         try
         {
             albumArtist = mbApiInterface.Library_GetFileTag(sourceFileUrl, MetaDataType.AlbumArtist);
         }
         catch { }
         return(PetitLyrics.FetchLyrics(trackTitle, artist, album));
     }
     return(null);
 }
コード例 #7
0
        public void AverageFiles()
        {
            double avg = 0;

            string       temp, check = null;
            MetaDataType tag;

            configMgr = new ConfigMgr();
            Dictionary <int, string> DeserializedDict = configMgr.DeserializeIntoDict(_workingDirectory + @"\DRconfig.xml", new Dictionary <int, string>());

            DeserializedDict.TryGetValue(7, out check);


            DeserializedDict.TryGetValue(2, out temp);
            tagsDictionary.TryGetValue(temp, out tag);


            if (!mbApiInterface.Library_QueryFilesEx("domain=SelectedFiles", ref files))
            {
                files = new string[0];
            }


            if (files.Length == 0)
            {
                MessageBox.Show("No files selected.");
                return;
            }

            for (int i = 0; i < files.Length; i++)
            {
                string taggedVal = mbApiInterface.Library_GetFileTag(files[i], tag);

                try
                {
                    avg += Convert.ToDouble(Regex.Replace(taggedVal, @"[a-zA-Z /\s/g :]", ""), CultureInfo.GetCultureInfo("en-us"));
                }
                catch (System.FormatException e)
                {
                    MessageBox.Show("Please tag all of the files first!");
                    return;
                }
            }

            avg = (avg / files.Length);

            if (check == "None")
            {
                MessageBox.Show("[NO TAG CONFIGURED - Files Not Tagged] \n\nAverage DR of selected files: " + Convert.ToString(Math.Round(avg, 2)) + " LU");
                return;
            }


            //Write tag to files:
            for (int i = 0; i < files.Length; i++)
            {
                DeserializedDict.TryGetValue(7, out temp);
                tagsDictionary.TryGetValue(temp, out tag);

                mbApiInterface.Library_SetFileTag(files[i], tag, Math.Round(avg, 2) + " LU");
                mbApiInterface.Library_CommitTagsToFile(files[i]);
            }

            //MessageBox.Show("Temp: " + temp + "\nTag: " + tag + "\nData: " + data[i]);


            mbApiInterface.MB_RefreshPanels();

            MessageBox.Show("[FILES TAGGED] \n\nAverage DR of selected files: " + Convert.ToString(Math.Round(avg, 2)) + " LU");


            return;
        }
コード例 #8
0
        public Dictionary <string, string> GenerateMetaDataDictionary(string fileUrl = null)
        {
            var ret = new Dictionary <string, string>(Enum.GetNames(typeof(MetaDataType)).Length + Enum.GetNames(typeof(FilePropertyType)).Length);

            foreach (MetaDataType elem in Enum.GetValues(typeof(MetaDataType)))
            {
                ret.Add(elem.ToString(), string.IsNullOrWhiteSpace(fileUrl) ? _mbApiInterface.NowPlaying_GetFileTag(elem) : _mbApiInterface.Library_GetFileTag(fileUrl, elem));
            }
            foreach (FilePropertyType elem in Enum.GetValues(typeof(FilePropertyType)))
            {
                ret.Add(elem.ToString(), string.IsNullOrWhiteSpace(fileUrl) ? _mbApiInterface.NowPlaying_GetFileProperty(elem) : _mbApiInterface.Library_GetFileProperty(fileUrl, elem));
            }
            ret.Add("Extension", Path.GetExtension(string.IsNullOrWhiteSpace(fileUrl) ? _mbApiInterface.NowPlaying_GetFileUrl() : fileUrl).TrimStart('.').ToUpper());
            ret.Add("PlayState", _mbApiInterface.Player_GetPlayState().ToString());
            ret.Add("Volume", Convert.ToInt32(_mbApiInterface.Player_GetVolume() * 100.0f).ToString());

            return(ret);
        }
コード例 #9
0
        private async Task <List <PlaylistAction> > GetPlaylistActions(List <MusicBeePlaylist> playlistsToSync, List <Playlist> existingGroovePlaylists)
        {
            List <PlaylistAction> playlistActions = new List <PlaylistAction>();
            int totalPlaylistsProcessed           = 0;

            foreach (MusicBeePlaylist playlist in playlistsToSync)
            {
                _window.WriteOutputLine($"Preparing {playlist.Name} for sync");

                // If playlist already exists,
                // for now, delete playlist and remake completely
                // eventually, calculate diff
                Playlist matchingGroovePlaylist = existingGroovePlaylists.Where(p => p.Name == playlist.Name).FirstOrDefault();
                if (matchingGroovePlaylist != null)
                {
                    PlaylistAction deletePlaylist = new PlaylistAction()
                    {
                        Id = matchingGroovePlaylist.Id,
                    };
                    playlistActions.Add(deletePlaylist);
                }

                // Get list of file paths to tracks in music bee library
                string[] playlistFiles = null;
                if (_mbApiInterface.Playlist_QueryFiles(playlist.MusicBeeName))
                {
                    bool success = _mbApiInterface.Playlist_QueryFilesEx(playlist.MusicBeeName, ref playlistFiles);
                    if (!success)
                    {
                        _window.WriteOutputLine($"Couldn't find playlist file for: {playlist.Name}");
                        return(null);
                    }
                }
                else
                {
                    playlistFiles = new string[] { };
                }

                // Map the track in music bee to Groove
                List <TrackAction> tracksToAdd = new List <TrackAction>();
                foreach (string file in playlistFiles)
                {
                    string title  = _mbApiInterface.Library_GetFileTag(file, MetaDataType.TrackTitle);
                    string artist = _mbApiInterface.Library_GetFileTag(file, MetaDataType.Artist);

                    ContentResponse response = await _client.SearchAsync(MediaNamespace.music, HttpUtility.UrlEncode(title), ContentSource.Collection, SearchFilter.Tracks);

                    if (response.Error == null || response.Error.ErrorCode == Enum.GetName(typeof(ErrorCode), ErrorCode.COLLECTION_INVALID_DATA))
                    {
                        TrackAction  action      = null;
                        List <Track> tracksFound = response.Tracks.Items.Cast <Track>().ToList();
                        foreach (Track track in tracksFound)
                        {
                            if (track.Name == title &&
                                track.Artists.Where(c => c.Artist.Name == artist).FirstOrDefault() != null)
                            {
                                action = new TrackAction()
                                {
                                    Action = TrackActionType.Add,
                                    Id     = track.Id
                                };
                                tracksToAdd.Add(action);
                            }
                        }

                        if (action == null)
                        {
                            _window.WriteOutputLine($"Could not match track {artist} - {title}");
                        }
                    }
                    else
                    {
                        _window.WriteOutputLine($"Could not match track {artist} - {title}");
                    }
                }

                PlaylistAction createPlaylist = new PlaylistAction()
                {
                    Name         = playlist.Name,
                    TrackActions = tracksToAdd
                };
                playlistActions.Add(createPlaylist);

                totalPlaylistsProcessed++;
                _window.UpdatePreparationProgress(100 * totalPlaylistsProcessed / playlistsToSync.Count);
            }

            return(playlistActions);
        }