コード例 #1
0
    static void Main()
    {
        List <Karaoke> karaokeList = new List <Karaoke>();

        string[] participants   = Console.ReadLine().Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
        string[] availableSongs = Console.ReadLine().Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);

        string command;

        while ((command = Console.ReadLine()) != "dawn")
        {
            string[] cmdArgs = command.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);

            string participant = cmdArgs[0];
            string song        = cmdArgs[1];
            string award       = cmdArgs[2];

            if (!participants.Contains(participant) || !availableSongs.Contains(song))
            {
                continue;
            }

            if (karaokeList.Any(x => x.Name == participant))
            {
                Karaoke karaoke = karaokeList.First(x => x.Name == participant);

                if (!karaoke.Songs.Contains(song) || !karaoke.Awards.Contains(award))
                {
                    karaoke.Songs.Add(song);

                    karaoke.Awards.Add(award);
                }
            }
            else
            {
                Karaoke karaoke = new Karaoke(participant);

                karaoke.Songs.Add(song);

                karaoke.Awards.Add(award);

                karaokeList.Add(karaoke);
            }
        }

        if (karaokeList.Count == 0)
        {
            Console.WriteLine("No awards");
        }

        foreach (Karaoke singer in karaokeList.OrderByDescending(x => x.Awards.Count).ThenBy(x => x.Name))
        {
            Console.WriteLine("{0}: {1} awards", singer.Name, singer.Awards.Count);

            foreach (string award in singer.Awards.OrderBy(x => x))
            {
                Console.WriteLine("--{0}", award);
            }
        }
    }
コード例 #2
0
        /// <summary>
        /// Devuelve una lista con N+1 líneas correspondientes al contenido de una <see cref="Line"/> dividido en los N índices indicados.
        /// </summary>
        /// <param name="lineaKaraoke"><see cref="Line"/> cuyo contenido es divisible como romaji.</param>
        /// <param name="indices">Arreglo con índices de sílabas donde dividir la línea.</param>
        public static List <Line> SplitKaraoke(Line lineaKaraoke, int[] indices)
        {
            var listaResultante  = new List <Line>();
            var lineasDivididas  = new List <Line>();
            var indicesOrdenados = (from i in indices
                                    orderby i
                                    select i).ToArray();
            var dividiendo = lineaKaraoke;

            for (var i = 0; i < indicesOrdenados.Length; i++)
            {
                var finPrimera = indicesOrdenados[i];

                if (i > 0)
                {
                    finPrimera -= new Karaoke(lineasDivididas.First().Content).Syllabes.Count;
                }

                lineasDivididas = SplitKaraoke(dividiendo, finPrimera);
                dividiendo      = lineasDivididas.Last();
                listaResultante.Add(lineasDivididas.First());
            }

            listaResultante.Add(lineasDivididas.Last());

            return(listaResultante);
        }
コード例 #3
0
        public void KaraokeToString(string ingresado, string esperado)
        {
            var linea   = new Line(ingresado);
            var karaoke = new Karaoke(linea.Content);

            Assert.AreEqual(esperado, karaoke.ToString());
        }
コード例 #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            Karaoke karaoke = db.Karaokes.Find(id);

            db.Karaokes.Remove(karaoke);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #5
0
 public ActionResult Edit([Bind(Include = "Id,Venue,AvailableDate,Address")] Karaoke karaoke)
 {
     if (ModelState.IsValid)
     {
         db.Entry(karaoke).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(karaoke));
 }
コード例 #6
0
        /// <summary>
        /// Devuelve un <see cref="Karaoke"/> con las sílabas de romaji divididas a partir de una <see cref="Line"/>.
        /// </summary>
        /// <param name="linea">Linea cuyo contenido contenga romaji.</param>
        public static Karaoke SplitSyllabes(Line linea)
        {
            // Karaoke resultante.
            var karaoke = new Karaoke();

            // Palabras del karaoke.
            var palabras = linea.Content.Split(' ').ToList();

            // Dividiendo palabras.
            for (var i = 0; i < palabras.Count; i++)
            {
                var palabra = palabras[i];

                // Si es romaji, se divide cada sílaba.
                if (IsRomaji(palabra))
                {
                    var regex   = new Regex(RegularExpressions.RegexRomaji);
                    var matches = regex.Matches(palabra);

                    foreach (Match match in matches)
                    {
                        karaoke.AgregarSilaba(0, match.Value, KaraokeType.Kf);
                    }
                }
                else
                {
                    // Si no es romaji, se agrega completa.
                    karaoke.AgregarSilaba(0, palabra, KaraokeType.Kf);
                }

                if (i != palabras.Count - 1)
                {
                    karaoke.Syllabes.Last().Text += " ";
                }
            }

            // Tiempo de sílabas.
            var tiempoSil = (int)Math.Round((linea.Length * 100 / karaoke.Syllabes.Count));

            // Agregando el tiempo a cada sílaba.
            karaoke.Syllabes.ForEach(sil => {
                sil.Length = tiempoSil;
            });

            // Ajustando última sílaba para completar el tiempo de línea.
            if (karaoke.Length != linea.Length * 100)
            {
                var delta = linea.Length - karaoke.Length / 100;

                // Por hacer: Agregar if mayor o menor.
                karaoke.Syllabes.Last().Length += (int)delta;
            }

            return(karaoke);
        }
コード例 #7
0
        public ActionResult Create([Bind(Include = "Id,Venue,AvailableDate,Address")] Karaoke karaoke)
        {
            if (ModelState.IsValid)
            {
                db.Karaokes.Add(karaoke);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(karaoke));
        }
コード例 #8
0
        // GET: Karaokes/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Karaoke karaoke = db.Karaokes.Find(id);

            if (karaoke == null)
            {
                return(HttpNotFound());
            }
            return(View(karaoke));
        }
コード例 #9
0
        /// <summary>
        /// Devuelve una lista con dos líneas correspondientes al contenido de una <see cref="Line"/> dividido en el índice indicado.
        /// </summary>
        /// <param name="lineaKaraoke"><see cref="Line"/> cuyo contenido es divisible como romaji.</param>
        /// <param name="indice">Indice de sílaba donde dividir la línea.</param>
        public static List <Line> SplitKaraoke(Line lineaKaraoke, int indice)
        {
            var listaLineas = new List <Line>();
            var karaoke     = new Karaoke(lineaKaraoke.Content);

            var sil = (from x in karaoke.Syllabes
                       select x.Text).ToList();

            // Sílaba de inicio para la segunda, iniciando justo después de la anterior.
            var inicioSegunda = indice + 1;

            // Verificando que no se seleccione un espacio en blanco ni que sea nulo para la segunda línea,
            // a excepción de que sea la última opción.
            while (sil[inicioSegunda] == "" || sil[inicioSegunda] == " ")
            {
                if (inicioSegunda != sil.Count)
                {
                    inicioSegunda++;
                }
            }

            // Generando suma total en centésimas de segundo de tiempos de la primera línea.
            var tiempo1Double = 0.0;

            for (var i = 0; i < indice + 1; i++)
            {
                tiempo1Double = tiempo1Double + karaoke.Syllabes[i].Length;
            }

            // Pasando a segundos.
            tiempo1Double = tiempo1Double / 100;

            // Generando tiempo.
            var tiempo1 = new Time(tiempo1Double);

            // Generando suma total en centésimas de segundo de tiempos de la segunda línea.
            var tiempo2Double = 0.0;

            for (var i = inicioSegunda; i < sil.Count; i++)
            {
                tiempo2Double = tiempo2Double + karaoke.Syllabes[i].Length;
            }

            // Pasando a segundos.
            tiempo2Double = tiempo2Double / 100;

            // Generando tiempo.
            var tiempo2 = new Time(tiempo2Double);

            // Generando primera línea.
            var linea1 = new Line(lineaKaraoke)
            {
                Content = ""
            };

            linea1.End = tiempo1 + linea1.Start;

            // Agregando sílabas correspondientes.
            for (var i = 0; i < indice + 1; i++)
            {
                linea1.Content += karaoke.Syllabes[i].ToString();
            }

            // Generando segunda línea.
            var linea2 = new Line(lineaKaraoke)
            {
                Content = ""
            };

            linea2.Start = linea2.End - tiempo2;

            // Agregando sílabas correspondientes.
            for (var i = inicioSegunda; i < sil.Count; i++)
            {
                linea2.Content += karaoke.Syllabes[i].ToString();
            }

            listaLineas.Add(linea1);
            listaLineas.Add(linea2);

            return(listaLineas);
        }
コード例 #10
0
        public IActionResult Fixembed(string Id, string t = "", string c = "", string cId = "", string u = "", string s = "UnembedabbleVideo", string rId = "", int hq = 0)
        {
            var karaoke = _db.Karaokes;

            if (hq == 1)
            {
                var k = karaoke.Find(Id);
                if (k != null)
                {
                    k.IsHQ            += 1;
                    k.FlagBy           = u;
                    _db.Entry(k).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    _db.SaveChanges();
                }
                else
                {
                    var newk = new Karaoke();
                    newk.Id        = Id;
                    newk.Title     = t;
                    newk.ChannelId = cId;
                    newk.Channel   = c;
                    newk.IsHQ      = 1;
                    newk.FlagBy    = u;
                    karaoke.Add(newk);
                    _db.SaveChanges();
                }
                return(Json(new { hq = "❤" }));
            }
            else if (hq == -1 && !string.IsNullOrEmpty(Id))
            {
                var k = karaoke.Find(Id);
                if (k != null)
                {
                    k.IsHQ            -= 1;
                    k.FlagBy           = u;
                    _db.Entry(k).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    _db.SaveChanges();
                }
                else
                {
                    var newk = new Karaoke();
                    newk.Id        = Id;
                    newk.Title     = t;
                    newk.ChannelId = cId;
                    newk.Channel   = c;
                    newk.IsHQ      = -1;
                    newk.FlagBy    = u;
                    karaoke.Add(newk);
                    _db.SaveChanges();
                }
                return(Json(new { hq = "👎" }));
            }

            var ReplaceId = string.Empty;

            if (karaoke != null)
            {
                ReplaceId = karaoke.Where(x => x.Id == Id).Select(k => k.ReplaceId).FirstOrDefault();
            }


            if (!string.IsNullOrEmpty(ReplaceId) && string.IsNullOrEmpty(rId))
            {
                return(Json(new { replaceId = ReplaceId }));
            }
            else if (!string.IsNullOrEmpty(Id) && !string.IsNullOrEmpty(rId))
            {
                //ReplaceId
                if (string.IsNullOrEmpty(ReplaceId))
                {
                    var k = karaoke.Find(Id);
                    if (k != null)
                    {
                        k.Title            = string.IsNullOrEmpty(t) ? k.Title : t;
                        k.ReplaceId        = rId;
                        _db.Entry(k).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                        _db.SaveChanges();
                    }
                }
                else
                {
                    var k = new Karaoke();
                    k.Id        = Id;
                    k.Title     = t;
                    k.IsHQ      = 0;
                    k.ReplaceId = rId;
                    karaoke.Add(k);
                    _db.SaveChanges();
                }
                return(Content($"Added replaceId [{rId}] to Id [{Id}] {t}"));
            }
            else if (!string.IsNullOrEmpty(Id))
            {
                if (karaoke != null && karaoke.Where(x => x.Id == Id).Count() == 0)
                {
                    _db.Karaokes.Add(new Karaoke {
                        Id = Id, Title = t, ChannelId = cId, Channel = c, FixBy = u, Status = s
                    });
                    _db.SaveChanges();
                }
                var jobId = BackgroundJob.Enqueue <IUtube>(x => x.DownloadVideo(Id, t, cId, c, u));
                BackgroundJob.ContinueWith <IUtube>(jobId, x => x.UploadVideo(Id, t, cId, c, u));
                BackgroundJob.Schedule <IUtube>(x => x.DeleteVideo(Id), TimeSpan.FromHours(1));
                return(Json(new { replaceId = string.Empty, replaceMsg = "Removing playback protection for " + t.ToUpper() }));
            }
            else
            {
                string result = "=== YOUTUBE UNEBEDDABLE & HQ VIDEOS ===";
                result += "[VIDEO ID] ==> [REPLACE ID]  [TITLE] [FIXBY] [HQ] [FLAGBY]";
                if (karaoke != null)
                {
                    foreach (var k in karaoke)
                    {
                        result += $"{Environment.NewLine} {k.Id} ==> {k.ReplaceId}   {k.Title} [{k.FixBy}]  {(k.IsHQ > 0 ? "HQ:" + k.IsHQ : "LQ:"+k.IsHQ)} [{k.FlagBy}] ";
                    }
                }
                return(Content(result));
            }
        }