Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -5,11 +5,11 @@ SHELL := /bin/bash #(for brace expansion) NAME := streamtuner2 VERSION := $(shell version get:plugin st2.py || echo 2.1dev) DEST := /usr/share/streamtuner2 INST := install -m 644 -PACK := xpm --verbose +PACK := xpm DEPS := -n $(NAME) -d python -d python-pyquery -d python-gtk2 -d python-requests -d python-keybinder OPTS := -s src -u packfile,man,fixperms -f --prefix=$(DEST) --deb-compression xz --rpm-compression xz --exe-autoextract # targets .PHONY: bin @@ -49,11 +49,11 @@ exe: $(PACK) $(OPTS) $(DEPS) -t $@ -p "$(NAME)-VERSION.exe" st2.py pyz: #@BUG: relative package references leave a /tmp/doc/ folder $(PACK) -u packfile -s src -t zip --zip-shebang "/usr/bin/env python" \ - -f -p "$(NAME)-$(VERSION).pyz" --prefix=./ --verbose .zip.py st2.py + -f -p "$(NAME)-$(VERSION).pyz" --prefix=./ .zip.py st2.py src: cd .. && pax -wvJf streamtuner2/streamtuner2-$(VERSION).src.txz \ streamtuner2/*.{py,png,svg,desktop} streamtuner2/channels/*.{py,png} \ streamtuner2/{bundle/,help/,gtk,NEWS,READ,PACK,PKG,CRED,Make,bin,.zip}* Index: action.py ================================================================== --- action.py +++ action.py @@ -34,10 +34,11 @@ from config import conf, __print__ as debug, dbg import platform import copy import json from datetime import datetime +from xml.sax.saxutils import escape as xmlentities, unescape as xmlunescape # Coupling to main window # main = None @@ -98,11 +99,12 @@ ("html", r""" (?i)<(audio|video)\b[^>]+\bsrc\s*=\s*["']?https?:// """), ("wpl", r""" <\?wpl \s+ version="1\.0" \s* \?> """), ("b4s", r""" """), # http://gonze.com/playlists/playlist-format-survey.html ("jspf", r""" ^ \s* \{ \s* "playlist": \s* \{ """), ("asf", r""" ^ \[Reference\] .*? ^Ref\d+= """), - ("json", r""" "url": \s* "\w+:// """), + ("json", r""" "url": \s* "\w+:\\?/\\?/ """), + ("jamj", r""" "audio": \s* "\w+:\\?/\\?/ """), ("gvp", r""" ^gvp_version:1\.\d+$ """), ("href", r""" .* """), ] @@ -233,11 +235,11 @@ # Check ambiguity (except pseudo extension) if len(set([source, mime, probe])) > 1: debug(dbg.ERR, "Possible playlist format mismatch:", (source, mime, probe, ext)) # Extract URLs from content - for fmt in ["pls", "xspf", "asx", "smil", "jspf", "m3u", "json", "asf", "raw"]: + for fmt in ["pls", "xspf", "asx", "smil", "jspf", "m3u", "json", "asf", "jamj", "raw"]: if not urls and fmt in (source, mime, probe, ext, "raw"): urls = extract_playlist(cnt).format(fmt) debug(dbg.DATA, "conversion from:", source, " with extractor:", fmt, "got URLs=", urls) # Return original, or asis for srv targets @@ -297,20 +299,29 @@ self.src = text # Extract only URLs from given source type def format(self, fmt): debug(dbg.DATA, "input regex:", fmt, len(self.src)) - return re.findall(self.extr_urls[fmt], self.src, re.X); + # regex + urls = re.findall(self.extr_urls[fmt], self.src, re.X) + # xml entities + urls = [xmlunescape(url) for url in urls] + # json escaping + urls = [url.replace("\\/", "/") for url in urls] + # uniques + urls = list(set(urls)) + return urls # Only look out for URLs, not local file paths extr_urls = { "pls": r"(?im) ^ \s*File\d* \s*=\s* (\w+://[^\s]+) ", "m3u": r" (?m) ^( \w+:// [^#\n]+ )", "xspf": r" (?x) (\w+://[^<>\s]+) ", "asx": r" (?x) ]+\b href \s*=\s* [\'\"] (\w+://[^\s\"\']+) [\'\"] ", "smil": r" (?x) <(?:audio|video|media)\b [^>]+ \b src \s*=\s* [^\"\']? \s* (\w+://[^\"\'\s]+) ", "jspf": r" (?x) \"location\" \s*:\s* \"(\w+://[^\"\s]+)\" ", + "jamj": r" (?x) \"audio\" \s*:\s* \"(\w+:\\?/\\?/[^\"\s]+)\" ", "json": r" (?x) \"url\" \s*:\s* \"(\w+://[^\"\s]+)\" ", "asf": r" (?m) ^ \s*Ref\d+ = (\w+://[^\s]+) ", "raw": r" (?i) ( [\w+]+:// [^\s\"\'\>\#]+ ) ", } @@ -358,10 +369,11 @@ if not self.source in ("srv", "raw", "asis"): new_rows = [] for i,row in enumerate(rows): # Preferrably convert to direct server addresses for url in convert_playlist(row["url"], self.source, "srv", local_file=False): + row = dict(row.items()) row["url"] = url new_rows.append(row) # Or just allow one stream per station in a playlist entry if not self.multiply: break @@ -441,17 +453,10 @@ txt += """\t\t