ADDED channels/filter_bitrate.py Index: channels/filter_bitrate.py ================================================================== --- channels/filter_bitrate.py +++ channels/filter_bitrate.py @@ -0,0 +1,47 @@ +# encoding: UTF-8 +# api: streamtuner2 +# title: Filter Bitrate +# description: Cleans up low-quality entries from all station lists. +# version: 0.1 +# type: filter +# category: audio +# priority: optional +# config: +# { name: min_bitrate_mp3, value: 32, type: select, select: "32|48|64|80|96|112|128|144|160", description: Filter MP3 streams with lesser audio quality. } +# [ name: min_bitrate_ogg, value: 32, type: select, select: "32|48|64|80|96|112|128|144|160", description: OggVorbis/AAC sound ok with slightly lower bitrates still. ] +# hooks: - +# +# Plugin that filters radio stations on bitrate (audio quality). +# Anything below 64 kbit/s often sounds awful for MP3 streams. +# While AAC or Ogg Vorbis might still be acceptable sometimes. +# +# This functionality was previously just implemented for the Xiph +# plugin. It's now available as generic filter for all channels. +# Beware that some channels provide more entries with low bitrates, +# thus might appear completely empty. + + +from config import * +import channels + + +# Filter streams by bitrate +class filter_bitrate(): + + meta = plugin_meta() + module = "filter_bitrate" + + # Hijack GenericChannel.prepare + def __init__(self, parent): + channels.GenericChannel.postprocess_filters.append(self.filter_rows) + + # filter bitrate + def filter_rows(self, row): + b = int(row.get("bitrate", 0)) + if b <= 10: + return True + elif b < int(conf.min_bitrate_mp3): + return False + else: + return True + Index: channels/xiph.py ================================================================== --- channels/xiph.py +++ channels/xiph.py @@ -5,11 +5,10 @@ # type: channel # url: http://dir.xiph.org/ # version: 0.5 # category: radio # config: -# { name: xiph_min_bitrate, value: 64, type: int, description: "Minimum bitrate; filter lesser quality streams.", category: filter } # { name: xiph_source, value: web, type: select, select: "cache=JSON cache srv|xml=Clunky XML blob|web=Forbidden fruits", description: "Source for station list extraction." } # priority: standard # png: # iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAg5JREFUOI2lk1tIE2AUx3+7CG1tlmlG1rSEHrKgEUF7yO40taQiRj10I4qKkOaT4hIUItuTkC8hpJAQtJCICrFpzEKw # h61eQorGNBOTzbEt16ZrnR5Wq3mZD/3heziX//983znngyyov+eSbHEA5WKBhs4BKVy9gsqajqwiCwo0dA5IQX5u2s4moliMPPV1nCeDzxgNBFDHE2wsKMPzsGVefobjcnO7RMfeMuL341ZBrNEGRmPqqjdvsbbf @@ -35,13 +34,12 @@ # # → "Forbidden Fruits" extracts from dir.xiph.org HTML pages, # with homepages and listener/max infos available. Also # enables live server searching. # -# The bitrate filter can strip any low-quality entries, but -# retains `0` entries (which just lack meta information and -# aren't necessarily low-bitrate.) +# The previous bitrate filter is now a separate plugin, but +# available for all channels. from config import * from uikit import uikit import ahttp @@ -87,14 +85,10 @@ log.PROC("Xiph mode: xml.dom.minidom to traverse yp.xml") r = self.from_yp_xml(cat, search) else: log.PROC("Xiph mode: extract from dir.xiph.org HTML listings") r = self.from_raw_html(cat, search) - - # filter bitrate - if conf.xiph_min_bitrate: - r = [row for row in r if row.get("bitrate", 0) <= 10 or row.get("bitrate", 0) >= int(conf.xiph_min_bitrate)] return r