当前位置: 动力学知识库 > 问答 > 编程问答 >

audio - Reading multimedia playlist file in Python (libraries)

问题描述:

Which libraries do you recommend for reading (parsing) multimedia playlist files?, would be useful if the library supports differents playlist formats, like M3U, WPL, and anothers.

For Python i found this page http://wiki.python.org/moin/PythonInMusic, that points to m3ute2 project, but it seems to be dead.

网友答案:

Here is a library to parse playlists. The library relies heavily on correct mimetype of the playlist. There are several samples the library can be tested on. http://t11.mine.nu/playlists_analyser.tar.gz

网友答案:

Like Misha said, they are plain text files so you can parse them pretty easily.

Here's a quick python script I whipped up not too long ago to parse an m3u file and calculate total play time as well as to print the length in minutes:seconds and the name of each song in the playlist.

#!/usr/local/bin/python

import string, sys

def sec_to_days(seconds) :
    return seconds / 86400

def sec_to_hours(seconds) :
    return seconds / 3600

def sec_to_minutes(seconds) :
    return seconds / 60

def sec_to_minutes_seconds(seconds) :
    minutes = sec_to_minutes(seconds)
    sec = seconds % 60
    return "%(n1)02d:%(n2)02d" % {"n1": minutes, "n2": sec}

# If no arguments were given, print a helpful message
if len(sys.argv)==1:
    print 'Usage:  m3utime filename.m3u'

    sys.exit(0)

filename = sys.argv[1]

items = [line.replace("#EXTINF:", "").strip() for line in file(filename) if line.startswith('#EXTINF')]

splitList = [line.split(",") for line in items ]

time = 0
for s in splitList : time = time + int(s[0])

days = sec_to_days(time)
hours = sec_to_hours(time) - (days * 24)
minutes = sec_to_minutes(time) - (days * 1440) - (hours * 60)
seconds = time % 60

print filename + " : " + str(time) + "s\n"

for s in splitList :
    print sec_to_minutes_seconds(int(s[0])), s[1]

print

print "Total play time : " + str(days) + ":" + str(hours) + ":" + str(minutes) + ":" + str(seconds) + "\n"
分享给朋友:
您可能感兴趣的文章:
随机阅读: