public override int GetHashCode() { int hashCode = 0; hashCode = hashCode ^ Id1.GetHashCode() ^ Id2.GetHashCode() ^ Id3.GetHashCode(); return(hashCode); }
/// <summary> /// Updated the beacon PID; The ID 1 (without dashes) + 5 digits ID 2 /// (padded with zeros) + 5 digits ID 3 (padded with zeros). /// </summary> private void UpdatePid() { string template = "00000"; string beaconId2 = Id2.ToString(); string beaconId3 = Id3.ToString(); beaconId2 = template.Substring(beaconId2.Length) + beaconId2; beaconId3 = template.Substring(beaconId3.Length) + beaconId3; string pid = Id1.Replace(HexStringSeparator.ToString(), string.Empty) + beaconId2 + beaconId3; Pid = pid.ToLower(); }
public void Setup() { var featuresNum = 3; var lines = File.ReadLines("../../../../train.csv"); data = new Data() { Columns = lines.First().Split(",").Select((value, index) => (value, index)).Take(featuresNum).ToDictionary(i => i.value, i => i.index), Rows = lines.Skip(1).Select(l => l.Split(",")).Select(r => (r[featuresNum], r.Take(featuresNum).ToArray())).ToArray() }; var features = data.Columns.Keys.Where(c => c != "IsLate" && c != "Day").ToArray(); node = Id3.Train(data, 10); }
private static List<Id3.Net.Id3Tag> GetInternetTags(Id3.Net.Id3Tag tag) { List<Id3.Net.Id3Tag> l = new List<Id3.Net.Id3Tag>(); Id3.Net.Info.WindowsMedia.WindowsMediaInfoProvider wm = new Id3.Net.Info.WindowsMedia.WindowsMediaInfoProvider(); l.AddRange(wm.GetInfo(tag)); Id3.Net.Info.Discogs.DiscogsInfoProvider d = new Id3.Net.Info.Discogs.DiscogsInfoProvider(); l.AddRange(d.GetInfo(tag)); Id3.Net.Info.LyricWiki.LyricWikiInfoProvider w = new Id3.Net.Info.LyricWiki.LyricWikiInfoProvider(); l.AddRange(w.GetInfo(tag).ToList()); Id3.Net.Info.Amazon.AmazonInfoProvider a = new Id3.Net.Info.Amazon.AmazonInfoProvider(); l.AddRange(a.GetInfo(tag).ToList()); Id3.Net.Info.Filename.FilenameInfoProvider f = new Id3.Net.Info.Filename.FilenameInfoProvider(); l.AddRange(f.GetInfo(tag).ToList()); return l; }
public void Base() { var sut = new Id3(); var example1 = new Dictionary <string, string> { { "outlook", "sunny" }, { "humidity", "high" }, { "windy", "false" }, { "class", "N" } }; var example2 = new Dictionary <string, string> { { "outlook", "overcast" }, { "humidity", "high" }, { "windy", "false" }, { "class", "P" } }; var example3 = new Dictionary <string, string> { { "outlook", "rain" }, { "humidity", "high" }, { "windy", "false" }, { "class", "P" } }; var example4 = new Dictionary <string, string> { { "outlook", "sunny" }, { "humidity", "normal" }, { "windy", "false" }, { "class", "P" } }; var example5 = new Dictionary <string, string> { { "outlook", "rain" }, { "humidity", "high" }, { "windy", "true" }, { "class", "N" } }; var example6 = new Dictionary <string, string> { { "outlook", "rain" }, { "humidity", "normal" }, { "windy", "true" }, { "class", "N" } }; var examples = new[] { example1, example2, example3, example4, example5, example6 }; var attributes = new Dictionary <string, List <string> >(); attributes.Add("outlook", new List <string> { "sunny", "rain", "overcast" }); attributes.Add("humidity", new List <string> { "high", "normal" }); attributes.Add("windy", new List <string> { "true", "false" }); var decisionTree = sut.CreateDecisionTree(examples, "class", attributes); Assert.Equal("windy", decisionTree.TestAttributeName); Assert.Equal("true", decisionTree.Children[0].BranchForValue); Assert.Equal("N", decisionTree.Children[0].TargetAttribute.Value); Assert.Equal("false", decisionTree.Children[1].BranchForValue); Assert.Equal("outlook", decisionTree.Children[1].TestAttributeName); Assert.Equal("sunny", decisionTree.Children[1].Children[0].BranchForValue); Assert.Equal("rain", decisionTree.Children[1].Children[1].BranchForValue); Assert.Equal("P", decisionTree.Children[1].Children[1].TargetAttribute.Value); Assert.Equal("overcast", decisionTree.Children[1].Children[2].BranchForValue); }
/// <summary> /// Write ID3 tags for a file /// </summary> /// <param name="FilePath">The file path to write</param> /// <param name="Id3Info">ID3 tags</param> /// <param name="Options">Options (whether need to write info, cover, lyrics)</param> public static void WriteFile(string FilePath, Id3 Id3Info, GrabOptions Options) { TagLib.File trackFile = TagLib.File.Create(FilePath); trackFile.RemoveTags(TagLib.TagTypes.Id3v1); trackFile.RemoveTags(TagLib.TagTypes.Ape); TagLib.Id3v2.Tag.DefaultVersion = 3; TagLib.Id3v2.Tag.ForceDefaultVersion = true; if (Options.needId3) { trackFile.Tag.Album = Id3Info.AlbumTitle; trackFile.Tag.AlbumArtists = Id3Info.AlbumArtists; trackFile.Tag.Title = Id3Info.TrackName; trackFile.Tag.Performers = Id3Info.Performers; trackFile.Tag.Year = Id3Info.Year; trackFile.Tag.Disc = Id3Info.Disc; trackFile.Tag.DiscCount = Id3Info.DiscCount; trackFile.Tag.Track = Id3Info.Track; trackFile.Tag.TrackCount = Id3Info.TrackCount; } if (Options.needCover) { trackFile.Tag.Pictures = Id3Info.CoverImageList.ToArray(); } if (Options.needLyric) { trackFile.Tag.Lyrics = Id3Info.Lyrics; } trackFile.Save(); }
public async Task <IActionResult> PostSoundCloud([FromBody] RequestBody requestBody) { var requestIp = Request.HttpContext.Connection.RemoteIpAddress; _logger.Information(string.Join(" ", requestIp, _logMessages["requestReceived"])); if (string.IsNullOrEmpty(requestBody.clientId) || string.IsNullOrEmpty(requestBody.soundcloudUrl.ToString())) { _logger.Information(string.Join(" ", requestIp, _logMessages["requestMalformed"])); return(StatusCode(400, new ErrorResponse(_logMessages["requestMalformed"]))); } var soundCloudManager = new Manager.Methods.SoundCloud(); var createdFiles = new List <string>(); try { if (requestBody.soundcloudUrl.ToString().Contains("sets")) //Use regex later { _logger.Information(string.Join(" ", requestIp, _logMessages["requestPlaylist"])); var playlistInformation = soundCloudManager.ResolvePlaylistUrl(requestBody.soundcloudUrl, requestBody.clientId); _logger.Information(string.Join(" ", requestIp, _logMessages["requestAuthentication"])); var playlistFolder = Directory.CreateDirectory($"{_tempFileStore}\\{playlistInformation.Title}"); _logger.Information(string.Join(" ", requestIp, _logMessages["playlistInformation"])); foreach (var track in playlistInformation.Tracks) { var trackUrl = soundCloudManager.QueryTrackUrl(track.Id, requestBody.clientId); var trackInformation = soundCloudManager.ResolveTrackUrl(trackUrl, requestBody.clientId); var trackName = trackInformation.Title; var trackMediaUrl = soundCloudManager.QueryTrackTranscodings(trackInformation.Media.Transcodings, requestBody.clientId); var filePath = $"{_tempFileStore}\\{playlistInformation.Title}\\{trackName}.mp3"; var trackM3u8 = soundCloudManager.QueryTrackM3u8(trackMediaUrl); var ffmpegManager = new Ffmpeg(); await ffmpegManager.DownloadTrack(trackM3u8, filePath); _logger.Information(string.Join(" ", requestIp, _logMessages["fileDownloadPlaylist"])); var trackMediaInformationMod = new TrackInformationMod() { artist = trackInformation.User.Username, album = trackInformation.User.Username, title = trackInformation.Title }; var id3Manager = new Id3(); id3Manager.SetFileMetadata(filePath, trackMediaInformationMod); } string zipPath = $"{_tempFileStore}\\{playlistInformation.Title}.zip"; var compressionManager = new Compression(); compressionManager.CompressFolder(playlistFolder.FullName, zipPath); _logger.Information(string.Join(" ", requestIp, _logMessages["zipStatus"])); var fileStream = await System.IO.File.ReadAllBytesAsync(zipPath); Response.Headers.Add("File-Type", "zip"); createdFiles.Add(zipPath); createdFiles.Add(playlistFolder.FullName); return(File(fileStream, "application/octet-stream")); } else { var trackInformation = soundCloudManager.ResolveTrackUrl(requestBody.soundcloudUrl, requestBody.clientId); _logger.Information(string.Join(" ", requestIp, _logMessages["requestAuthentication"])); string trackName = trackInformation.Title; var trackMediaInformation = soundCloudManager.QueryTrackTranscodings(trackInformation.Media.Transcodings, requestBody.clientId); var trackMediaUrl = soundCloudManager.QueryTrackM3u8(trackMediaInformation); string filePath = $"{_tempFileStore}\\{trackName}.mp3"; var ffmpegManager = new Ffmpeg(); await ffmpegManager.DownloadTrack(trackMediaUrl, filePath); _logger.Information(string.Join(" ", requestIp, _logMessages["fileDownload"])); var trackMediaInformationMod = new TrackInformationMod() { artist = trackInformation.User.Username, album = trackInformation.User.Username, title = trackInformation.Title }; var id3Manager = new Id3(); id3Manager.SetFileMetadata(filePath, trackMediaInformationMod); var fileStream = await System.IO.File.ReadAllBytesAsync(filePath); _logger.Information(string.Join(" ", requestIp, _logMessages["requestSuccess"])); Response.Headers.Add("File-Type", "mp3"); return(File(fileStream, "application/octet-stream")); } } catch (Exception processException) { _logger.Information(string.Join(" ", requestIp, _logMessages["requestError"], processException.Message)); return(StatusCode(500, new ErrorResponse(processException.Message))); } finally { foreach (var file in createdFiles) { if (Directory.Exists(file)) { Directory.Delete(file, true); } else { System.IO.File.Delete(file); } } //Leaves still some unknow file behind when downloading singular Tracks... _logger.Information(string.Join(" ", requestIp, _logMessages["fileCleanup"])); } }