Index: action.py ================================================================== --- action.py +++ action.py @@ -223,10 +223,15 @@ log.PROC("convert_playlist(", url, source, dest, ")") # Leave alone if format matches, or if already "srv" URL, or if not http (local path, mms:/rtsp:) if source == dest or source in ("srv", "href") or not re.match("(https?|spdy)://", url): return [url] + + # Reuse tempoary files? + if local_file and conf.reuse_m3u and os.path.exists(tmp_fn(row, dest)): + log.STAT("reuse temporary filename") + return [tmp_fn(row, dest)] # Retrieve from URL (mime, cnt) = http_probe_get(url) # Leave streaming server as is @@ -255,11 +260,11 @@ elif dest in ("srv", "href"): return urls # Otherwise convert to local file if local_file: - fn, is_unique = tmp_fn(cnt, dest) + fn = tmp_fn(row, dest) with open(fn, "w") as f: log.DATA("exporting with format:", dest, " into filename:", fn) f.write( save_playlist(source="srv", multiply=True).export(urls, row, dest) ) return [fn] else: @@ -630,28 +635,24 @@ row = rows[0] return "[Desktop Entry]\nVersion=1.0\nIcon=media-playback-start\nType=Link\nName={title}\nComment={playing}\nURL={url}\n".format(**row) -# Generate filename for temporary .m3u, if possible with unique id -def tmp_fn(pls, ext="m3u"): - # use shoutcast unique stream id if available - stream_id = re.search("http://.+?/.*?(\d+)", pls, re.M) - stream_id = stream_id and stream_id.group(1) or "XXXXXX" - try: - channelname = main.current_channel - except: - channelname = "unknown" +# Generate filename for temporary .pls/m3u, with unique id +def tmp_fn(row, ext="pls"): + # use original url for generating a hash sum + stream_url_hash = abs(hash(str(row))) + try: channelname = main.current_channel + except: channelname = "unknown" # return temp filename - fn = "%s/streamtuner2.%s.%s.%s" % (str(conf.tmp), channelname, stream_id, ext) - is_unique = len(stream_id) > 3 and stream_id != "XXXXXX" + fn = "%s/%s.%s.%s" % (str(conf.tmp), channelname, stream_url_hash, ext) tmp_files.append(fn) - return fn, is_unique + return fn # Collect generated filenames tmp_files = [] # Callback from main / after gtk_main_quit def cleanup_tmp_files(): if not int(conf.reuse_m3u): [os.remove(fn) for fn in set(tmp_files)] Index: channels/dnd.py ================================================================== --- channels/dnd.py +++ channels/dnd.py @@ -186,11 +186,11 @@ # Text sources are assumed to understand the literal URL or expect a description block elif info >= 5: buf = 'text', "{url}\n# Title: {title}\n# Homepage: {homepage}\n\n".format(**r) # Create temporary PLS file, because "text/uri-list" is widely misunderstood and just implemented for file:// IRLs else: - tmpfn = "{}/{}.{}".format(conf.tmp, re.sub("[^\w-]+", " ", r["title"]), conf.dnd_format) + tmpfn = "{}/{}.{}".format(conf.tmp, re.sub("[^\w-]+", " ", r["title"]).strip(), conf.dnd_format) cnv.file(rows=[r], dest=conf.dnd_format, fn=tmpfn) buf = 'uris', ["file://{}".format(tmpfn)] if (info==4) else tmpfn # Keep in type request buffer self.buf[info] = buf Index: config.py ================================================================== --- config.py +++ config.py @@ -85,10 +85,14 @@ self.migrate() # store defaults in file else: self.save("settings") self.firstrun = 1 + + # temporary files + if not os.path.exists(self.tmp): + os.mkdir(self.tmp) # add argv self.args = self.init_args(argparse.ArgumentParser()) self.apply_args(self.args) @@ -113,11 +117,11 @@ "bookmarks": 1, "search": 1, "streamedit": 1, "configwin": 1, } - self.tmp = os.environ.get("TEMP", "/tmp") + self.tmp = os.environ.get("TEMP", "/tmp") + "/streamtuner2" self.max_streams = "500" self.show_bookmarks = 1 self.show_favicons = 1 self.load_favicon = 1 self.heuristic_bookmark_update = 0 @@ -238,10 +242,12 @@ def migrate(self): # 2.1.1 if "audio/mp3" in self.play: self.play["audio/mpeg"] = self.play["audio/mp3"] del self.play["audio/mp3"] + if self.tmp == "/tmp": + self.tmp = "/tmp/streamtuner2" # check for existing filename in directory list def find_in_dirs(self, dirs, file): for d in dirs: