def _import_sputnikmusic(): for res in Sputnikmusic().reviews(): if not res.get('artist') or not res.get('album') or not res.get('rating'): continue if not res.get('date') or res['date'] < datetime.utcnow() - DELTA_RELEASE: continue name = '%s - %s' % (res['artist'], res['album']) if not Release.find_one({ 'artist': res['artist'], 'album': res['album'], 'type': 'audio', 'info.subtype': 'music', }): Release.insert({ 'name': name, 'artist': res['artist'], 'album': res['album'], 'type': 'audio', 'src': {'web': 'sputnikmusic'}, 'info': {'subtype': 'music'}, 'date': res['date'], # datetime 'created': datetime.utcnow(), 'processed': False, }, safe=True) logger.info('added music release "%s"', name)
def _get_object_search(id, type): obj = None search = None if type == 'media': obj = Media.get(id) if obj: search = Media.get_search(obj) elif type == 'release': obj = Release.get(id) if obj: search = Release.get_search(obj) elif type == 'search': obj = Search.get(id) if obj: search = { 'name': obj['name'], 'category': obj['category'], 'search_id': id, } if obj.get('album'): search['album'] = obj['album'] if obj and search: search['extra'] = obj.get('extra', {}) return search
def run(): if Google().accessible: factory = get_factory() for type in ('imdb', 'metacritic', 'rottentomatoes', 'vcdquality', 'tvrage', 'sputnikmusic'): target = '%s.workers.release.import_releases' % settings.PACKAGE_NAME factory.add(target=target, args=(type,), timeout=TIMEOUT_IMPORT) Release.remove({'date': {'$lt': datetime.utcnow() - DELTA_RELEASE}}, safe=True)
def list_media(type, skip, limit): cache = {} spec = {} category = request.args.get('category') if category: if type in ('search', 'similar'): spec['category'] = category else: spec['info.subtype'] = category query = request.args.get('query') if query: spec.update(_get_search_spec(query)) sort = request.args.get('sort', 'date') if sort == 'name': sort = [('name', ASCENDING)] elif sort == 'rating': sort = [('rating', DESCENDING)] else: sort = [('date', DESCENDING), ('created', DESCENDING)] params = {'sort': sort, 'skip': skip, 'limit': limit} items = [] if type == 'media': for res in Media.find(spec, **params): search = Media.get_search(res) items.append(_get_object(res, type=type, has_search=_has_search(cache, search), has_similar=_has_similar(cache, search))) elif type == 'release': for res in Release.find(spec, **params): search = Release.get_search(res) items.append(_get_object(res, type=type, has_search=_has_search(cache, search), has_similar=_has_similar(cache, search))) elif type == 'search': for res in Search.find(spec, **params): items.append(_get_object(res, type=type, has_search=True, has_similar=_has_similar(cache, res))) elif type == 'similar': for res in SimilarSearch.find(spec, **params): items.append(_get_object(res, type=type, has_similar=True)) return serialize({'result': items})
def _import_rottentomatoes(): for res in Rottentomatoes().releases('dvd_new'): name = res['title'] if not Release.find_one({ 'name': name, 'type': 'video', 'info.subtype': 'movies', }): Release.insert({ 'name': name, 'type': 'video', 'src': {'web': 'rottentomatoes'}, 'info': {'subtype': 'movies'}, 'url': res['url'], 'date': datetime.utcnow(), 'created': datetime.utcnow(), 'processed': False, }, safe=True) logger.info('added movies release "%s"', name)
def _import_vcdquality(): for res in Vcdquality().releases(pages_max=VCDQUALITY_PAGES_MAX): if res['date'] < datetime.utcnow() - DELTA_RELEASE: continue name = clean(res['release'], 7) if not Release.find_one({ 'name': name, 'type': 'video', 'info.subtype': 'movies', }): Release.insert({ 'name': name, 'type': 'video', 'src': {'web': 'vcdquality'}, 'info': {'subtype': 'movies'}, 'release': res['release'], 'date': res['date'], 'created': datetime.utcnow(), 'processed': False, }, safe=True) logger.info('added movies release "%s"', name)
def _import_metacritic(): for res in Metacritic().releases('movies_dvd'): if res['date'] < datetime.utcnow() - DELTA_RELEASE: continue name = res['title'] if not Release.find_one({ 'name': name, 'type': 'video', 'info.subtype': 'movies', }): Release.insert({ 'name': name, 'type': 'video', 'src': {'web': 'metacritic'}, 'info': {'subtype': 'movies'}, 'url': res['url'], 'date': res['date'], 'created': datetime.utcnow(), 'processed': False, }, safe=True) logger.info('added movies release "%s"', name)
def process_releases(): media_langs = Settings.get_settings('media_langs') for release in Release.find({ 'processed': False, 'valid': {'$exists': True}, }): valid = release['valid'] subtype = release['info'].get('subtype') if not valid and subtype == 'music' \ and _media_exists(name=release['artist'], category='music'): valid = True if valid is None: continue if valid: search = Release.get_search(release) search['langs'] = media_langs.get(subtype, []) add_search(**search) Release.update({'_id': release['_id']}, {'$set': {'processed': datetime.utcnow()}}, safe=True)
def _import_tvrage(): for res in Tvrage().scheduled_shows(): if not res.get('url') or not res.get('season') or not res.get('episode'): continue if res['season'] > 1 or res['episode'] > TV_EPISODE_MAX: continue name = clean(res['title'], 7) if not Release.find_one({ 'name': name, 'type': 'video', 'info.subtype': 'tv', }): Release.insert({ 'name': name, 'type': 'video', 'src': {'web': 'tvrage'}, 'info': {'subtype': 'tv'}, 'url': res['url'], 'date': datetime.utcnow(), # release date is the date we discovered the show 'created': datetime.utcnow(), 'processed': False, }, safe=True) logger.info('added tv release "%s"', name)