'-------------------------------------------------------------- '- Smart Visionの出力するSVIファイルを元に '- Uzuで認識可能なプレイリストを作成する '- '- 無保証です。作者は、いかなる損害も一切の責任を負いません。 '- 2004/3/11 namichin '--------------------------------------------------------------- Option Explicit '************* メイン **************** dim uplFolder,sviFolder '*************************************************************** '* *.upl ファイルを保存するフォルダーを設定してください * '*************************************************************** uplFolder = "c:\uzu\videolist" '*************************************************************** '* *.svi ファイルが保存してあるフォルダーを設定してください * '*************************************************************** sviFolder = "C:\Documents and Settings\All Users\Documents\My Pictures\SVAutoRec" deleteUpl uplFolder checkSVIFiles sviFolder,uplFolder WScript.Echo "すべての処理が終了しました" '****************************************** '* ここから各種のサブルーチン '****************************************** '************ ファイルの削除 *********************** sub DelFile(filespec) dim fso set fso = CreateObject("Scripting.FileSystemObject") fso.DeleteFile(filespec) end sub '************ フォルダの削除 *********************** sub DelFolder(folderspec) dim fso set fso = CreateObject("Scripting.FileSystemObject") fso.DeleteFolder(folderspec) end sub '***フォルダ内のすべてのファイル,フォルダの削除**** sub DeleteAllFiles(folderspec) dim fso, f,files,folders,f1 set fso = CreateObject("Scripting.FileSystemObject") set f = fso.GetFolder(folderspec) set files = f.Files for Each f1 in files DelFile f1 next set folders = f.SubFolders for Each f1 in folders DelFolder f1 next end sub '******** フォルダを作成 ********************* sub CreateFolder(folderspec) dim fso,a set fso = CreateObject("Scripting.FileSystemObject") set a = fso.CreateFolder(folderspec) end sub '******** フォルダの内容をコピー *************** sub CopyFolder(src,dst) FileSystemObject.CopyFolder src,dst end sub '******** 表示用に2桁にした数字を返す ************* function tnum(n) if n < 10 then tnum = "0" & n else tnum = n end if end function '*** sviデータからuplファイルを作成する *********** sub makeUpl(svi,folder) const ForWriting = 2 dim fso, f,upl ' upl = svi.StartYear & "年" & svi.StartMonth & "月" & svi.StartDay & "日" _ ' & svi.StartHour& "時" & svi.StartMinute & "分 " & svi.ProgramName & " " _ ' & svi.ChName & ".upl" ' ' upl = tnum(svi.StartMonth) & "月" & tnum(svi.StartDay) & "日_" _ ' & svi.ProgramName & ".upl" upl = tnum(svi.StartMonth) & "-" & tnum(svi.StartDay) & "_" _ & svi.ProgramName & ".upl" upl = folder & "\" & upl Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile(upl, ForWriting, True,0) f.Writeline svi.DataFileName f.close end sub '***フォルダ内のUPLファイルを削除する**** sub deleteUpl(uplFolder) dim fso, f,files,folders,f1 dim svi set svi = new SviData set fso = CreateObject("Scripting.FileSystemObject") set f = fso.GetFolder(uplFolder) set files = f.Files for Each f1 in files if UCase(right(f1.Name,3)) = "UPL" then delfile f1 end if next end sub '***フォルダ内のSVIファイルを探す**** sub checkSVIFiles(folderspec,uplFolder) dim fso, f,files,folders,f1 dim svi set svi = new SviData set fso = CreateObject("Scripting.FileSystemObject") set f = fso.GetFolder(folderspec) set files = f.Files for Each f1 in files if UCase(right(f1.Name,3)) = "SVI" then GetSviData svi,f1 ' printSviData svi makeUpl svi,uplFolder end if next end sub '************ Svi ファイルの構造体 *********************** Class SviData public Channel,Source,ChName,ProgramName,Infomation,DataFileName public StartYear,StartMonth,StartWeek,StartDay,StartHour public StartMinute,EndYear,EndMonth,EndWeek,EndDay,EndHour,EndMinute public Length,Size,User End Class '************* バイナリデータを文字列に変換 特殊文字を削除**************** Function bin2Str(buf,maxlen) Dim i,outStr,t1,t2,clen,flag flag = 1 clen = LenB(buf) if clen > maxlen then clen = maxlen '最大文字数の指定 for i=1 to clen t1 = ascB(MidB(buf,i,1)) if t1 = 0 then exit for if t1 = &H5B then flag = 0 if t1 = &H5D then flag = 1 if ((t1 >= &H81) and (t1 <= &H9F)) or ((t1 >= &HE0) and (t1 <= &HFC)) then t2 = ascB(MidB(buf,i+1,1)) if ((t2 >= &H40) and (t2 <= &H7E)) or ((t2 >= &H80) and (t2 <= &HFC)) then if flag <> 0 then outStr = outStr + chr(t1*256+ t2) i = i + 1 else if flag <> 0 then outStr = outStr + chr(t1) end if else '文字  |\/<>,:;?"*%&$ は使わない if t1=&H7C or t1=&H5C or t1=&H2F or t1=&H3C or t1=&H3E _ or t1=&H2C or t1=&H3A or t1=&H3B or t1=&H3F or t1=&H22 _ or t1=&H2A or t1=&H25 or t1=&H26 or t1=&H24 then t1=&H5F '&H2D if flag <> 0 and t1 <> &H5D then outStr = outStr + chr(t1) end if next bin2Str = outStr end function '************* バイナリデータを文字列に変換**************** Function bin2Str2(buf,maxlen) Dim i,outStr,t1,t2,clen clen = LenB(buf) if clen > maxlen then clen = maxlen '最大文字数の指定 for i=1 to clen t1 = ascB(MidB(buf,i,1)) if t1 = 0 then exit for if ((t1 >= &H81) and (t1 <= &H9F)) or ((t1 >= &HE0) and (t1 <= &HFC)) then t2 = ascB(MidB(buf,i+1,1)) if ((t2 >= &H40) and (t2 <= &H7E)) or ((t2 >= &H80) and (t2 <= &HFC)) then outStr = outStr + chr(t1*256+ t2) i = i + 1 else outStr = outStr + chr(t1) end if else outStr = outStr + chr(t1) end if next bin2Str2 = outStr end function '************* バイナリデータを2byte整数に変換**************** Function bin2Short(buf) Dim t1,t2 t1 = ascB(MidB(buf,1,1)) t2 = ascB(MidB(buf,2,1)) bin2Short = t2*256 + t1 end function '************* バイナリデータを4byte整数に変換**************** Function bin2Long(buf) Dim t1,t2,t3,t4 t1 = ascB(MidB(buf,1,1)) t2 = ascB(MidB(buf,2,1)) t3 = ascB(MidB(buf,3,1)) t4 = ascB(MidB(buf,4,1)) bin2Long = t4*16777216 + t3*65536 + t2 * 256 + t1 end function '************* SVIデータを読み込む**************** sub GetSviData(svi,filename) Const adTypeBinary = 1 Dim BinaryStream,rd,c ' Dim svi ' set svi = new SviData Set BinaryStream = CreateObject("ADODB.Stream") BinaryStream.Type = adTypeBinary BinaryStream.Open BinaryStream.LoadFromFile filename rd = BinaryStream.Read(8) 'ダミー rd = BinaryStream.Read(2) 'チャンネル svi.Channel = bin2Short(rd) rd = BinaryStream.Read(2) '入力ソース 0:チューナー 4:外部入力 svi.Source = bin2Short(rd) rd = BinaryStream.Read(260) '放送局名 svi.ChName = bin2Str(rd,16) rd = BinaryStream.Read(3072) '番組名 svi.ProgramName = bin2Str(rd,30) rd = BinaryStream.Read(1024) '番組情報 svi.Infomation = bin2Str(rd,4) rd = BinaryStream.Read(256) 'データーファイル名 svi.DataFileName = bin2Str2(rd,512) rd = BinaryStream.Read(4) 'ダミー rd = BinaryStream.Read(2) '録画開始 年 svi.StartYear = bin2Short(rd) rd = BinaryStream.Read(2) '録画開始 月 svi.StartMonth = bin2Short(rd) rd = BinaryStream.Read(2) '録画開始 曜日 svi.StartWeek = bin2Short(rd) rd = BinaryStream.Read(2) '録画開始 日 svi.StartDay = bin2Short(rd) rd = BinaryStream.Read(2) '録画開始 時 svi.StartHour = bin2Short(rd) rd = BinaryStream.Read(2) '録画開始 分 svi.StartMinute = bin2Short(rd) rd = BinaryStream.Read(4) 'ダミー rd = BinaryStream.Read(2) '録画終了 年 svi.EndYear = bin2Short(rd) rd = BinaryStream.Read(2) '録画終了 月 svi.EndMonth = bin2Short(rd) rd = BinaryStream.Read(2) '録画終了 曜日 svi.EndWeek = bin2Short(rd) rd = BinaryStream.Read(2) '録画終了 日 svi.EndDay = bin2Short(rd) rd = BinaryStream.Read(2) '録画終了 時 svi.EndHour = bin2Short(rd) rd = BinaryStream.Read(2) '録画終了 分 svi.EndMinute = bin2Short(rd) rd = BinaryStream.Read(316) 'ダミー rd = BinaryStream.Read(2) '録画時間 svi.Length = bin2Short(rd) rd = BinaryStream.Read(10) 'ダミー rd = BinaryStream.Read(4) 'ファイルのサイズ svi.Size = bin2Long(rd) rd = BinaryStream.Read(2443) 'ダミー rd = BinaryStream.Read(760) '録画したユーザー svi.User = bin2Str(rd,4) BinaryStream.close end sub '************* SVIデータを出力**************** sub printSviData(svi) dim s s = "Channel: " & svi.Channel & vbNewLine s = s & "Source: " & svi.Source & vbNewLine s = s & "ChName: " &svi.ChName & vbNewLine s = s & "ProgramName: " &svi.ProgramName & vbNewLine s = s & "Infomation: " &svi.Infomation & vbNewLine s = s & "DataFileName: " &svi.DataFileName & vbNewLine s = s & "Start: " &svi.StartYear&"/"&svi.StartMonth&"/"&svi.StartDay&" "&svi.StartHour&":"&svi.StartMinute & vbNewLine s = s & "End: " &svi.EndYear&"/"&svi.EndMonth&"/"&svi.EndDay&" "&svi.EndHour&":"&svi.EndMinute & vbNewLine s = s & "Length: " &svi.Length & vbNewLine s = s & "Size: " &svi.Size & vbNewLine s = s & "User: " &svi.User & vbNewLine WScript.Echo s end sub