-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also allows navigating media within the browser or rather provides directory listings html
- Loading branch information
1 parent
34d6bd7
commit 1e55715
Showing
4 changed files
with
93 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import re | ||
|
||
def parse_playlist(filepath): | ||
# CAUTION: attribute values that contain ',' or ' ' are not supported | ||
extinf_regex = re.compile(r'^#EXTINF:([0-9]+)( [^,]+)?,[\s]*(.*)') | ||
with open(filepath, 'r', encoding='UTF-8') as file: | ||
linenum = 0 | ||
item = PlaylistItem() | ||
while line := file.readline(): | ||
line = line.rstrip() | ||
linenum += 1 | ||
if linenum == 1: | ||
assert line == '#EXTM3U', 'File is not an EXTM3U playlist!' | ||
continue | ||
if len(line.strip()) == 0: | ||
continue | ||
m = extinf_regex.match(line) | ||
if m: | ||
item = PlaylistItem() | ||
duration = m.group(1) | ||
item.duration = int(duration) | ||
attrs = m.group(2) | ||
if attrs: | ||
item.attrs = {k: v.strip('"') for k,v in [kv.split('=') for kv in attrs.strip().split(' ')]} | ||
item.title = m.group(3) | ||
continue | ||
if line.startswith('#'): | ||
continue | ||
item.uri = line | ||
yield item | ||
item = PlaylistItem() | ||
|
||
class PlaylistItem(): | ||
def __init__(self): | ||
self.title = None | ||
self.duration = None | ||
self.uri = None | ||
self.attrs = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters