Ejemplo n.º 1
0
        protected MetaInfo PerformUpdateMetaInfo()
        {
            MetaInfo ConcurrentSong = this._CurrentSong;

            if (this.Status == ConnectionStatus.Recording && System.Threading.Monitor.TryEnter(LastManager.UpdateLocker))
            {
                try
                {
                    System.IO.File.AppendAllText(PathSettings.TempPath + System.IO.Path.DirectorySeparatorChar + "thelastripper.log",
                                                 "\n -Start update");

                    HttpWebRequest hReq = (HttpWebRequest)WebRequest.Create(this.ServiceURL + "np.php?session=" + this.SessionID + "&debug=0");
                    hReq.Timeout = 10000;
                    System.IO.File.AppendAllText(PathSettings.TempPath + System.IO.Path.DirectorySeparatorChar + "thelastripper.log",
                                                 "\n - URL :" + this.ServiceURL + "np.php?session=" + this.SessionID + "&debug=0");
                    HttpWebResponse hRes           = (HttpWebResponse)hReq.GetResponse();
                    Stream          ResponseStream = hRes.GetResponseStream();

                    System.Byte[] Buffer = new System.Byte[LastManager.ProtocolBufferSize];

                    System.Int32 Count = ResponseStream.Read(Buffer, 0, Buffer.Length);

                    //WebClient Client = new WebClient();
                    //System.String data = Client.DownloadString(this.ServiceURL + "np.php?session=" + this.SessionID + "&debug=0");


                    ConcurrentSong = new MetaInfo(Encoding.UTF8.GetString(Buffer, 0, Count));                     // data;
                    //return ConcurrentSong;
                }
                catch (System.Exception e)
                {
                    System.IO.File.AppendAllText(PathSettings.TempPath + System.IO.Path.DirectorySeparatorChar + "thelastripper.log",
                                                 "\n - Update timeout ERROR: " + e.Message + e.StackTrace);
                    //		System.Threading.Monitor.Exit(LastManager.UpdateLocker);
                    //System.Threading.Thread.CurrentThread.Abort();
                }
                finally
                {
                    System.IO.File.AppendAllText(PathSettings.TempPath + System.IO.Path.DirectorySeparatorChar + "thelastripper.log",
                                                 "\n - Update finished");
                    System.Threading.Monitor.Exit(LastManager.UpdateLocker);
                }
            }
            return(ConcurrentSong);
        }
		protected MetaInfo PerformUpdateMetaInfo()
		{
			MetaInfo ConcurrentSong = this._CurrentSong;
			if (this.Status == ConnectionStatus.Recording && System.Threading.Monitor.TryEnter(LastManager.UpdateLocker))
			{
				try
				{
					System.IO.File.AppendAllText(PathSettings.TempPath + System.IO.Path.DirectorySeparatorChar + "thelastripper.log",
										 "\n -Start update");

					HttpWebRequest hReq = (HttpWebRequest)WebRequest.Create(this.ServiceURL + "np.php?session=" + this.SessionID + "&debug=0");
					hReq.Timeout = 10000;
					System.IO.File.AppendAllText(PathSettings.TempPath + System.IO.Path.DirectorySeparatorChar + "thelastripper.log",
											 "\n - URL :" + this.ServiceURL + "np.php?session=" + this.SessionID + "&debug=0");
					HttpWebResponse hRes = (HttpWebResponse)hReq.GetResponse();
					Stream ResponseStream = hRes.GetResponseStream();

					System.Byte[] Buffer = new System.Byte[LastManager.ProtocolBufferSize];

					System.Int32 Count = ResponseStream.Read(Buffer, 0, Buffer.Length);

					//WebClient Client = new WebClient();
					//System.String data = Client.DownloadString(this.ServiceURL + "np.php?session=" + this.SessionID + "&debug=0");


					ConcurrentSong = new MetaInfo(Encoding.UTF8.GetString(Buffer, 0, Count)); // data;
					//return ConcurrentSong;
				}
				catch (System.Exception e)
				{
					System.IO.File.AppendAllText(PathSettings.TempPath + System.IO.Path.DirectorySeparatorChar + "thelastripper.log",
										 "\n - Update timeout ERROR: " + e.Message + e.StackTrace);
					//		System.Threading.Monitor.Exit(LastManager.UpdateLocker);
					//System.Threading.Thread.CurrentThread.Abort();
				}
				finally
				{
					System.IO.File.AppendAllText(PathSettings.TempPath + System.IO.Path.DirectorySeparatorChar + "thelastripper.log",
										 "\n - Update finished");
					System.Threading.Monitor.Exit(LastManager.UpdateLocker);
				}
			}
			return ConcurrentSong;
		}
Ejemplo n.º 3
0
        protected void UpdateMetaInfoCallBack(System.IAsyncResult Res)
        {
            PerformUpdateMetaInfoDelegate SendDelegate = (PerformUpdateMetaInfoDelegate)((System.Runtime.Remoting.Messaging.AsyncResult)Res).AsyncDelegate;
            MetaInfo ConcurrentSong = SendDelegate.EndInvoke(Res);

            if (this._CurrentSong == null || !this._CurrentSong.Streaming)
            {
                this._CurrentSong = ConcurrentSong;
                if (this._CurrentSong.Streaming)
                {
                    this.SetTimer();
                    if (this.OnNewSong != null)
                    {
                        this.OnNewSong(this, ConcurrentSong);
                    }
                }
                else
                {
                    this.SetTimer(5000);
                }
            }
            else
            {
                if (!MetaInfo.Equals(ConcurrentSong, this._CurrentSong))
                {
                    //Perform on new thread, perhaps not needed at all...
                    //Since all we are doing is IO work, not networking...
                    this.SaveSong(this._CurrentSong);

                    this._CurrentSong = ConcurrentSong;
                    if (this.OnNewSong != null)
                    {
                        this.OnNewSong(this, ConcurrentSong);
                    }
                    this.SetTimer();
                }
            }
        }
Ejemplo n.º 4
0
        protected void SaveSong(MetaInfo SongInfo)
        {
            System.Boolean DownloadCovers = false;
            System.String  AlbumPath      = "";
            System.String  NewFilePath    = "";

            lock (LastManager.StreamLocker)
            {
                Stream       RadioStream = (Stream)this.ReadHandle.AsyncState;
                System.Int32 Count       = RadioStream.EndRead(this.ReadHandle);

                if (this.SkipSave || !SongInfo.Streaming)
                {
                    //Close file
                    this.TempFile.Close();

                    //Create or overwrite tempfile
                    this.TempFile = File.Create(PathSettings.TempFilePath);

                    //Start recording agian
                    this.ReadHandle = RadioStream.BeginRead(this.Buffer, 0, this.Buffer.Length, new System.AsyncCallback(this.TempSave), RadioStream);

                    //Change SkipSave
                    this.SkipSave = false;
                }
                else
                {
                    //Write last data from stream
                    this.TempFile.Write(this.Buffer, 0, Count);

                    //Write metadata to stream as ID3v1
                    SongInfo.AppendID3(this.TempFile);

                    //Write the file, and close it
                    this.TempFile.Flush();
                    this.TempFile.Close();
                    this.TempFile.Dispose();

                    //Filesystem paths
                    AlbumPath   = this.MusicPath + System.IO.Path.DirectorySeparatorChar + LastManager.RemoveIllegalChars(SongInfo.Artist) + System.IO.Path.DirectorySeparatorChar + LastManager.RemoveIllegalChars(SongInfo.Album) + System.IO.Path.DirectorySeparatorChar;
                    NewFilePath = AlbumPath + LastManager.RemoveIllegalChars(SongInfo.Track) + ".mp3";

                    //Dont overwrite file if it already exist, new rip may be bad, and we should leave it to the user to sort them manually
                    if (File.Exists(NewFilePath))
                    {
                        File.Delete(PathSettings.TempFilePath);
                    }
                    else
                    {
                        if (!Directory.Exists(AlbumPath))
                        {
                            Directory.CreateDirectory(AlbumPath);
                        }
                        File.Move(PathSettings.TempFilePath, NewFilePath);
                    }

                    //Create or overwrite tempfile
                    this.TempFile = File.Create(PathSettings.TempFilePath);

                    //Start recording agian
                    this.ReadHandle = RadioStream.BeginRead(this.Buffer, 0, this.Buffer.Length, new System.AsyncCallback(this.TempSave), RadioStream);

                    //Set download covers, do this outside the lock.
                    DownloadCovers = true;
                }
            }
            if (DownloadCovers)
            {
                //Download covers
                WebClient Client = new WebClient();

                if ((!File.Exists(AlbumPath + "SmallCover.jpg")) && SongInfo.AlbumcoverSmall != null)
                {
                    Client.DownloadFile(SongInfo.AlbumcoverSmall, AlbumPath + "SmallCover.jpg");
                }

                if ((!File.Exists(AlbumPath + "MediumCover.jpg")) && SongInfo.AlbumcoverMedium != null)
                {
                    Client.DownloadFile(SongInfo.AlbumcoverMedium, AlbumPath + "MediumCover.jpg");
                }

                if ((!File.Exists(AlbumPath + "LargeCover.jpg")) && SongInfo.AlbumcoverLarge != null)
                {
                    Client.DownloadFile(SongInfo.AlbumcoverLarge, AlbumPath + "LargeCover.jpg");
                }
            }
        }
Ejemplo n.º 5
0
 protected void SetTimer(MetaInfo SongInfo)
 {
     this.SetTimer(System.Convert.ToDouble(SongInfo.Trackduration) * 1000);
 }
		protected void SaveSong(MetaInfo SongInfo)
		{
			System.Boolean DownloadCovers = false;
			System.String AlbumPath = "";
			System.String NewFilePath = "";

			lock (LastManager.StreamLocker)
			{
				Stream RadioStream = (Stream)this.ReadHandle.AsyncState;
				System.Int32 Count = RadioStream.EndRead(this.ReadHandle);

				if (this.SkipSave || !SongInfo.Streaming)
				{
					//Close file
					this.TempFile.Close();

					//Create or overwrite tempfile
					this.TempFile = File.Create(PathSettings.TempFilePath);

					//Start recording agian
					this.ReadHandle = RadioStream.BeginRead(this.Buffer, 0, this.Buffer.Length, new System.AsyncCallback(this.TempSave), RadioStream);

					//Change SkipSave
					this.SkipSave = false;
				}
				else
				{

					//Write last data from stream
					this.TempFile.Write(this.Buffer, 0, Count);

					//Write metadata to stream as ID3v1
					SongInfo.AppendID3(this.TempFile);

					//Write the file, and close it
					this.TempFile.Flush();
					this.TempFile.Close();
					this.TempFile.Dispose();

					//Filesystem paths
					AlbumPath = this.MusicPath + System.IO.Path.DirectorySeparatorChar + LastManager.RemoveIllegalChars(SongInfo.Artist) + System.IO.Path.DirectorySeparatorChar + LastManager.RemoveIllegalChars(SongInfo.Album) + System.IO.Path.DirectorySeparatorChar;
					NewFilePath = AlbumPath + LastManager.RemoveIllegalChars(SongInfo.Track) + ".mp3";

					//Dont overwrite file if it already exist, new rip may be bad, and we should leave it to the user to sort them manually
					if (File.Exists(NewFilePath))
					{
						File.Delete(PathSettings.TempFilePath);
					}
					else
					{
						if (!Directory.Exists(AlbumPath))
						{
							Directory.CreateDirectory(AlbumPath);
						}
						File.Move(PathSettings.TempFilePath, NewFilePath);
					}

					//Create or overwrite tempfile
					this.TempFile = File.Create(PathSettings.TempFilePath);

					//Start recording agian
					this.ReadHandle = RadioStream.BeginRead(this.Buffer, 0, this.Buffer.Length, new System.AsyncCallback(this.TempSave), RadioStream);

					//Set download covers, do this outside the lock.
					DownloadCovers = true;
				}
			}
			if (DownloadCovers)
			{
				//Download covers
				WebClient Client = new WebClient();

				if ((!File.Exists(AlbumPath + "SmallCover.jpg")) && SongInfo.AlbumcoverSmall != null)
					Client.DownloadFile(SongInfo.AlbumcoverSmall, AlbumPath + "SmallCover.jpg");

				if ((!File.Exists(AlbumPath + "MediumCover.jpg")) && SongInfo.AlbumcoverMedium != null)
					Client.DownloadFile(SongInfo.AlbumcoverMedium, AlbumPath + "MediumCover.jpg");

				if ((!File.Exists(AlbumPath + "LargeCover.jpg")) && SongInfo.AlbumcoverLarge != null)
					Client.DownloadFile(SongInfo.AlbumcoverLarge, AlbumPath + "LargeCover.jpg");
			}
		}
		protected void SetTimer(MetaInfo SongInfo)
		{
			this.SetTimer(System.Convert.ToDouble(SongInfo.Trackduration) * 1000);
		}
		protected void UpdateMetaInfoCallBack(System.IAsyncResult Res)
		{
			PerformUpdateMetaInfoDelegate SendDelegate = (PerformUpdateMetaInfoDelegate)((System.Runtime.Remoting.Messaging.AsyncResult)Res).AsyncDelegate;
			MetaInfo ConcurrentSong = SendDelegate.EndInvoke(Res);

			if (this._CurrentSong == null || !this._CurrentSong.Streaming)
			{
				this._CurrentSong = ConcurrentSong;
				if (this._CurrentSong.Streaming)
				{
					this.SetTimer();
					if (this.OnNewSong != null)
					{
						this.OnNewSong(this, ConcurrentSong);
					}
				}
				else
				{
					this.SetTimer(5000);
				}
			}
			else
			{
				if (!MetaInfo.Equals(ConcurrentSong, this._CurrentSong))
				{
					//Perform on new thread, perhaps not needed at all... 
					//Since all we are doing is IO work, not networking...
					this.SaveSong(this._CurrentSong);

					this._CurrentSong = ConcurrentSong;
					if (this.OnNewSong != null)
					{
						this.OnNewSong(this, ConcurrentSong);
					}
					this.SetTimer();
				}
			}

		}