The problem
I am trying to search my computer using os.walk for mp3s and mp4s that match the tag metadata. I want to be able to search for Mario, and a list of songs or videos come up based on the song name, or artists, album.
I am using Tinytag to get the metadata from the file but I don't know how to apply both OS.walk and Tinytag to search my computer based on song name, artists or album.
TinyTag documentation: https://pypi.org/project/tinytag/
Example code of how tinytag works:
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)
Results:
This track is by Hidenor Shoji.
It is 154.087267 seconds long.
How my os.walk search works currently. Right now I have it set to only find the first five results:
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")
Results:
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 I can find a way to combine the two, I would have what I need. I tried doing some if statestaments like: if TinyTag.get(name) or if TinyTag.get(music) but I am not sure where to apply it to pull the specific results for results that start with or match the search query.
Any ideas or suggestions would be appreciated.
Aucun commentaire:
Enregistrer un commentaire