python - 使用元数据在计算机上搜索 mp3/mp4 - tinytag python
问题描述
问题
我正在尝试使用 os.walk 在我的计算机上搜索与标签元数据匹配的 mp3 和 mp4。我希望能够搜索马里奥,并根据歌曲名称或艺术家、专辑出现歌曲或视频列表。
我正在使用 Tinytag 从文件中获取元数据,但我不知道如何应用 OS.walk 和 Tinytag 根据歌曲名称、艺术家或专辑搜索我的计算机。
TinyTag 文档:https ://pypi.org/project/tinytag/
tinytag 工作原理的示例代码:
from tinytag import TinyTag
tag = TinyTag.get(r"\\Vgmstation\e\Gamecube\F-Zero GX\8 Guitars (Sand Ocean).mp4")
print('This track is by %s.' % tag.artist)
print('It is %f seconds long.' % tag.duration)
结果:
This track is by Hidenor Shoji.
It is 154.087267 seconds long.
我的 os.walk 搜索目前是如何工作的。现在我将其设置为仅查找前五个结果:
import os
import subprocess
def playmusic(name):
count = 0
extf = ['$RECYCLE.BIN','System Volume Information']
for root, dirs, files in os.walk('E:\\', followlinks=True):
dirs[:] = [d for d in dirs if d not in extf]
for file in files:
if name in file and file.endswith(".mp4"):
music=str(os.path.join(file))
musiconly= os.path.splitext(music)[0]
print(musiconly)
count = count + 1
if count == 5:
break
if count >= 5:
break
print("Finish")
input()
try:
s=raw_input("name: ")
playmusic(s)
except Exception as e:
print(e)
print("Error")
结果:
name: te
00044converted
crash crate jump
footy_MAGIX AVC-AAC MP4_Internet HD 1080p 29.97 fps (Intel QSV) final[0]
footy_MAGIX AVC-AAC MP4_Internet HD 1080p 29.97 fps (Intel QSV) final[1]
Untitled3_MAGIX AVC-AAC MP4_Internet HD 1080p 29.97 fps (Intel QSV) final[0]
Finish
如果我能找到一种将两者结合起来的方法,我就会拥有我需要的东西。我尝试做一些 if 语句,例如:if TinyTag.get(name)
或者if TinyTag.get(music)
但我不确定在哪里应用它来提取以搜索查询开头或匹配的结果的特定结果。
任何想法或建议将不胜感激。
解决方案
推荐阅读
- reactjs - (react-route) 嵌套路由访问url时显示404 not found
- python - 错误 - 接受 1 个位置参数,但给出了 2 个
- node.js - React Native:Xcode 12.5 EMFILE:打开的文件太多,看
- pytorch - 扩展 Pytorch:Python vs. C++ vs. CUDA
- python - 如何根据我的训练 csv 文件中的文件名将文件夹中的图像分隔到训练文件夹
- spartacus-storefront - 如何在 Spartacus 店面中创建和使用自定义 API?
- c - SSL_read 函数的错误代码卡住了我
- python - Python,熊猫 DF。从字符串中获取数字并将其添加到新列
- c# - 处置 HttpResponseMessage 是好习惯吗?
- javascript - 检测输入元素的属性(类型)变化