Пример #1
0
def switch_filter():
    type = request.args['type']
    current = request.args['current']
    
    if current == 'accept':
        session['filters'].remove(type)
    else:
        session['filters'].append(type)
        
    common.reload_slot(['left-filter', '@center'])
    
    return beans.Null()
Пример #2
0
def feed_movie():
    """Creates folder with movie data."""    
    hlog = common.HydraLog(slot = `time.time()`, heading = "Analiza pliku")
    data = dict(MOVIE_DATA)

    #: adding new torrent
    if request.args.get('torrent_url'):
        torrent_data = torrent.get_torrent_data(request.args['torrent_url'])
        path = join(app.config['RTORRENT_DOWNLOADING_DIR'], 
                    torrent_data['info']['name'])                                      
        title, year = title_year_from_filename(torrent_data['info']['name'])        
        
        hlog.emit(u'Sparsowano tytuł filmu: "%s" na podstawie pliki' % title)        
        if year:
            hlog.emit(u'Wyciągnięto rok produkcji filmu:%s ' % year)      
    
    #: refreshing dat - getting info from ini_file    
    else:
        path = request.args['path']
        title = path.split('/')[-1]
        cfg = ConfigParser.RawConfigParser()        
        cfg.read(join(path, 'grabarz.ini'))
        ini_data = dict(cfg.items('data'))
        year = ini_data.get('year')
        title = ini_data.get('title')            
        hlog.emit(u'Rozpoczynam odświeżanie "%s" ' % title)
                                        
    #: Searching in IMDB database    
    hlog.emit(u'Szukam filmu w bazie IMDB...')    
    try:
        movies = imdb.search_movie(title)        
    except IndexError:
        hlog.emit(u'[ERROR] Nie rozpoznano filmu w bazie IMDB')
        return 'ERROR'            
    
    #: selecting best match
    if year:
        movies = [m for m in movies if `m.get('year')` == year]        
    matches = difflib.get_close_matches(title, [m.get('title') for m in movies])
    try:        
        movie = [m for m in movies if m.get('title') == matches[0]][0]
    except(KeyError):
        hlog.emit(u'[ERROR] Nie rozpoznano filmu w bazie IMDB')
        return 'ERROR'        
    
    #: getting full movie data from imdb
    imdb_id = movie.getID()
    imdb_data = imdb.get_movie(imdb_id)
    title = data['title'] = imdb_data['title']
    if not all([imdb_data.get('rating'), imdb_data.get('year'),
                imdb_data.get('runtime')]):
        hlog.emit(u'[ERROR] Nie można znaleść poprawnego filmu w bazie IMDB')
        return 'ERROR'        
    hlog.emit(u'Znaleziono film w bazie IMDB')
        
    #: feeding from IMDB    
    data['imdb_rating'] = imdb_data.get('rating')
    data['runtime'] =  ' '.join(imdb_data.get('runtime')[:1])
    data['year'] =  imdb_data.get('year')
    data['genres'] = ' '.join(imdb_data.get('genres'))
    data['date_added'] = '-'.join(str(date.today()).split('-')[::-1])
                
    #: Saving cover url    
    cover_url = imdb_data.get('cover url') or get_cover_from_google(title)      
    utils.download(cover_url, join(path, 'cover.jpg'))
                             
    #: Searching in Filmweb site
    hlog.emit(u'Szukam definicji w bazie Filmweb')
    br = mechanize.Browser()
    resp = br.open('http://www.filmweb.pl/search?q=%s' % title.replace(' ','+'))
    
    #: Dodge Welcome commercial  :)
    try:        
        resp = br.follow_link(text_regex=u"Przejd", nr=0)
    except(mechanize.LinkNotFoundError):
        resp = None
                
    #: Get first record from search results
    try:
        pred = lambda link:dict(link.attrs).get('class') == u'searchResultTitle'        
        resp = br.follow_link(predicate = pred)
    except(mechanize.LinkNotFoundError, KeyError):        
        resp = None        
    
    if resp:
        hlog.emit(u'Znaleziono film "%s" w bazie Filmweb' % title)
        d = pq(resp.read())
        data['filmweb_rating'] = d('.rating .average').text().replace(',', '.')
        data['description'] = d('.filmDescrBg').text()
        data['filmweb_url'] = br.geturl()
        data['polish_title'] = d('.fn').text()
        data['filmweb_opinions'] = '\n'.join(d('.fltTitle')
                                        .text().split('czytaj dalej'))
    else:
        app.logger.warning(u'Nie znaleziono filmu "%s" w bazie Filmweb' % title)    
        
    data['__space__'] = " " * 8
    hlog.emit(u"""
        =================================<br/>
        Podstawowe informację o filmie:<br/> 
        %(__space__)srating IMDB: %(imdb_rating)s<br/>
        %(__space__)sFilmweb: %(filmweb_rating)s<br/>
        %(__space__)sPolski tytuł: "%(polish_title)s"<br/>
        %(__space__)srok produkcji: %(year)s<br/>                       
    """% data) 
            
    if request.args.get('torrent_url'):
        #:-- new torrent succesfully recognizes ad film or tvshow --
        
        #: saving torrent file    
        utils.download(request.args.get('torrent_url'), 
                       join(app.config['RTORRENT_WATCH_DIR'], title+'.torrent'))
                
        #: making link to movies directory
        try:
            os.symlink(path, join(app.config['MOVIES_DL_DIR'], 
                                  split(path)[-1]))
        except(OSError): #file exists
            pass     
        hlog.close()
    else:
        common.reload_slot('@center', method = 'sql')
        
    #: Dumps data to ini file
    config = ConfigParser.RawConfigParser()
    config.add_section('data')
    for k, v in data.items():
        val = unicode(v).encode('utf-8')
        config.set('data', k, val)
                
    with open(join(path, 'grabarz.ini'), 'wb') as configfile:
        config.write(configfile)
        
    hlog.emit(u'Uaktualniono plik ini<br/><br/>KONIEC')            
    hlog.close()
    common.reload_slot(['left-menu', '@center'], method = 'sql')
    return 'OK'        
Пример #3
0
def calendar_refresh():
    """ Used to reload both the calendar content and slots at the same time."""
    save_year_month_day()
    common.reload_slot(['calendar-content', 'calendar-notes'])
    return beans.Null()