Check-in [7a1577bf74]
Overview
Comment: | Collect audio format form URL guessing into new class heuristic_funcs |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
7a1577bf74f0745148cba02ad1cd469d |
User & Date: | mario on 2017-02-26 21:44:13 |
Other Links: | manifest | tags |
Context
2017-02-26
| ||
21:45 | Reuse mime_guess+list_guess functions from action.heuristic_funcs check-in: c5e06b031a user: mario tags: trunk | |
21:44 | Collect audio format form URL guessing into new class heuristic_funcs check-in: 7a1577bf74 user: mario tags: trunk | |
21:43 | Enable search with post/json=1 and seperating token from other params{} check-in: 85f1271d4d user: mario tags: trunk | |
Changes
Modified action.py from [1923204c8e] to [77e25ddc1d].
1 2 3 4 5 6 | # encoding: UTF-8 # api: streamtuner2 # type: functions # category: io # title: play/record actions # description: Starts audio applications, guesses MIME types for URLs | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # encoding: UTF-8 # api: streamtuner2 # type: functions # category: io # title: play/record actions # description: Starts audio applications, guesses MIME types for URLs # version: 1.3 # priority: core # # Multimedia interface for starting audio players, recording app, # or web browser (listed as "url/http" association in players). # It maps audio MIME types, and extracts/converts playlist types # (PLS, M3U, XSPF, SMIL, JSPF, ASX, raw urls). # # Each channel plugin has a .listformat which defines the linked # audio playlist format. It's "pls", seldomly "m3u", or "xspf". # Some channels list raw "srv" addresses, while Youtube "href" # entries point to Flash videos. # # As fallback the playlist URL is retrieved and its MIME type # checked, then its content regexped to guess the list format. # Lastly a playlist format suitable for audio players recreated. |
︙ | ︙ | |||
369 370 371 372 373 374 375 376 377 378 379 | return (mime, url) # Rejoin into string content = "\n".join(str.decode(errors='replace') for str in r.iter_lines()) return (mime, content) # Extract URLs and meta infos (titles) from playlist formats # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # It's mostly regex-based at the moment, because that's more | > > > > > > > > > > > > > > > > > > > > > > > > > | | | 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | return (mime, url) # Rejoin into string content = "\n".join(str.decode(errors='replace') for str in r.iter_lines()) return (mime, content) # A few guessing functions # class heuristic_funcs(object): # Probe url "extensions" for common media types # (only care about the common audio formats, don't need an exact match or pre-probing in practice) def mime_guess(self, url, default="x-audio-video/unknown"): audio = re.findall("\\b(ogg|opus|spx|aacp|aac|mpeg|mp3|m4a|mp2|flac|midi|mod|kar|aiff|wma|ram|wav)", url) if audio: return "audio/{}".format(*audio) video = re.findall("\\b(mp4|flv|avi|mp2|theora|3gp|nsv|fli|ogv|webm|mng|mxu|wmv|mpv|mkv)", url) if audio: return "video/{}".format(*audio) return default # guess PLS/M3U from url def list_guess(self, url): ext = re.findall("|".join(playlist_fmt_prio), url) if ext: return ext[0] else: return "srv" # Extract URLs and meta infos (titles) from playlist formats # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # It's mostly regex-based at the moment, because that's more # resilient against malformed XSPF or JSON. But specialized # import helpers can be added as needed. # class extract_playlist(heuristic_funcs): # Content of playlist file src = "" fn = "" def __init__(self, text=None, fn=None): # Literal playlist source content if text: |
︙ | ︙ | |||
602 603 604 605 606 607 608 | "listformat": self.probe_ext(url) or "href", # or srv? "format": self.mime_guess(url), "genre": "copy", } comb.update(row) return comb | < < < < < < < < < < < < | 627 628 629 630 631 632 633 634 635 636 637 638 639 640 | "listformat": self.probe_ext(url) or "href", # or srv? "format": self.mime_guess(url), "genre": "copy", } comb.update(row) return comb # Save rows[] in one of the export formats # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # → The export() version uses urls[] and a template row{} as input, # converts it into a list of complete rows{} beforehand. It's mostly # utilized to expand a source playlist, merge in alternative streaming |
︙ | ︙ |