Ejemplo n.º 1
0
 // TODO change this method to more understandable
 public long GetSize(VkNet.Model.Attachments.Audio audio)
 {
     if (cacheDictionary.ContainsKey(audio.Id))
     {
         return(cacheDictionary[audio.Id]);
     }
     try
     {
         //from http://stackoverflow.com/questions/122853/get-http-file-size
         System.Net.WebRequest req = System.Net.HttpWebRequest.Create(audio.Url);
         req.Method = "HEAD";
         using (System.Net.WebResponse resp = req.GetResponse())
         {
             long length;
             if (long.TryParse(resp.Headers.Get("Content-Length"), out length))
             {
                 cacheDictionary[audio.Id] = length;
                 Save();
                 return(length);
             }
             return(0);
         }
     }
     catch (Exception) { return(0); }
 }
Ejemplo n.º 2
0
        //Remove record from cache and delete local file
        public async void DeleteFromCache(VkNet.Model.Attachments.Audio Audio)
        {
            string predicate = DBTable.Audio.Columns[1].Name;

            predicate += " == ";
            predicate += Audio.Id;
            predicate += " AND ";
            predicate += DBTable.Audio.Columns[2].Name;
            predicate += " == ";
            predicate += Audio.OwnerId;
            List <object> response = DB.Select(DBTable.Audio, predicate);

            if (response.Count == 0)
            {
                return;
            }
            await Task.Run(() =>
            {
                DB.Remove(DBTable.Audio, Convert.ToInt32((response[0] as object[])[0]));
                string path = Environment.CurrentDirectory + Constants.CacheDirAudioSuffix + "\\" + CachePath(Audio);
                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
            });
        }
Ejemplo n.º 3
0
        //Get full path for audio
        private string DownloadPath(VkNet.Model.Attachments.Audio Audio)
        {
            string name = Audio.Artist + " - " + Audio.Title;

            foreach (char CHR in _BadSymbs)
            {
                name = String.Join("_", name.Split(CHR));
            }
            return((string)this.GetConfigValue(ConfigDefault.AudioDownloadDir) + "\\" + name + ".mp3");
        }
Ejemplo n.º 4
0
 private void DownloadAudio(VkNet.Model.Attachments.Audio Audio)
 {
     if (!_DownloadQueue.Contains(Audio))
     {
         _DownloadQueue.Add(Audio);
     }
     if (!_bw.IsBusy)
     {
         _bw.RunWorkerAsync();
     }
 }
Ejemplo n.º 5
0
 public void RemoveFromPlaylist(VkNet.Model.Attachments.Audio Audio)
 {
     if (PlaylistChanged != null)
     {
         var audioList = new List <KeyValuePair <int, VkNet.Model.Attachments.Audio> >();
         audioList.Add(new KeyValuePair <int, VkNet.Model.Attachments.Audio>(_PlayList.IndexOf(Audio), Audio));
         PlaylistChanged(this, new PlaylistChangedEventArgs(PlaylistChangeType.Remove, audioList));
     }
     _PlayList.Remove(Audio);
     this.Log(MessageStatus.Info, LogStrings.Info.Audio.Player.PlaylistDell + GetAudioFileName(Audio));
 }
Ejemplo n.º 6
0
        public static string GetRightNameAudio(VkNet.Model.Attachments.Audio audio)
        {
            string Name = audio.Artist + "↨" + audio.Title;
            var    per  = Name.LastIndexOfAny(new[] { '\\', '/', '?', ':', '*', '/', '>', '<', '|', '\"' });

            while (per != -1)
            {
                Name = Name.Remove(per, 1);
                per  = Name.LastIndexOfAny(new[] { '\\', '/', '?', ':', '*', '/', '>', '<', '|', '\"' });
            }

            return(Name);
        }
Ejemplo n.º 7
0
 public void UpdateAudioBitrate(VkNet.Model.Attachments.Audio audio)
 {
     //background worker here because of server requests
     // return Task.Run(() =>
     //      {
     if (!SizeGetterToDo.Contains(audio))
     {
         SizeGetterToDo.Add(audio);
     }
     if (!FileSizeGetter.IsBusy && _canRunFileSizeGetter)
     {
         FileSizeGetter.RunWorkerAsync();
     }
     //      });
 }
Ejemplo n.º 8
0
        //Save localy to defined folder
        public void Download(VkNet.Model.Attachments.Audio Audio)
        {
            string downDir = (string)GetConfigValue(ConfigDefault.AudioDownloadDir);

            if (!Directory.Exists(downDir))
            {
                Directory.CreateDirectory(downDir);
            }

            _DownloadQueue.Add(Audio);
            if (!_DownloaderBW.IsBusy)
            {
                _DownloaderBW.RunWorkerAsync();
            }

            this.Log(MessageStatus.Info, LogStrings.Info.Audio.StartedDownloading + Audio.Artist + " - " + Audio.Title);
        }
Ejemplo n.º 9
0
 public AudioSongEditor(NullUtilVK.Categories.Audio AudioApi, VkNet.Model.Attachments.Audio Audio)
 {
     InitializeComponent();
     this._AudioApi = AudioApi;
     this._Audio    = Audio;
 }
Ejemplo n.º 10
0
 //Get local audio cahce name
 private string CachePath(VkNet.Model.Attachments.Audio Audio)
 {
     return(Audio.OwnerId.ToString() + "_" + Audio.Id.ToString() + ".mp3");
 }
Ejemplo n.º 11
0
 //Get audio url
 private string WebPath(VkNet.Model.Attachments.Audio Audio)
 {
     return(Audio.Url.ToString().Split('?')[0]);
 }
Ejemplo n.º 12
0
        //Remove from user's audio
        public void Delete(VkNet.Model.Attachments.Audio Audio)
        {
            this.ApiAudio.Delete(Convert.ToUInt64(Audio.Id), (long)Audio.OwnerId);

            this.Log(MessageStatus.Info, LogStrings.Info.Audio.Deleted + Audio.Artist + " - " + Audio.Title);
        }