Пример #1
0
        public static LyricClass getTxtItem(string item, int i)
        {
            LyricClass tmp = new LyricClass();

            var lines = File.ReadAllLines(item, Encoding.UTF8);

            var _backslackIdx = item.LastIndexOf(@"\");

            // id
            tmp.id = i;
            // name
            tmp.name = lines[1];
            // composer
            tmp.composer = lines[3];
            // filename
            var _fileName = item.Substring(_backslackIdx + 1, item.Length - _backslackIdx - 1);

            tmp.filename = _fileName;
            // url
            tmp.url = item;
            // type
            tmp.type = "txt";
            // last updated
            tmp.updated = DateTime.ParseExact(lines[5], "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
            // last recent
            tmp.updated = DateTime.ParseExact(lines[7], "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
            // rate
            try
            {
                tmp.rate = int.Parse(lines[9]);
            }
            catch
            {
                tmp.rate = 0;
            }
            // is favorite
            try
            {
                tmp.isFavorite = int.Parse(lines[11]);
            }
            catch
            {
                tmp.isFavorite = 0;
            }
            // link
            tmp.link = lines[13];
            // content
            //var len = lines.Length;
            //string[] result = new string[len-15];
            //Array.Copy(lines, 15, result, 0, len-15);
            //tmp.content = string.Join("\n", result);
            tmp.content = string.Join("\n", lines);

            return(tmp);
        }
Пример #2
0
        public static LyricClass getLyricInfo(string item, int i)
        {
            LyricClass tmp = new LyricClass();

            var _backslackIdx = item.LastIndexOf(@"\");
            var _minusIdx     = item.LastIndexOf("-");
            var _dotIdx       = item.LastIndexOf(".");

            // id
            tmp.id = i;

            // name
            var _name = item.Substring(_backslackIdx + 1, _minusIdx - _backslackIdx - 1);

            while (_name[0] == ' ')
            {
                _name = _name.Substring(1, _name.Length - 1);
            }
            while (_name[_name.Length - 1] == ' ')
            {
                _name = _name.Substring(0, _name.Length - 1);
            }
            tmp.name = _name;

            // composer
            var _composer = item.Substring(_minusIdx + 1, _dotIdx - _minusIdx - 1);

            while (_composer[0] == ' ')
            {
                _composer = _composer.Substring(1, _composer.Length - 1);
            }
            while (_composer[_composer.Length - 1] == ' ')
            {
                _composer = _composer.Substring(0, _composer.Length - 1);
            }
            tmp.composer = _composer;

            // filename
            var _fileName = item.Substring(_backslackIdx + 1, item.Length - _backslackIdx - 1);

            tmp.filename = _fileName;

            // url
            tmp.url = item;

            // type
            var _type = item.Substring(_dotIdx + 1, item.Length - _dotIdx - 1);

            tmp.type = _type;

            return(tmp);
        }
Пример #3
0
        public Task <List <LyricClass> > GetVOALyric(string id)
        {
            return(Task.Run(async() =>
            {
                HttpResponseMessage response = await new SimRequest().SimPost("http://apps.iyuba.cn/voa/textApi.jsp?voaid=" + id + "&format=json");
                List <LyricClass> lyric = new List <LyricClass>();

                string jsonstr = response.Content.ReadAsStringAsync().Result;
                JsonSerializer serializer = new JsonSerializer();
                TextReader tr = new StringReader(jsonstr);
                JsonTextReader jtr = new JsonTextReader(tr);
                object obj = serializer.Deserialize(jtr);

                StringWriter textWriter = new StringWriter();
                JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
                {
                    Formatting = Formatting.Indented,
                    Indentation = 4,
                    IndentChar = ' '
                };
                serializer.Serialize(jsonWriter, obj);

                LyricJsonClass.RootObject rb1 = JsonConvert.DeserializeObject <LyricJsonClass.RootObject>(textWriter.ToString());

                List <LyricCreator> lyrics = new List <LyricCreator>();
                List <string> ParaId = new List <string>();
                List <string> IdIndex = new List <string>();
                List <string> Announcer = new List <string>();
                List <string> Sentence = new List <string>();
                List <string> Sentence_cn = new List <string>();
                List <string> BbcId = new List <string>();
                List <string> Timing = new List <string>();

                foreach (LyricJsonClass.Data data1 in rb1.data)
                {
                    ParaId.Add(data1.ParaId);
                    IdIndex.Add(data1.IdIndex);
                    Announcer.Add(data1.Announcer);
                    Sentence.Add(data1.Sentence);
                    Sentence_cn.Add(data1.sentence_cn);
                    BbcId.Add(data1.BbcId);
                    Timing.Add(data1.Timing);
                }

                for (int i = 0; i < Sentence.Count; i++)
                {
                    LyricClass Lyrics = new LyricClass()
                    {
                        ParaId = ParaId[i],
                        IdIndex = IdIndex[i],
                        Announcer = Announcer[i],
                        Sentence = Sentence[i],
                        Sentence_cn = Sentence_cn[i],
                        BbcId = BbcId[i],
                        Timing = Timing[i]
                    };
                    lyric.Add(Lyrics);
                }

                return lyric;
            }));
        }