用于创建音乐播放列表的 Python 模块(Windows) [英] Python module to create music playlist (windows)

查看:39
本文介绍了用于创建音乐播放列表的 Python 模块(Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个简单的 python 脚本来查看文件夹和子文件夹,并使用包含 mp3 的文件夹的名称创建一个播放列表.但到目前为止,我只遇到过在 linux 上运行的 python 模块,或者我不知道如何安装它们 (pymad)..

I want to create a simple python script that look into folders and subfolders and create a playlist with the name of the folder containing the mp3's. But so far I have only came across python modules that work on linux OR I could not figure out howto install them (pymad)..

它仅适用于我的 android 手机,因此我认为 m3u 格式应该可以做到.除了 mp3 文件本身的名称之外,我不关心任何其他元数据.

It's just for my android mobile so figured that the m3u format should do it.. I don't care for any other meta data than the name of the mp3 files themself.

推荐答案

我其实只是看了http://en.wikipedia.org/wiki/M3U 并看到编写 m3u 文件非常容易......应该能够通过简单的 python 写入文本文件来做到这一点`

I actually just looked at http://en.wikipedia.org/wiki/M3U and saw that it is quite easy to write m3u files... should be able to do it with simple python write to text file`

这是我的解决方案

import os
import glob

dir = os.getcwd()

for (path, subdirs, files) in os.walk(dir):
    os.chdir(path)
    if glob.glob("*.mp3") != []:
        _m3u = open( os.path.split(path)[1] + ".m3u" , "w" )
        for song in glob.glob("*.mp3"):
            _m3u.write(song + "\n")
        _m3u.close()

os.chdir(dir) # Not really needed.. 

这篇关于用于创建音乐播放列表的 Python 模块(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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