Example #1
0
 static void Main(string[] args)
 {
     Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
     Logger.SetLogger(new LoggerHelper());
     try {
         var command = CommandLine.Parse(args);
         var ids     = command.GetValue("-id");
         var path    = command.GetValue("-path");
         var type    = command.GetValueDefault("-type", "");
         if (string.IsNullOrWhiteSpace(ids))
         {
             throw new Exception("请添加id");
         }
         path = System.IO.Path.Combine(Environment.CurrentDirectory, path ?? "");
         Task.Run(async() => {
             foreach (var id in ids.Split(","))
             {
                 try {
                     await MusicFactory.Create(type).Download(id, path);
                 } catch (Exception e) {
                     Logger.error($"下载 {id} 失败 : {e.ToString()}");
                 }
             }
         }).Wait();
     } catch (Exception e) {
         Logger.error("Error : " + e.ToString());
     }
 }
    static async Task <SearchResult> SearchAll(string key)
    {
        var items = new List <IMusic>();
        var sr    = new SearchResult
        {
            Items      = items,
            Keyword    = key,
            Page       = -1,
            SearchType = EnumSearchType.all,
        };
        dynamic obj = await NetAccess.Json(XiamiUrl.url_search_all, "key", key);

        if (obj == null)
        {
            return(sr);
        }
        foreach (var type in new string[] { "song", "album", "artist", "collect" })
        {
            dynamic data = obj[type + "s"];
            if (data == null)
            {
                continue;
            }
            foreach (dynamic x in data)
            {
                items.Add(MusicFactory.CreateFromJson(x, (EnumMusicType)Enum.Parse(typeof(EnumMusicType), type)));
            }
        }
        return(sr);
    }
Example #3
0
        public void musicplay()
        {
            DateTime Mutime = Rmes.DA.Base.DB.GetServerTime();
            string   time   = Mutime.ToString("HH:mm");
            //string hour = Mutime.Hour.ToString();
            //string munite = Mutime.Minute.ToString();
            // string time = hour + ":" + munite;
            //MessageBox.Show(time );


            List <MusicEntity> Mlist = MusicFactory.GetAllMusic();

            for (int i = 0; i < Mlist.Count; i++)
            {
                if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPlaying)
                {
                    return;
                }
                //if (lib.MP3isPlaying == true)
                //    return;
                if (time == Mlist[i].ANDON_TIME)
                {
                    axWindowsMediaPlayer1.URL = Mlist[i].ANDON_MUSIC;
                    //lib.MP3PlayFile(Mlist[i].ANDON_MUSIC);
                    //axWindowsMediaPlayer1.Ctlcontrols.play();
                }
            }
        }
    static List <IMusic> GetArtist(dynamic json)
    {
        var items = new List <IMusic>();

        try
        {
            items.Add(MusicFactory.CreateFromJson(json["artist"], EnumMusicType.artist));
        }
        catch { }
        return(items);
    }
    static List <IMusic> GetSongsOfArtist(dynamic json)
    {
        var items = new List <IMusic>();

        try
        {
            foreach (var x in json["songs"])
            {
                items.Add(MusicFactory.CreateFromJson(x, EnumMusicType.song));
            }
        }
        catch { }
        return(items);
    }
Example #6
0
        public IActionResult Song(string songPath)
        {
            if (MusicFactory.DoesSoundExist(songPath))
            {
                return(File(MusicFactory.GetSong(songPath), "audio/mpeg"));
            }

            string[] paths = MusicFactory.GetSounds().Where(c => c.StartsWith(songPath)).ToArray();
            if (paths.Length > 0)
            {
                return(Json(paths));
            }

            return(NotFound());
        }
    static List <IMusic> GetAlbum(dynamic json)
    {
        var items = new List <IMusic>();

        try
        {
            if (json["album"] != null)
            {
                json = json["album"];
            }
            items.Add(MusicFactory.CreateFromJson(json, EnumMusicType.album));
        }
        catch { }
        return(items);
    }
    static List <IMusic> GetSimilarsOfArtist(dynamic json)
    {
        var items = new List <IMusic>();

        try
        {
            var obj = json["artists"];
            foreach (var x in obj)
            {
                items.Add(MusicFactory.CreateFromJson(x, EnumMusicType.artist));
            }
        }
        catch { }
        return(items);
    }
    static List <IMusic> GetSong(dynamic json)
    {
        List <IMusic> res = new List <IMusic>();

        try
        {
            if (json["song"] != null)
            {
                json = json["song"];
            }
            var song = MusicFactory.CreateFromJson(json, EnumMusicType.song);
            res.Add(song);
        }
        catch { }
        return(res);
    }
    static List <IMusic> GetSongsOfAlbum(dynamic json)
    {
        var items = new List <IMusic>();

        try
        {
            if (json["album"] != null)
            {
                json = json["album"];
            }
            foreach (var x in json["songs"])
            {
                Song a = MusicFactory.CreateFromJson(x, EnumMusicType.song);
                items.Add(a);
            }
        }
        catch { }
        return(items);
    }
    static List <IMusic> GetSongsOfCollect(dynamic json)
    {
        var items = new List <IMusic>();

        try
        {
            if (json["collect"] != null)
            {
                json = json["collect"];
            }
            foreach (var x in json["songs"])
            {
                string id   = x["song_id"];
                Song   song = MusicFactory.CreateFromJson(x, EnumMusicType.song);
                items.Add(song);
            }
        }
        catch { }
        return(items);
    }
    async static Task <SearchResult> _searchByKey(string keyword, int page, EnumMusicType type = EnumMusicType.song)
    {
        dynamic obj = await NetAccess.Json(XiamiUrl.url_search_all, "key", keyword, "page", page.ToString());

        /////////////
        if (obj == null)
        {
            return(null);
        }
        //string typestr = type.ToString();
        //dynamic obj = await XiamiClient.GetDefault().Call_xiami_api(string.Format("Search.{0}s", typestr),
        //    string.Format("\"key={0}\"", keyword),
        //    string.Format("page={0}", page));
        //if (obj == null) return null;
        dynamic data = obj[type.ToString() + "s"];

        if (data == null)
        {
            return(null);
        }
        var items = new List <IMusic>();

        foreach (dynamic x in data)
        {
            items.Add(MusicFactory.CreateFromJson(x, type));
        }
        var searchType = EnumSearchType.song;

        Enum.TryParse <EnumSearchType>(type.ToString(), out searchType);
        bool hasNext = page.ToString() != obj["next"];
        var  res     = new SearchResult
        {
            Items      = items,
            Keyword    = keyword,
            Page       = page,
            HasNext    = hasNext,
            SearchType = searchType,
        };

        return(res);
    }
Example #13
0
        public Engine(/* final */ EngineOptions pEngineOptions)
        {
            Engine.Instance = this;

            //TextureRegionFactory.setAssetBasePath("");
            TextureRegionFactory.SetAssetBasePath("");
            //SoundFactory.setAssetBasePath("");
            SoundFactory.SetAssetBasePath("");
            //MusicFactory.setAssetBasePath("");
            MusicFactory.SetAssetBasePath("");
            //FontFactory.setAssetBasePath("");
            FontFactory.setAssetBasePath("");

            //BufferObjectManager.setActiveInstance(this.mBufferObjectManager);
            BufferObjectManager.SetActiveInstance(this.mBufferObjectManager);

            this.mEngineOptions = pEngineOptions;
            //this.SetTouchController(new SingleTouchController());
            this.TouchController = new SingleTouchController();
            //this.mCamera = pEngineOptions.getCamera();
            this.mCamera = pEngineOptions.GetCamera();

            if (this.mEngineOptions.NeedsSound())
            {
                this.mSoundManager = new SoundManager();
            }

            if (this.mEngineOptions.NeedsMusic())
            {
                this.mMusicManager = new MusicManager();
            }

            if (this.mEngineOptions.HasLoadingScreen())
            {
                this.InitLoadingScreen();
            }

            this.mUpdateThread.Start();
        }
Example #14
0
        public IActionResult GetBGM(int mapId)
        {
            Map map = MapFactory.GetMap(mapId);

            return(File(MusicFactory.GetSong(map.BackgroundMusic), "audio/mpeg"));
        }
Example #15
0
 public IActionResult List(
     [FromQuery] int startPosition = 0,
     [FromQuery] int?count         = null
     ) => Json(MusicFactory.GetSounds(startPosition, count));
    static async Task getUserMusic(string key)
    {
        bool isKeyValidMusicType = new Regex("^(song|album|artist|collect)$").IsMatch(key.Trim());
        var  searchType          = EnumSearchType.song;
        var  musicType           = EnumMusicType.song;

        if (isKeyValidMusicType)
        {
            Enum.TryParse(key, out searchType);
            Enum.TryParse(key, out musicType);
        }
        int page = 1;

        while (true)
        {
            dynamic obj = null;
            if (key == "daily")
            {
                obj = await XiamiClient.GetDefault().Call_xiami_api("Recommend.DailySongs");
            }
            else if (key == "guess")
            {
                if (!isGuessUsed)
                {
                    await Http.Get("http://www.xiami.com/index/feeds", null);

                    isGuessUsed = true;
                }
                musicType  = EnumMusicType.all;
                searchType = EnumSearchType.all;
                var html = await Http.Get(string.Format(XiamiUrl.url_recommend_guess, page), null);

                var doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(html);
                obj      = new JObject();
                obj.alls = new JArray();
                HtmlNodeCollection nodes = null;
                nodes = doc.DocumentNode.SelectNodes("*[contains(concat(' ', @class, ' '), ' album ')]");
                if (nodes != null)
                {
                    foreach (var x in nodes)
                    {
                        string id, name, artist_id, artist_name;
                        string logo = x.SelectSingleNode(".//img").Attributes["src"].Value;
                        getIdName(x, "/album/", out id, out name);
                        getIdName(x, "/artist/", out artist_id, out artist_name);
                        try
                        {
                            obj.alls.Add(JObject.Parse(string.Format(@"
                            {{
                                Type: 'album',
                                album_id : '{0}',
                                album_name : '{1}',
                                artist_id : '{2}',
                                artist_name : '{3}',
                                logo:'{4}',
                            }}", id, name, artist_id, artist_name, logo)));
                        }
                        catch
                        {
                        }
                    }
                }
                nodes = doc.DocumentNode.SelectNodes("*[contains(concat(' ', @class, ' '), ' collect ')]");
                if (nodes != null)
                {
                    foreach (var x in nodes)
                    {
                        string id, name, artist_id, artist_name;
                        string logo = x.SelectSingleNode(".//img").Attributes["src"].Value;
                        getIdName(x, "/song/showcollect/id/", out id, out name);
                        getIdName(x, "/u/", out artist_id, out artist_name);
                        try
                        {
                            obj.alls.Add(JObject.Parse(string.Format(@"
                    {{
                        Type: 'collect',
                        list_id : '{0}',
                        collect_name : '{1}',
                        user_id : '{2}',
                        user_name : '{3}',
                        logo:'{4}',
                    }}", id, name, artist_id, artist_name, logo)));
                        }
                        catch
                        {
                        }
                    }
                }
            }
            else if (key == "collect_recommend")
            {
                musicType  = EnumMusicType.collect;
                searchType = EnumSearchType.collect;
                obj        = await XiamiClient.GetDefault().Call_xiami_api("Collects.recommend");
            }
            else if (isKeyValidMusicType)
            {
                obj = await NetAccess.Json(XiamiUrl.url_lib_music, "music", key, "uid", Global.AppSettings["xiami_uid"], "page", page.ToString());
            }
            else
            {
                Logger.Error(new Exception("user:"******" is not supported"));
                break;
            }
            if (obj == null)
            {
                break;
            }
            var items = new List <IMusic>();
            if (obj[musicType.ToString() + "s"] != null)
            {
                obj = obj[musicType.ToString() + "s"] as dynamic;
            }
            foreach (dynamic item in obj)
            {
                try
                {
                    EnumMusicType t = musicType;
                    if (item["Type"] != null)
                    {
                        Enum.TryParse(item["Type"].ToString(), out t);
                    }
                    items.Add(MusicFactory.CreateFromJson(item, t));
                }
                catch (Exception e)
                {
                }
            }
            var sr = new SearchResult {
                Keyword = "user:"******"song")
            {
                foreach (Song item in sr.Items)
                {
                    item.InFav = true;
                }
            }
            SearchManager.notifyState(sr);
            //if (obj.more != null && obj.more != "true")
            //    break;
            page++;
        }
    }