不显示提取的音频文件的YouTube-DL Python详细信息 [英] YouTube-DL Python details of extracted audio file are not displayed

查看:144
本文介绍了不显示提取的音频文件的YouTube-DL Python详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用python写了一小段代码,以从YouTube视频中提取音频.这是代码:

I have written a small piece of code in python to extract the audio from a YouTube video. Here is the code:

from __future__ import unicode_literals
import youtube_dl

link = input("Enter the video link:")

ydl_opts = {
    'format': 'bestaudio/best',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192',
    }],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    info_dict = ydl.extract_info(link, download=False)
    video_title = info_dict.get('title', None)

path = f'D:\\{video_title}.mp3'

ydl_opts.update({'outtmpl':path})

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download([link])

这是保存输出音频文件的文件夹:

This is the folder where the output audio file is saved:

如您所见,将显示音频文件的所有详细信息,例如修改日期",类型"和大小".

As you can see, all the details of the audio file are displayed, such as Date Modified, Type and Size.

但是,如果将path = f'D:\\{video_title}.mp3'更改为path = f'D:\\YT_Files\\{video_title}.mp3',则不会显示文件详细信息.

However, if I change path = f'D:\\{video_title}.mp3' to path = f'D:\\YT_Files\\{video_title}.mp3', then the file details are not getting displayed.

关于为什么会这样的任何想法吗?有什么办法可以解决这个问题?任何帮助,将不胜感激.谢谢.

Any idea about why this is so? Is there any way to solve this problem? Any help would be appreciated. Thanks.

推荐答案

由于YT_Files是目录,因此可以将路径设置为path = f'D:\\{video_title}.mp3',这将导致显示元数据.然后尝试使用os.system()将文件移动到YT_Files.然后,您应该在YT_Folders上具有元数据.如果不是,那么我认为它是Windows资源管理器的错误.以下代码应该可以工作,但是我不是100%确信此语法将在Windows上工作.

Since YT_Files is a directory, you could set the path as path = f'D:\\{video_title}.mp3' which causes metadata to be displayed. Then try to move the file to YT_Files using os.system(). Then you should have metadata on YT_Folders. If not then its fault of Windows explorer i assume. Following code should work but i am not 100% sure this syntax will work on windows.

from __future__ import unicode_literals
import youtube_dl

link = input("Enter the video link:")

ydl_opts = {
    'format': 'bestaudio/best',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192',
    }],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    info_dict = ydl.extract_info(link, download=False)
    video_title = info_dict.get('title', None)

path = f'D:\\{video_title}.mp3'

ydl_opts.update({'outtmpl':path})

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download([link])
import os
os.system('move D:\\*.mp3 D:\\YT_Files\\')

运行此代码,并检查是否存在元数据.不要通过Windows资源管理器进行检查.转到属性".单击详细信息"选项卡,然后向下滚动. 如果使用Date-ModifiedType查找属性,则问题出在Windows资源管理器/文件资源管理器中,但是如果您没有找到,则我将尝试调试

Run this code and check if metadata is there or not. Dont check by windows explorer. Go to "Properties". Click on the "Details" tab and scroll down. If you find the properties with Date-Modified or Type then the problem is in Windows Explorer/File Explorer but if you dont then i will try to debug

这篇关于不显示提取的音频文件的YouTube-DL Python详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆