Viewing file: genres.py (8.18 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/python # coding=UTF-8 # # Copyright (C) 2008 Tim-Philipp Müller <tim.muller@collabora.co.uk> # Copyright (C) 2008 Canonical Ltd. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # The Totem project hereby grant permission for non-gpl compatible GStreamer # plugins to be used and distributed together with GStreamer and Totem. This # permission are above and beyond the permissions granted by the GPL license # Totem is covered by. # # See license_change file for details.
import gobject gobject.threads_init() import pygst pygst.require ("0.10") import gst
shortref_to_label_map = { "childrens": "Children's", "childrens/activities": "Activities", "childrens/drama": "Drama", "childrens/entertainmentandcomedy": "Entertainment & Comedy", "childrens/factual": "Factual", "childrens/music": "Music", "childrens/news": "News", "childrens/sport": "Sport", "drama": "Drama", "drama/actionandadventure": "Action & Adventure", "drama/biographical": "Biographical", "drama/classicandperiod": "Classic & Period", "drama/crime": "Crime", "drama/historical": "Historical", "drama/horrorandsupernatural": "Horror & Supernatural", "drama/legalandcourtroom": "Legal & Courtroom", "drama/medical": "Medical", "drama/musical": "Musical", "drama/political": "Political", "drama/psychological": "Psychological", "drama/relationshipsandromance": "Relationships & Romance", "drama/scifiandfantasy": "SciFi & Fantasy", "drama/soaps": "Soaps", "drama/spiritual": "Spiritual", "drama/thriller": "Thriller", "drama/waranddisaster": "War & Disaster", "drama/western": "Western", "entertainmentandcomedy": "Entertainment & Comedy", "entertainmentandcomedy/impressionists": "Impressionists", "entertainmentandcomedy/satire": "Satire", "entertainmentandcomedy/sitcoms": "Sitcoms", "entertainmentandcomedy/sketch": "Sketch", "entertainmentandcomedy/spoof": "Spoof", "entertainmentandcomedy/standup": "Standup", "entertainmentandcomedy/varietyshows": "Variety Shows", "factual": "Factual", "factual/antiques": "Antiques", "factual/artscultureandthemedia": "Arts, Culture & the Media", "factual/beautyandstyle": "Beauty & Style", "factual/carsandmotors": "Cars & Motors", "factual/cinema": "Cinema", "factual/consumer": "Consumer", "factual/crimeandjustice": "Crime & Justice", "factual/disability": "Disability", "factual/familiesandrelationships": "Families & Relationships", "factual/foodanddrink": "Food & Drink", "factual/healthandwellbeing": "Health & Wellbeing", "factual/history": "History", "factual/homesandgardens": "Homes & Gardens", "factual/lifestories": "Life Stories", "factual/money": "Money", "factual/petsandanimals": "Pets & Animals", "factual/politics": "Politics", "factual/sciencenatureandenvironment": "Science, Nature & Environment", "factual/travel": "Travel", "learning": "Learning", "learning/1119": "Age 11-19", "learning/511": "Age 5-11", "learning/adults": "Adults", "learning/preschool": "Pre-School", "music": "Music", "music/classicpopandrock": "Classic Pop & Rock", "music/classical": "Classical", "music/country": "Country", "music/danceandelectronica": "Dance & Electronica", "music/desi": "Desi", "music/easylisteningsoundtracksandmusicals": "Easy Listening, Soundtracks & Musicals", "music/folk": "Folk", "music/hiphoprnbanddancehall": "Hip Hop, RnB & Dancehall", "music/jazzandblues": "Jazz & Blues", "music/popandchart": "Pop & Chart", "music/rockandindie": "Rock & Indie", "music/soulandreggae": "Soul & Reggae", "music/world": "World", "news": "News", "religionandethics": "Religion & Ethics", "sport": "Sport", "sport/archery": "Archery", "sport/athletics": "Athletics", "sport/badminton": "Badminton", "sport/baseball": "Baseball", "sport/basketball": "Basketball", "sport/bowls": "Bowls", "sport/boxing": "Boxing", "sport/canoeing": "Canoeing", "sport/cricket": "Cricket", "sport/cycling": "Cycling", "sport/darts": "Darts", "sport/disabilitysport": "Disability Sport", "sport/diving": "Diving", "sport/equestrian": "Equestrian", "sport/fencing": "Fencing", "sport/football": "Football", "sport/gaelicgames": "Gaelic Games", "sport/golf": "Golf", "sport/gymnastics": "Gymnastics", "sport/handball": "Handball", "sport/hockey": "Hockey", "sport/horseracing": "Horse Racing", "sport/judo": "Judo", "sport/modernpentathlon": "Modern Pentathlon", "sport/motorsport": "Motorsport", "sport/olympics": "Olympics", "sport/rowing": "Rowing", "sport/rugbyleague": "Rugby League", "sport/rugbyunion": "Rugby Union", "sport/sailing": "Sailing", "sport/shinty": "Shinty", "sport/shooting": "Shooting", "sport/snooker": "Snooker", "sport/softball": "Softball", "sport/swimming": "Swimming", "sport/tabletennis": "Table Tennis", "sport/taekwondo": "Taekwondo", "sport/tennis": "Tennis", "sport/triathlon": "Triathlon", "sport/volleyball": "Volleyball", "sport/waterpolo": "Water Polo", "sport/weightlifting": "Weightlifting", "sport/wintersports": "Winter Sports", "sport/wrestling": "Wrestling", "weather": "Weather" }
# lowest = at the top shortref_to_sortrank_map = { "news": 1, "childrens": 2, "drama": 3, "entertainmentandcomedy": 4, "factual": 5, "learning": 6, "music": 7, "religionandethics": 8, "sport": 9, "weather": 10 }
''' GenrePool: keeps track of the already-created genres, mainly so we can easily find already-existing parents for to-be-created genres ''' class GenrePool(object): __slots__ = [ 'genres', 'toplevel_genres' ]
def __init__(self): self.clear()
def clear(self): self.genres = { } # maps short_ref => genre object
def get_genre(self, short_ref): # check if genre already exists if short_ref in self.genres: return self.genres[short_ref]
# if not, create genre (and any parents which don't exist yet) lastslash_pos = short_ref.rfind('/') if lastslash_pos > 0: parent_ref = short_ref[0:lastslash_pos] gst.log('genre: ' + short_ref + ', parent_genre: ' + parent_ref) parent = self.get_genre(parent_ref) else: parent = None
genre = Genre(short_ref, parent) self.genres[short_ref] = genre
return genre
def get_toplevel_genres(self): toplevel_genres = [] for genre in self.genres.values(): if not genre.parent: toplevel_genres.append(genre) return toplevel_genres
''' Genre: represents a genre ''' class Genre(object): __slots__ = [ 'short_ref', 'label', 'sort_rank', 'parent', 'children', 'brands' ]
def __init__(self, short_ref, parent_genre): self.short_ref = short_ref
if short_ref in shortref_to_label_map: self.label = shortref_to_label_map[short_ref] else: self.label = 'Unknown: ' + short_ref
if short_ref in shortref_to_sortrank_map: self.sort_rank = shortref_to_sortrank_map[short_ref] else: self.sort_rank = 99999
self.parent = parent_genre self.children = [] self.brands = []
if parent_genre is not None: parent_genre.add_child(self)
gst.log('created genre ' + short_ref + ' = ' + self.label)
def add_child(self, child_genre): if child_genre not in self.children: self.children.append(child_genre)
def add_brand(self, brand): if brand not in self.brands: self.brands.append(brand) gst.log(self.short_ref + ': adding show ' + brand.title)
if __name__ == "__main__": pass
|