使用 awk 在 zenity 列表中获取详细信息

使用 awk 在 zenity 列表中获取详细信息

我正在使用 youtube-dl 来获取视频及其格式。这是我的代码

youtube-dl -F https://www.youtube.com/watch?v=uvr1xiEaICU |awk 'NR > 5 { print}' | zenity  --list  --column "youtube"

这是列表框中的结果

249          webm       audio only DASH audio , opus @ 50k
250          webm       audio only DASH audio , opus @ 70k
251          webm       audio only DASH audio , opus @160k
140          m4a        audio only DASH audio  128k , m4a_dash container, aac  @128k (44100Hz), 4.21MiB
171          webm       audio only DASH audio  131k , audio@128k (44100Hz), 3.90MiB
160          mp4        256x138    DASH video  110k , 12fps, video only, 3.60MiB
278          webm       256x138    DASH video  113k , webm container, VP9, 12fps, video only, 2.82MiB
133          mp4        426x230    DASH video  252k , 24fps, video only, 8.10MiB
242          webm       426x230    DASH video  263k , 24fps, video only, 5.86MiB
243          webm       640x346    DASH video  482k , 24fps, video only, 10.34MiB
134          mp4        640x346    DASH video  609k , 24fps, video only, 13.93MiB
244          webm       854x462    DASH video  818k , 24fps, video only, 17.30MiB
135          mp4        854x462    DASH video 1114k , 24fps, video only, 27.40MiB
247          webm       1280x692   DASH video 1621k , 24fps, video only, 31.78MiB
136          mp4        1280x692   DASH video 2229k , 24fps, video only, 52.99MiB
17           3gp        176x144    
36           3gp        320x240    
5            flv        400x240    
43           webm       640x360    
18           mp4        640x360    
22           mp4        1280x720   (best)

上述代码的问题在于,它将所有这些数据发布在 zenity 列表框中的单个列 (youtube) 中。我希望这些详细信息在列表框中的单独列中

例如

 I            F            A             D              R

249     |     webm   |    audio only| DASH audio | opus @ 50k etc

其中 I、F、A、D、R 是列

答案1

这是您的解决方案

youtube-dl -F https://www.youtube.com/watch\?v\=uvr1xiEaICU | sed 's/audio only/audio only  /' | awk -F'\\s{3,}| , ' 'NR>5 {for(i=1;i<=5;i++){print $i}}' | zenity --list --column="I" --column="F" --column="A" --column="D" --column="R"

解释

命令

youtube-dl -F https://www.youtube.com/watch\?v\=uvr1xiEaICU

返回

[youtube] uvr1xiEaICU: Downloading webpage
[youtube] uvr1xiEaICU: Extracting video information
[youtube] uvr1xiEaICU: Downloading DASH manifest
[info] Available formats for uvr1xiEaICU:
format code  extension  resolution note
249          webm       audio only DASH audio , opus @ 50k
250          webm       audio only DASH audio , opus @ 70k
251          webm       audio only DASH audio , opus @160k
140          m4a        audio only DASH audio  128k , m4a_dash container, aac  @128k (44100Hz), 4.21MiB
171          webm       audio only DASH audio  131k , audio@128k (44100Hz), 3.90MiB
160          mp4        256x138    DASH video  110k , 12fps, video only, 3.60MiB
278          webm       256x138    DASH video  113k , webm container, VP9, 12fps, video only, 2.82MiB
133          mp4        426x230    DASH video  252k , 24fps, video only, 8.10MiB
242          webm       426x230    DASH video  263k , 24fps, video only, 5.86MiB
243          webm       640x346    DASH video  482k , 24fps, video only, 10.34MiB
134          mp4        640x346    DASH video  609k , 24fps, video only, 13.93MiB
244          webm       854x462    DASH video  818k , 24fps, video only, 17.30MiB
135          mp4        854x462    DASH video 1114k , 24fps, video only, 27.40MiB
247          webm       1280x692   DASH video 1621k , 24fps, video only, 31.78MiB
136          mp4        1280x692   DASH video 2229k , 24fps, video only, 52.99MiB
17           3gp        176x144    
36           3gp        320x240    
5            flv        400x240    
43           webm       640x360    
18           mp4        640x360    
22           mp4        1280x720   (best)

我们需要一个经过修改的列表:

sed 's/audio only/audio only  /' | awk -F'\\s{3,}| , ' 'NR>5 {for(i=1;i<=5;i++){print $i}}'

输出:

249
webm
audio only
DASH audio
opus @ 50k
250
webm
audio only
DASH audio
opus @ 70k
251
webm
audio only
DASH audio
opus @160k
140
m4a
audio only
DASH audio  128k
m4a_dash container, aac  @128k (44100Hz), 4.21MiB
171
webm
audio only
DASH audio  131k
audio@128k (44100Hz), 3.90MiB
160
mp4
256x138
DASH video  110k
12fps, video only, 3.60MiB
278
webm
256x138
DASH video  113k
webm container, VP9, 12fps, video only, 2.82MiB
133
mp4
426x230
DASH video  252k
24fps, video only, 8.10MiB
242
webm
426x230
DASH video  263k
24fps, video only, 5.86MiB
243
webm
640x346
DASH video  482k
24fps, video only, 10.34MiB
134
mp4
640x346
DASH video  609k
24fps, video only, 13.93MiB
244
webm
854x462
DASH video  818k
24fps, video only, 17.30MiB
135
mp4
854x462
DASH video 1114k
24fps, video only, 27.40MiB
247
webm
1280x692
DASH video 1621k
24fps, video only, 31.78MiB
136
mp4
1280x692
DASH video 2229k
24fps, video only, 52.99MiB
17
3gp
176x144


36
3gp
320x240


5
flv
400x240


43
webm
640x360


18
mp4
640x360


22
mp4
1280x720
(best)

zenity

zenity --list --column="I" --column="F" --column="A" --column="D" --column="R"

我们有这个:

在此处输入图片描述

相关内容