MCPcopy
hub / github.com/beetbox/beets / __init__

Method __init__

beetsplug/playlist.py:41–85  ·  view source on GitHub ↗
(self, _, pattern: str, __)

Source from the content-addressed store, hash-verified

39 return [BLOB_TYPE(p) for p in self.pattern]
40
41 def __init__(self, _, pattern: str, __):
42 config = beets.config["playlist"]
43
44 # Get the full path to the playlist
45 playlist_paths = (
46 pattern,
47 os.path.abspath(
48 os.path.join(
49 config["playlist_dir"].as_filename(), f"{pattern}.m3u"
50 )
51 ),
52 )
53
54 paths = []
55 for playlist_path in playlist_paths:
56 if not is_m3u_file(playlist_path):
57 # This is not am M3U playlist, skip this candidate
58 continue
59
60 try:
61 f = open(beets.util.syspath(playlist_path), mode="rb")
62 except OSError:
63 continue
64
65 if config["relative_to"].get() == "library":
66 relative_to = beets.config["directory"].as_filename()
67 elif config["relative_to"].get() == "playlist":
68 relative_to = os.path.dirname(playlist_path)
69 else:
70 relative_to = config["relative_to"].as_filename()
71 relative_to_bytes = beets.util.bytestring_path(relative_to)
72
73 for line in f:
74 if line[0] == "#":
75 # ignore comments, and extm3u extension
76 continue
77
78 paths.append(
79 beets.util.normpath(
80 os.path.join(relative_to_bytes, line.rstrip())
81 )
82 )
83 f.close()
84 break
85 super().__init__("path", paths)
86
87
88class PlaylistPlugin(beets.plugins.BeetsPlugin):

Callers 1

__init__Method · 0.45

Calls 4

is_m3u_fileFunction · 0.85
joinMethod · 0.80
getMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected