musicfiledb.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:synthesizer 作者: irmen 项目源码 文件源码
def _add_itunes_library(self, path):
        """
        Read the iTunes music library index xml from the given path and use all songs in there
        instead of scanning all files in the given path.
        """
        print("Importing iTunes music library.")
        itunes_idx = os.path.join(path, "iTunes Music Library.xml")
        if not os.path.isfile(itunes_idx):
            itunes_idx = os.path.join(path, "iTunes Library.xml")
        with open(itunes_idx, "rb") as fp:
            library = plistlib.load(fp)
            tracks = library["Tracks"]
            print("iTunes library contains {:d} entries.".format(len(tracks)))
            music_folder = urllib.request.url2pathname(urllib.parse.urlparse(library["Music Folder"]).path)
            if music_folder.endswith(('/', '\\')):
                music_folder = music_folder[:-1]
            music_folder = os.path.split(music_folder)[0] + os.path.sep
        tracks = (Track.from_itunes(t, music_folder, path)
                  for t in tracks.values()
                  if t["Track Type"] == "File" and not t.get("Podcast") and
                  t.get("Genre", "").lower() not in ("audio book", "audiobook") and
                  "document" not in t.get("Kind", ""))
        amount_new = self.add_tracks(tracks)
        print("Added {:d} new tracks.".format(amount_new))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号