55"""
66
77from rich .progress import Progress , SpinnerColumn , TextColumn , TimeElapsedColumn , BarColumn
8+ from urllib .parse import urlparse
89
910import warnings
1011
@@ -63,6 +64,15 @@ def _dispatch(command, lang, num_speakers,
6364 files = []
6465 outputs = []
6566
67+ if kwargs .get ("data" ):
68+ url = kwargs .get ("data" )
69+ url = urlparse (url )
70+ if url .scheme == "" :
71+ url = url ._replace (scheme = "http" )
72+ base = os .path .basename (url .path )
73+ files .append (url )
74+ outputs .append (os .path .join (out_dir , base ))
75+
6676 for basedir , _ , fs in os .walk (in_dir ):
6777 for f in fs :
6878 path = Path (os .path .join (basedir , f ))
@@ -128,7 +138,8 @@ def _dispatch(command, lang, num_speakers,
128138 errors = []
129139 # create the spinner bars
130140 for f in files :
131- tasks [f ] = prog .add_task (Path (f ).name , start = False , processor = "" )
141+ tasks [f ] = prog .add_task (Path (f ).name if isinstance (f , str ) else Path (f .geturl ()).name ,
142+ start = False , processor = "" )
132143
133144 # create pipeline and read files
134145 baL .debug ("Attempting to create BatchalignPipeline for CLI..." )
@@ -152,7 +163,7 @@ def progress_callback(file, step, total, tools):
152163 prog .start_task (tasks [file ])
153164 with warnings .catch_warnings (record = True ) as w :
154165 # parse the input format, as needed
155- doc = loader (os .path .abspath (file ))
166+ doc = loader (os .path .abspath (file ) if isinstance ( file , str ) else file . geturl () )
156167 # if we ended up with a tuple of length two,
157168 # that means that the loader requested kwargs
158169 kw = {}
@@ -179,7 +190,7 @@ def progress_callback(file, step, total, tools):
179190 if len (errors ) > 0 :
180191 C .print ()
181192 for file , trcbk , e in errors :
182- C .print (f"[bold red]ERROR[/bold red] on file [italic]{ os .path .relpath (str (Path (file ).absolute ()), in_dir )} [/italic]: { escape (str (e ))} \n " )
193+ C .print (f"[bold red]ERROR[/bold red] on file [italic]{ os .path .relpath (str (Path (file ).absolute ()), in_dir ) if isinstance ( file , str ) else file . geturl () } [/italic]: { escape (str (e ))} \n " )
183194 if ctx .obj ["verbose" ] == 1 :
184195 C .print (escape (str (trcbk )))
185196 elif ctx .obj ["verbose" ] > 1 :
0 commit comments