Uncategorized
Music Aggregator!
by Dean Thomas on Mar.08, 2008, under Uncategorized
Hey anyone who actually reads this.
I’m sick of searching for a music video, or trying to find lyrics without getting innundated with my web browser making noises and slowing down because annoying popups want to abuse my machine. So this project (side project, not spending much time on it…) is gunna fix all my issues.
With an AmazonAPI Hooked in, i can search for artists. I’m in the process of writing a Lyrics web scraper and after that is videos (YouTube, etc) so that i can have all the info i need about a band in one place. Google is a wonderful thing, but everything in one place is much more efficient.
Anywho, here is the current url (Removed) it doens’t do much except cache the results, as the AmazonAPI has restrictions on how often i can speak to them (1 hit per second) it’s better i cache the results as it’ll speed up the search and prevent Amazon removing my account.
If anyone could just type in a few random bands, i would be greatful. I just need the content then i can haveĀ a bigger website, community driven effectively.
I don’t want to hear about bugs, crashes, slowness, this is so far from being ready it’s not true. But you can never have enough content, hence the release.
I will be writing a simple MP3 Tag Reader that’ll run through my collection of music, populating the DB too, should anyone be interested in devoting some time to running an app through their collection i will be greatful (just leave a comment). Sourcecode will be released with of course to prove i’m not about to chuck a worm onto your machine.
Cheers!
Dean
Usenet ReadLine()
by Dean Thomas on Feb.12, 2008, under Uncategorized
Ever tried writing a Usenet client before? Even a simple little one that just downloads an image from your favourite group.
Well, it can be a pain. The spec is simple enough, everything is explained well in the 2 RFCs. But a couple of things weren’t so clear when i started.
First off, the curse of the double dot. For most Usenet calls (Body, Head, etc) its way of notifying you that it has finished sending you data, is to send you a ‘.’. Which is great, nice simple way to let me know that you have finished sending me the information.
However, when you receive a file from usenet, you tend to do it line by line, so you can check for such an end of message. But what if your line of data starts with a ‘.’ because, well it just might. It just adds another ‘.’, so it now becomes ‘..’ which is fine, because i know it’s not the end of the message, and i can just carry on as normal. Do NOT forget to remove one of those ‘.’ otherwise your file will appear as ‘corrupt’ even though it may only be one byte at the end.
Secondly, the encoding. I spent ages trying to figure out why my files were completely different to what they should be, and why my results werent matching up with what say Outlook express could return me. For those of you that didn’t know, Outlook express is a pretty neat Usenet client, terrible as an email client however.
Anywho, usenet files are posted as iso-8859-1, so any file saving that gets done, MUST use that encoding, or again corruption. Imagine not removing a . and saving with the wrong encoding, thats a fun debugging session.
Well, i have attached a sample function that will read a line response from Usenet, and return it as a string (iso-8859-1). It handles the double dot, at the end of the function as you can see.
I Hope this helps someone and saves them more problems than i had…
D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | public string ReadLine() { ArrayList returnedBytes = new ArrayList(); byte[] previousByte = new byte[1]; byte[] thisByte = new byte[1]; NetworkStream reader = ServerConnection.GetStream(); while (true) { //Read a byte, check it int received = reader.Read(thisByte, 0, 1); //Check the byte, let's see what it is... if (received == 1) { bool addByte = false; bool endOfLine = false; //Check if we have a previous byte switch ((char)previousByte[0]) { case '\r'://Ignore this byte, it's probably a \n addByte = true; break; default: //No previous byte addByte = true; break; } //Check for New Line if ((char)thisByte[0] == '\n' && (char)previousByte[0] == '\r') { endOfLine = true; } //Set the previous byte previousByte[0] = thisByte[0]; //Add this byte? if (addByte) returnedBytes.Add(thisByte[0]); //Is this the end of the line? if (endOfLine) break; } else { break; } } Encoding usenetEncoding = Encoding.GetEncoding("iso-8859-1"); string finalLine = usenetEncoding.GetString((byte[])returnedBytes.ToArray()); if (finalLine.StartsWith("..")) finalLine = finalLine.Remove(0, 1); return finalLine; } |