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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| Option Explicit
Dim ws,fso,Title,InPutFile,Pattern,OutPutFile,Data,MyString2Find,scriptdir,ALLMyStrings,MyString,M3U_Files
Title = "Extracting Data from M3U file by Word "& chrW(169) &" Hackoo 2020"
If wscript.arguments.count > 0 Then
' The InPutFile is the file to be dragged and dropped over this Vbscript
InPutFile = Wscript.Arguments(0)
Data = ReadFile(InPutFile)
MyString2Find = InPutBox(ExtractFileName(InPutFile) & vbCrLF & "Tapez un ou plusieurs mot(s) à rechercher séparés par un point virgule "";"" : " &_
vbcrlf & vbcrlf &"Exemple : "& vbCrLf &_
"BEIN;RMC;OSN;MYHD;FR;AR;EN;SP;CANAL",Title,"BEIN;RMC;OSN;MYHD;|FR|;FR;AR;|AR|;EN;SP;CANAL;ORANGE;OCS")
IF MyString2Find = "" Then Wscript.Quit(1)
ALLMyStrings = Split(MyString2Find,";")
Set fso = CreateObject("Scripting.FileSystemObject")
'scriptdir = fso.GetParentFolderName(WScript.ScriptFullName)
M3U_Files = GetFilenameWithoutExtension(InPutFile) &"_M3U_Files"
Call SmartCreateFolder(M3U_Files)
For Each MyString In ALLMyStrings
Pattern = Replace("(#EXTINF:-1,"& MyString &").*[\s\S](http://.*)" , "|" ,"\|")
MyString = Replace(MyString ,"|","_")
OutPutFile = MyString & "_" & ExtractFileName(InPutFile)
Write2File "#EXTM3U",M3U_Files &"\"& OutPutFile,2
Write2File Extract(Data,Pattern),M3U_Files &"\"& OutPutFile,8
Next
Explorer M3U_Files
Else
Call Display_Help_Usage()
End If
'-----------------------------------------------------------------
Function Extract(Data,Pattern)
Dim oRE,oMatches,Match,Line
set oRE = New RegExp
oRE.IgnoreCase = True
oRE.Global = True
oRE.Pattern = Pattern
set oMatches = oRE.Execute(Data)
If not isEmpty(oMatches) then
For Each Match in oMatches
Line = Line & Match.Value & vbLf
Next
Extract = Line
End if
End Function
'------------------------------------------------
Function GetFilenameWithoutExtension(FileName)
Dim Result, i
Result = FileName
i = InStrRev(FileName, ".")
If ( i > 0 ) Then
Result = Mid(FileName, 1, i - 1)
End If
GetFilenameWithoutExtension = Result
End Function
'------------------------------------------------
Sub Display_Help_Usage()
Dim ws
Set ws = CreateObject("wscript.shell")
ws.Popup "You should drag and drop a M3U file over this program " & vbCrLF &_
chr(34) & Wscript.ScriptName & chr(34) & vbCrLF &_
" to extract data !",8,Title,vbExclamation
Wscript.Quit(1)
End Sub
'-----------------------------------------------------------------
Sub Explorer(Object)
Dim ws
Set ws = CreateObject("wscript.shell")
ws.run "Explorer /n,/select,"& Object &"",1,True
End Sub
'-----------------------------------------------------------------
Function ReadFile(InPutFile)
Dim objFSO,oTS,sText
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oTS = objFSO.OpenTextFile(InPutFile)
sText = oTS.ReadAll
oTS.close
set oTS = nothing
Set objFSO = nothing
ReadFile = sText
End Function
'-----------------------------------------------------------------
Sub Write2File(strText,OutPutFile,Mode)
Dim fs,ts
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(OutPutFile,Mode,True)
ts.WriteLine strText
ts.Close
End Sub
'-----------------------------------------------------------------
Function ExtractFileName(strMyPath)
ExtractFileName = Mid(strMyPath, InStrRev(strMyPath, "\") + 1)
End Function
'-----------------------------------------------------------------
Sub SmartCreateFolder(strFolder)
With CreateObject("Scripting.FileSystemObject")
If Not .FolderExists(strFolder) then
SmartCreateFolder(.getparentfoldername(strFolder))
.CreateFolder(strFolder)
End If
End With
End Sub
'----------------------------------------------------------------- |
Partager