/* pclinkscan v0.5 by Paul Halloran (paul@paulhalloran.com) This program produces a nodesfile.txt file which can be used in conjunction with Nathan Peterson's pclink.pl to create make your MP3s accessable on your Philips Streamium. Makes use of code from: Jason Motylinski's id3v2.1 application This code is released under the GPL. Please read the GPL readme file provided with this code. Thanks to: Dominic Weiß James Tewkesbury */ using System; using System.IO; using System.Collections; using System.Text; using System.Xml; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Diagnostics; using System.Reflection; [assembly: AssemblyTitle("pclinkscan")] [assembly: AssemblyDescription("Utility to produce a nodesfile.txt to be used with pclink.pl")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("")] [assembly: AssemblyCopyright("GPL")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: AssemblyVersion("0.5.1")] namespace PCLinkScan { /// /// PCLinkScan scans a directory of MP3 and M3U files and will produce a nodesfile.txt file to be used with pclink.pl /// See www.paulhalloran.com/streamium for details /// class Class1 { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { int parammarker=0; StringBuilder options = new StringBuilder(); for (int i=0;iparammarker+2) { sStreamsPath=args[parammarker+2]; } ID3 thisMP3; ArrayList arFiles; ArrayList arPlayLists; ScanDir(sPath,out arFiles,out arPlayLists); if (arFiles==null) { Console.Write("No files found"); return; } ArrayList arNodeFile = new ArrayList(); arNodeFile.Add("#"); arNodeFile.Add("1;Streams;"); arNodeFile.Add("#"); arNodeFile.Add("#"); arNodeFile.Add("#"); arNodeFile.Add("#"); arNodeFile.Add("#"); int streamsNode=1; int artistNode=2; int artistalbumNode=3; int albumNode=4; int playlistNode=5; int trackNode=6; int nodePointer=7; bool bInserted; string lengthString=""; ArrayList arMP3s = new ArrayList(); if (options.ToString().IndexOf("r")==-1) { if (File.Exists(sPath+Path.DirectorySeparatorChar+".pclinkscan.tmp")) { try { FileStream s = File.OpenRead(sPath+Path.DirectorySeparatorChar+".pclinkscan.tmp"); BinaryFormatter b = new BinaryFormatter(); arMP3s = (ArrayList) b.Deserialize(s); s.Close(); Console.WriteLine("Skipping "+arMP3s.Count+" tracks indexed in previous run. Use -r option to override this."); } catch { arMP3s=new ArrayList(); } } } string thisFileName; bool dup; for (int j=0;j0) { ArrayList AlbumIndexer = new ArrayList(); getIndexer(ref AlbumIndexer); indexPointer=0; int albums=0; Album tmpAlbum; thisAlbum=""; StringBuilder albumsList = null; //Write albums to nodesfile for (int i=0;i0) { StreamReader sr; String searchFile; String input; String listName; StringBuilder playList; bool foundItem=false; bool fileEnd; string zeroChar=((char)0).ToString(); ArrayList PlaylistIndexer = new ArrayList(); getIndexer(ref PlaylistIndexer); trackindexPointer=0; tracks=-1; for (int i=0;i0) { if (topIndex==null) topIndex = new StringBuilder("0;Top;"+playlistNode.ToString()); else topIndex.Append(","+playlistNode.ToString()); } break; case "T": if (topIndex==null) topIndex = new StringBuilder("0;Top;"+trackNode.ToString()); else topIndex.Append(","+trackNode.ToString()); break; } } arNodeFile[0]=topIndex.ToString(); } else { string topNode="0;Top;1,2,3,4,5,6"; if (!bStreamsExist) topNode=topNode.Replace("1,",""); if (arPlayLists.Count==0) topNode=topNode.Replace(",5",""); arNodeFile[0]=topNode; } //Streamium seems to use iso-8859-1 (Latin1) charset. It doesn't like Unicode! try { for (int k=0;k=0) { tmpIndex=new Index(((Index)Indexer[indexPointer]).index); tmpIndex.id=index; Indexer[indexPointer]=tmpIndex; indexPointer++; } } } public static string indexFinish(ref ArrayList Indexer, ref int indexPointer, int finalIndex) { Index tmpIndex; for (int j=indexPointer;j> 1) & 63) | ((Buffer[1] & 3) << 6) ; nb[1] = ((Buffer[1] >> 2) & 31) | ((Buffer[0] & 7) << 5) ; nb[0] = ((Buffer[0] >> 3) & 15) ; FrameSize = 10 + (long)nb[3] | ((long)nb[2] << 8) | ((long)nb[1] << 16) | ((long) nb[0] << 24) ; long i=0; long fs=1; string thisData=""; while(i0) { data = new StringBuilder(); i+=10; oFS.Seek(i, SeekOrigin.Begin); oFS.Read(Buffer,0,4); tagName=instEncoding.GetString(Buffer).Substring(0,4); oFS.Seek(i+4, SeekOrigin.Begin); oFS.Read(Buffer,0,4); fs = ((long)Buffer[0] << 24) + ((long)Buffer[1] << 16) +((long)Buffer[2] << 8) + ((long)Buffer[3]); if (tagName=="TIT2"||tagName=="TPE1"||tagName=="TALB"||tagName=="TRCK"||tagName=="TLEN") { byte[] s = new byte[fs]; oFS.Seek(i+10, SeekOrigin.Begin); oFS.Read(s,0,(int)fs); Decoder d = Encoding.UTF7.GetDecoder(); char[] chars = new Char[d.GetCharCount(s,0,(int)fs)]; int charLen = d.GetChars(s, 0,s.Length, chars, 0); for(int j=0;j0) { thisTag.songLength=length*1000; break; } } } } iOffset=iOffset+1024; } while (iOffset