//listo public void createDataSongVersionLocal(DataSong pDataSongVersion) { TagManager.setID3(pDataSongVersion); int lversion_id = DatabaseManager.createVersion(pDataSongVersion); DatabaseManager.setVersion2Song(pDataSongVersion._LocalSongID, lversion_id.ToString()); }
public window_id3Tool(DataSong pMetadata) { this._SongToEdit = pMetadata; this._InfoManager = new InfoProvider(); InitializeComponent(); textbox_artist.Text = pMetadata._ID3Artist; textbox_genre.Text = pMetadata._ID3Genre; textbox_lyric.Text = pMetadata._ID3Lyrics; textbox_title.Text = pMetadata._ID3Title; textbox_album.Text = pMetadata._ID3Album; //this._MetadataVersion = this._InfoManager.getVersiono(); }
public static void setID3(DataSong pMetadata) { var taglibFile = TagLib.File.Create(pMetadata._SongDirectory); taglibFile.Tag.Title = pMetadata._ID3Title; string[] artists = {pMetadata._ID3Artist}; taglibFile.Tag.Performers = artists; string[] genres = { pMetadata._ID3Genre }; taglibFile.Tag.Genres = genres; taglibFile.Tag.Album = pMetadata._ID3Album; taglibFile.Tag.Comment = pMetadata._ID3Comment; taglibFile.Tag.Lyrics = pMetadata._ID3Lyrics; uint pYearParse = 0; uint.TryParse(pMetadata._ID3Year, out pYearParse); taglibFile.Tag.Year = pYearParse; taglibFile.Save(); }
//listo public async void createSong(DataSong pDataSongInitial) { RestTools rtop = new RestTools(); Song songop = await rtop.createSong(pDataSongInitial._SongDirectory); if (songop == null) { Console.WriteLine("Canción No Fue Creada"); } else { pDataSongInitial._SongID = songop.song_id.ToString(); Song songtop = await rtop.createVersion(pDataSongInitial); if (songtop == null) { } else { Console.WriteLine("Primera NO FUE Versión Creada"); } } }
public static DataSong getID3ByDirectory(string pDirectory) { DataSong id3op = new DataSong(); TagLib.File tagFile = TagLib.File.Create(pDirectory); List<string> p = new List<string>(); id3op._SongDirectory = pDirectory; id3op._ID3Title = tagFile.Tag.Title; id3op._ID3Album = tagFile.Tag.Album; id3op._ID3Year = (tagFile.Tag.Year.ToString()); id3op._ID3Lyrics = tagFile.Tag.Lyrics; if (tagFile.Tag.Genres.Length > 0) { id3op._ID3Genre = tagFile.Tag.Genres[0]; } if (tagFile.Tag.Performers.Length > 0) { id3op._ID3Artist = tagFile.Tag.Performers[0]; } id3op._SongName = tagFile.Name.Substring(tagFile.Name.LastIndexOf('\\') + 1); id3op.fillEmpty(); return id3op; }
/// <summary> /// Obtiene todas las canciones de un usario y su metadata /// </summary> /// <param name="user_name"> /// nombre del usuario /// </param> /// <returns> /// Lista de objetos metadata /// </returns> public async Task<List<DataSong>> getMetadataSongByUser(string user_name) { List<DataSong> songs_metadata = new List<DataSong>(); using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(server_url); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(format)); HttpResponseMessage response = await client.GetAsync(songs_by_user_path + "/" + user_name); if (response.IsSuccessStatusCode) { MetadataAndSong[] sngs_n_met = await response.Content.ReadAsAsync<MetadataAndSong[]>(); for (int i = 0; i < sngs_n_met.Length; i++) { DataSong song_met = new DataSong(); song_met._ID3Artist = (sngs_n_met[i].id3v2_author); song_met._ID3Title = (sngs_n_met[i].id3v2_title); song_met._ID3Album = (sngs_n_met[i].id3v2_album); song_met._ID3Year = (sngs_n_met[i].id3v2_year.ToString()); song_met._ID3Genre = (sngs_n_met[i].id3v2_genre); song_met._ID3Lyrics = (sngs_n_met[i].id3v2_lyrics); song_met._SongID = (sngs_n_met[i].song_id.ToString()); song_met._ID3Title = (sngs_n_met[i].id3v2_title); song_met._SongDirectory = (sngs_n_met[i].song_directory); song_met._SubmissionDate = (sngs_n_met[i].submission_date); song_met._SongName = (sngs_n_met[i].song_name); songs_metadata.Add(song_met); } } } return songs_metadata; }
/// <summary> /// Obtiene todas las canciones de un usuario /// </summary> /// <param name="user_name"> /// /// </param> /// <returns> /// /// </returns> public static List<DataSong> getSongsOfUser(string user_name) { try { List<DataSong> songs_list = new List<DataSong>(); using (SqlConnection connection = new SqlConnection(databaseConn)) { SqlCommand versionSongs = new SqlCommand(); versionSongs.CommandType = System.Data.CommandType.Text; versionSongs.CommandText = "SELECT * " + "FROM canc_metadata_tbl " + "WHERE usr_name = @usrname"; versionSongs.Parameters.AddWithValue("@usrname", user_name); versionSongs.Connection = connection; connection.Open(); SqlDataReader reader = versionSongs.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { DataSong dataSong = new DataSong(); dataSong._ID3Title = reader.GetString(1); dataSong._ID3Artist = reader.GetString(2); dataSong._ID3Album = reader.GetString(3); dataSong._ID3Year = reader.GetInt32(4).ToString(); dataSong._ID3Genre = reader.GetString(5); dataSong._ID3Lyrics = reader.GetString(6); dataSong._SubmissionDate = reader.GetDateTime(7).ToString(); dataSong._SongDirectory = reader.GetString(8); dataSong._LocalSongID = reader.GetInt32(9).ToString(); dataSong._SongID = reader.GetInt32(10).ToString(); songs_list.Add(dataSong); } } reader.Close(); connection.Close(); return songs_list; } } catch (Exception e) { Console.WriteLine(e); return null; } }
/// <summary> /// Cambia la version de metadata de una canción ya /// existente /// </summary> /// <param name="dataSong"> /// Objeto DataSong que contiene el id de la canción y /// la información de la nueva versión /// </param> /// <returns> /// bool que es true si se hace el cambio exitosamente, false /// en cualquier otro caso. /// </returns> public static bool setVersion2Song(DataSong dataSong) { try { //crea la version a agregar a la canción int version_id = createVersion(dataSong); return setVersion2Song(dataSong._LocalSongID, version_id.ToString()); } catch (Exception e) { Console.WriteLine(e); return false; } }
/// <summary> /// Crea la versión de una canción. /// </summary> /// <param name="datasong"> /// Objeto con todos los datos de la canción. /// </param> /// <returns> /// int que es el id de la versión, si es -2 no insertó nada /// y si es -1 hay un error. /// </returns> public static int createVersion(DataSong datasong) { try { int result = -2; using (SqlConnection connection = new SqlConnection(databaseConn)) { SqlCommand insertConnection = new SqlCommand(); insertConnection.CommandType = System.Data.CommandType.Text; insertConnection.CommandText = "INSERT INTO versiones_tbl "+ "(local_song_id, id3v2_title, id3v2_author, id3v2_lyrics, id3v2_album, id3v2_genre, id3v2_year) "+ "output INSERTED.local_version_id VALUES (@lsng_id, @title, @author, @lyrics, @album, @genre, @year)"; insertConnection.Parameters.AddWithValue("@lsng_id", Convert.ToInt32(datasong._LocalSongID)); insertConnection.Parameters.AddWithValue("@title", datasong._ID3Title); insertConnection.Parameters.AddWithValue("@author", datasong._ID3Artist); insertConnection.Parameters.AddWithValue("@lyrics", datasong._ID3Lyrics); insertConnection.Parameters.AddWithValue("@album", datasong._ID3Album); insertConnection.Parameters.AddWithValue("@genre", datasong._ID3Genre); insertConnection.Parameters.AddWithValue("@year", Convert.ToInt32(datasong._ID3Year)); insertConnection.Connection = connection; connection.Open(); object obj = insertConnection.ExecuteScalar(); result = (int)obj; connection.Close(); } return result; } catch(Exception e) { etrace1 = datasong._ID3Lyrics + " "+datasong._ID3Title; Console.WriteLine(e); return -1; } }
/// <summary> /// /// </summary> /// <param name="userName"></param> /// <returns></returns> public static List<DataSong> getDesynchronizeSongsByUser(string userName) { List<DataSong> songs_list = new List<DataSong>(); try { using (SqlConnection connection = new SqlConnection(databaseConn)) { SqlCommand versionSongs = new SqlCommand(); versionSongs.CommandType = System.Data.CommandType.Text; versionSongs.CommandText = "SELECT id3v2_title, id3v2_author, id3v2_album, id3v2_year, id3v2_genre, id3v2_lyrics, " + "submission_date, song_directory, local_song_id, cloud_song_id " + "FROM canc_metadata_tbl " + "WHERE usr_name = @usrname AND cloud_song_id = -1"; versionSongs.Parameters.AddWithValue("@usrname", userName); versionSongs.Connection = connection; connection.Open(); SqlDataReader reader = versionSongs.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { DataSong dataSong = new DataSong(); dataSong._ID3Title = reader.GetString(0); dataSong._ID3Artist = reader.GetString(1); dataSong._ID3Album = reader.GetString(2); dataSong._ID3Year = reader.GetInt32(3).ToString(); dataSong._ID3Genre = reader.GetString(4); dataSong._ID3Lyrics = reader.GetString(5); dataSong._SubmissionDate = reader.GetDateTime(6).ToString(); dataSong._SongDirectory = reader.GetString(7); dataSong._LocalSongID = reader.GetInt32(8).ToString(); dataSong._SongID = reader.GetInt32(9).ToString(); songs_list.Add(dataSong); } } reader.Close(); connection.Close(); } } catch(Exception e) { Console.WriteLine(e.Message); DataSong dataSong = new DataSong(); dataSong._ID3Title = e.Message + e.StackTrace; songs_list.Add(dataSong); } return songs_list; }
/// <summary> /// Agrega una canción a un usurio /// </summary> /// <param name="usr_name"> /// Usuario al que se le agrega la canción /// </param> /// <param name="song_name"> /// Nombre del archivo de la canción /// </param> /// <param name="datasong"> /// Objeto con toda la información de la canción /// </param> /// <returns> /// bool que es true si se pudo agregar la canción. /// En cualquier otro caso es false /// </returns> public static bool addSong2User(string usr_name, DataSong datasong) { int local_song_id = createSong(datasong); datasong._LocalSongID = local_song_id.ToString(); int version_id = createVersion(datasong); setVersion2Song(local_song_id.ToString(), version_id.ToString()); return createProperty(usr_name, local_song_id.ToString(), datasong._SongName); }
/// <summary> /// Crea una nueva canción en la base de datos local /// </summary> /// <param name="datasong"> /// objeto con toda la información de la canción. /// </param> /// <returns> /// int que es el id de la canción agregada /// </returns> public static int createSong(DataSong datasong) { try { int result = -1; using (SqlConnection connection = new SqlConnection(databaseConn)) { SqlCommand insertSong = new SqlCommand(); insertSong.CommandType = System.Data.CommandType.Text; insertSong.CommandText = "INSERT canciones_tbl (song_directory) output INSERTED.local_song_id VALUES (@directory)"; insertSong.Parameters.AddWithValue("@directory", datasong._SongDirectory); insertSong.Connection = connection; connection.Open(); object obj = insertSong.ExecuteScalar(); result = (int)obj; connection.Close(); } return result; } catch(Exception e) { Console.WriteLine(e); return -1; } }
/// <summary> /// Agrega una version nueva a una canción ya creada. /// </summary> /// <param name="dataSong"> /// Objeto DataSong que cnotiene la información /// de la version /// </param> public void setVersion2Song(DataSong dataSong) { DatabaseManager.setVersion2Song(dataSong); }
public void createLocalVersion(DataSong pDataSong) { int versionID = DatabaseManager.createVersion(pDataSong); DatabaseManager.setVersion2Song(pDataSong._LocalSongID, versionID.ToString()); }
/// <summary> /// /// </summary> /// <param name="met"></param> /// <returns> /// /// </returns> public async Task<Song> createVersion(DataSong met) { Song song; Version ver = new Version(met); ver.submission_date = "2015-11-15 07:23:23.440"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(server_url); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(format)); HttpResponseMessage response = await client.PostAsJsonAsync(versions_path, ver); if (response.IsSuccessStatusCode) { ver = await response.Content.ReadAsAsync<Version>(); song = await getSongById(Convert.ToInt32(met._SongID)); song.metadata_id = ver.version_id; HttpResponseMessage updsng = await client.PutAsJsonAsync<Song>(songs_path + "/" + song.song_id, song); if (updsng.IsSuccessStatusCode) { Console.WriteLine("\nSe creo correctamente, metadata_id {0}", song.metadata_id); } else { song = null; Console.WriteLine("\nError {0}", updsng.StatusCode); } } else { song = null; } return song; } }
public Version(DataSong met) { song_id = Convert.ToInt32(met._SongID); id3v2_title = met._ID3Title; id3v2_author = met._ID3Artist; id3v2_album = met._ID3Album; id3v2_year = Convert.ToInt32(met._ID3Year); id3v2_genre = met._ID3Genre; id3v2_lyrics = met._ID3Lyrics; submission_date = met._SubmissionDate; }
//listo public async void createDataSongVersionCloud(DataSong pDataSongVersion) { RestTools rtop = new RestTools(); Song songop = await rtop.createVersion(pDataSongVersion); }
private async void button_makeVersion_Click(object sender, RoutedEventArgs e) { DataSong selectedMeta = new DataSong(); selectedMeta._SongDirectory = this._SongDataList[listview_data.SelectedIndex]._SongDirectory; selectedMeta._SongName = this._SongDataList[listview_data.SelectedIndex]._SongName; selectedMeta._SongID = this._SongDataList[listview_data.SelectedIndex]._SongID; selectedMeta._LocalSongID = this._SongDataList[listview_data.SelectedIndex]._LocalSongID; selectedMeta._ID3Title = textbox_title.Text; selectedMeta._ID3Artist = textbox_artist.Text; selectedMeta._ID3Genre = textbox_genre.Text; selectedMeta._ID3Lyrics = textbox_lyric.Text; selectedMeta._ID3Album = textbox_album.Text; selectedMeta._ID3Year = textbox_year.Text; if (this._uploadMode == window_main.MODE_CLOUD) { this._InfoManager.createDataSongVersionCloud(selectedMeta); this._VersionList = await this._InfoManager.getListOfDataSong(this._SongDataList[listview_data.SelectedIndex]._SongID); } else if(this._uploadMode == window_main.MODE_LOCAL) { this._InfoManager.createDataSongVersionLocal(selectedMeta); this._VersionList = this._InfoManager.getLocalVersionList(this._SongDataList[listview_data.SelectedIndex]._LocalSongID); } if (this._VersionList != null) { this.refreshVersion(); } }
public async Task<List<DataSong>> getRecomendatedSongs(string pUserName) { RestTools rtop = new RestTools(); List<DataSong> r = new List<DataSong>(); foreach(OtroObjeto ob in (await rtop.getRecomendatedSongs(pUserName))) { DataSong d = new DataSong(); d._ID3Album = ob.album; d._ID3Artist = ob.author; d._ID3Genre = ob.genre; d._ID3Lyrics = ob.lyrics; d._SongID = ob.song_id.ToString(); d._ID3Year = ob.song_year.ToString(); d._ID3Title = ob.title; r.Add(d); } return r; }