如何解决使用元数据在计算机上搜索 mp3/mp4 - tinytag python
问题
我正在尝试使用 os.walk 在我的计算机上搜索与标签元数据匹配的 mp3 和 mp4。我希望能够搜索 Mario,并根据歌曲名称或艺术家、专辑显示歌曲或视频列表。
我正在使用 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)
,但我不确定在哪里应用它来提取以搜索查询开头或匹配的结果的特定结果。
任何想法或建议将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。