Пример #1
0
 def load(self):        
     '''load songs and playlists from db file'''
     self.logdebug("Loading library...")
     
     # Load songs
     try:
         db_objs = utils.load_db(get_config_file("songs.db"))
     except:    
         self.logexception("Failed to load library")
         db_objs = []
         
     # Load playlists    
     try:    
         pls_objs = utils.load_db(get_config_file("playlists.db"))
     except:    
         self.logexception("Failed load playlists")
         pls_objs = []
         
         
     if db_objs:    
         for obj in db_objs:
             try:
                 song_type = obj["song_type"]
             except KeyError:    
                 self.logerror("Song with no type found, %s", obj.get("uri"))
                 
             if song_type not in self.__song_types:    
                 self.logwarn("Song type %s not exist, for registration", song_type)
                 self.register_type(song_type)
                 
             if self.__force_check:    
                 s = Song()
                 s.init_from_dict(obj)
                 s["uri"] = utils.realuri(s.get("uri"))
             else:    
                 s = Song(obj)
             s.set_type(song_type)    
             if not self.__force_check or not self.__songs.has_key(s.get("uri")):
                 self.add(s)
                 
     if pls_objs:            
         for pl_obj in pls_objs:            
             name, infos = pl_obj
             if self.__force_check:
                 infos = map(utils.realuri, infos)
             self.create_playlist("local", name, infos)    
     if self.__force_check:        
         self.save()
     self.__dirty = False    
     
     # fire signal
     self.__reset_queued_signal()
     gobject.timeout_add(AUTOSAVE_TIMEOUT, self.interval_async_save)
     gobject.timeout_add(SIGNAL_DB_QUERY_FIRED * 20, self.__fire_queued_signal)
     
     self.logdebug("%s songs loaded in %s types", len(self.__songs), len(self.__song_types))
     self.logdebug("Finish loading library")
     gobject.idle_add(self.__delay_post_load)
Пример #2
0
 def fresh_favotite_status(self):
     if os.path.exists(self.conf_db):
         data = utils.load_db(self.conf_db)
         if data.get('favorite'):
             for id in data['favorite']:
                 self.webview.execute_script("change_favorite_status(%s, 'ilike')" %
                     json.dumps(id, encoding="UTF-8", ensure_ascii=False))
Пример #3
0
    def show_recent_page(self):
        downloads_dir = os.path.join(CACHE_DIR, 'downloads')
        if os.path.exists(self.conf_db):
            data = utils.load_db(self.conf_db)
            if data.get('recent'):
                infos = []
                recent_list = data['recent']
                for id in recent_list:
                    try:
                        info_js_path = os.path.join(downloads_dir, str(id), 'info.json')
                        info = json.load(open(info_js_path))
                        info['index_pic_url'] = os.path.join(downloads_dir, str(id), info['index_pic_url'].split('/')[-1])
                        #info['swf_game'] = os.path.join(downloads_dir, str(id), info['swf_game'].split('/')[-1])
                        info['swf_game'] = urlparse.urlparse(info['swf_game']).path[1:]
                        info['type'] = 'recent'
                        infos.append(info)
                    except:
                        pass
                if infos:
                    self.webview.execute_script('var infos=%s' % 
                            json.dumps(infos, encoding="UTF-8", ensure_ascii=False))
                    self.webview.execute_script("gallery_change(%s)" %
                        json.dumps(self.gallery_html_path, encoding="UTF-8", ensure_ascii=False))
                    return

        self.webview.execute_script("gallery_change(%s)" %
                json.dumps(self.no_recent_html_path, encoding="UTF-8", ensure_ascii=False))
 def get_uid(self):
     try:
         self.uid = utils.load_db(self.cookie_db_file)[0]
         return self.uid
     except:
         print 'get uid failed'
         return None
    def load(self):
        try:
            objs = utils.load_db(self.listen_db_file)
            (current_playing_item,
                (playing_list_song, playing_list_songs),
                (personal_fm_song, personal_fm_songs)) = objs
            if current_playing_item == 'playing_list':
                self.current_playing_item = self.playing_list_item
                self.last_song = Song(playing_list_song)
            elif current_playing_item == 'personal_fm':
                self.current_playing_item = self.personal_fm_item
                self.last_song = Song(personal_fm_song)
            else:
                self.current_playing_item = None
                self.last_song = None
            self.playing_list_item.add_songs([Song(song) for song in
                playing_list_songs])
            if nplayer.is_login:
                self.personal_fm_item.add_songs([Song(song) for song in
                    personal_fm_songs])

        except:
            self.last_song = None
            utils.save_db(None, self.listen_db_file)
            return
Пример #6
0
def remove_recent_play(appid, conf_db):
    if os.path.exists(conf_db):
        data = utils.load_db(conf_db)
        recent_list = data.get('recent')
        if recent_list and appid in recent_list:
            data['recent'].remove(appid)
            utils.save_db(data, conf_db)
Пример #7
0
def remove_favorite(appid, conf_db):
    if os.path.exists(conf_db):
        data = utils.load_db(conf_db)
        favorite_list = data.get('favorite')
        if favorite_list and appid in favorite_list:
            data['favorite'].remove(appid)
            utils.save_db(data, conf_db)
Пример #8
0
 def get_uid(self):
     try:
         self.uid = utils.load_db(self.cookie_db_file)[0]
         return self.uid
     except:
         print 'get uid failed'
         return None
Пример #9
0
    def load(self):
        try:
            channel_infos = utils.load_db(self.preview_db_file)
        except:
            channel_infos = None

        if channel_infos is not None:
            self.add_channels(channel_infos)
Пример #10
0
 def load(self):    
     try:
         channel_infos = utils.load_db(self.preview_db_file)
     except:    
         channel_infos = None
         
     if channel_infos is not None:    
         self.add_channels(channel_infos)
Пример #11
0
 def remove(self, db=settings.SUBSCRIPTIONS_FILE):
     data = utils.load_db(db)
     if self.url in data['subscriptions']:
         data['subscriptions'].pop(self.url)
         utils.dump_db(db, data)
         logger.info('unsubscribed => %s' % self.url)
         print('unsubscribed => %s' % self.url)
     else:
         print('nothing has been removed.')
Пример #12
0
 def load(self):    
     objs = utils.load_db(self.db_file)
     songs = []
     if objs:
         for obj in objs:
             s = Song()
             s.init_from_dict(obj, cmp_key="sid")
             songs.append(s)
     if songs:        
         self.add_songs(songs)
 def load(self):
     objs = utils.load_db(self.listen_db_file)
     if objs:
         (self.last_song, songs,
                 self.playing_list_item.song_view.playback_mode) = objs
         if self.last_song:
             self.last_song = Song(self.last_song)
         self.playing_list_item.add_songs([Song(song) for song in songs])
     else:
         self.last_song = None
         self.playing_list_item.song_view.playback_mode = MusicView.LIST_REPEAT
    def load_status(self):
        obj = utils.load_db(self.status_db_file)
        if obj:
            index, d = obj
            song = Song()
            song.init_from_dict(d, cmp_key="sid")
        else:
            index = 0
            song = None

        self.playlist_index = index
        self.last_song = song
    def load_status(self):
        obj = utils.load_db(self.status_db_file)
        if obj:
            index, d = obj
            song = Song()
            song.init_from_dict(d, cmp_key="sid")
        else:
            index = 0
            song = None

        self.playlist_index = index
        self.last_song = song
Пример #16
0
 def load(self):    
     try:
         webcast_uris = utils.load_db(self.preview_db_file)
     except:    
         webcast_uris = None
         
     if webcast_uris:    
         webcasts = [ WebcastDB.get_song(uri) for uri in webcast_uris]
     else:    
         webcasts = None
         
     if webcasts:    
         self.add_webcasts(webcasts)
Пример #17
0
    def load(self):
        try:
            webcast_uris = utils.load_db(self.preview_db_file)
        except:
            webcast_uris = None

        if webcast_uris:
            webcasts = [WebcastDB.get_song(uri) for uri in webcast_uris]
        else:
            webcasts = None

        if webcasts:
            self.add_webcasts(webcasts)
    def load(self):    
        
        save_flag = False
        
        try:
            db_objs = utils.load_db(self.__user_save_db)
        except:    
            db_objs = None

            
        if db_objs is None:    
            save_flag = True
            self.logexception("Faild load user db, will to load default db")
            try:
                db_objs = utils.load_db(self.__default_db)
            except:    
                db_objs = []
                
        if db_objs:        
            for obj in db_objs:
                s = Song(obj)
                s.set_type(self.__type)
                if not self.__songs.has_key(s.get("uri")):
                    self.logdebug("load webcast %s" % s)
                    self.add(s)
                    
        if save_flag:            
            self.set_dirty()
            self.asyc_save()
            
        self.__dirty = False            

        # fire signal
        self.__reset_queued_signal()
        gobject.timeout_add(AUTOSAVE_TIMEOUT, self.asyc_save)
        gobject.timeout_add(SIGNAL_DB_QUERY_FIRED * 20, self.__fire_queued_signal)
        
        gobject.idle_add(self.__delay_post_load)
Пример #19
0
    def load(self):    
        
        save_flag = False
        
        try:
            db_objs = utils.load_db(self.__user_save_db)
        except:    
            db_objs = None

            
        if db_objs is None:    
            save_flag = True
            self.logexception("Faild load user db, will to load default db")
            try:
                db_objs = utils.load_db(self.__default_db)
            except:    
                db_objs = []
                
        if db_objs:        
            for obj in db_objs:
                s = Song(obj)
                s.set_type(self.__type)
                if not self.__songs.has_key(s.get("uri")):
                    # self.logdebug("load webcast %s" % s)
                    self.add(s)
                    
        if save_flag:            
            self.set_dirty()
            self.asyc_save()
            
        self.__dirty = False            

        # fire signal
        self.__reset_queued_signal()
        gobject.timeout_add(AUTOSAVE_TIMEOUT, self.asyc_save)
        gobject.timeout_add(SIGNAL_DB_QUERY_FIRED * 20, self.__fire_queued_signal)
        
        gobject.idle_add(self.__delay_post_load)
 def load(self):
     objs = utils.load_db(self.listen_db_file)
     if objs:
         items = []
         for title, bsongs in objs:
             item = MusicListItem(title, list_type=MusicListItem.LOCAL_TYPE)
             songs = []
             for d in bsongs:
                 s = Song()
                 s.init_from_dict(d, cmp_key="sid")
                 songs.append(s)
             item.add_songs(songs)
             items.append(item)
         self.category_list.add_items(items, insert_pos=1)
Пример #21
0
def record_favorite(appid, conf_db):
    if os.path.exists(conf_db):
        data = utils.load_db(conf_db)
        favorite_list = data.get('favorite')
        if favorite_list:
            if appid in favorite_list:
                data['favorite'].remove(appid)
            data['favorite'].insert(0, appid)
        else:
            data['favorite'] = [appid]
    else:
        data = dict(recent=[appid])

    utils.save_db(data, conf_db)
 def load(self):
     objs = utils.load_db(self.listen_db_file)
     if objs:
         items = []
         for title, bsongs in objs:
             item = MusicListItem(title, list_type=MusicListItem.LOCAL_TYPE)
             songs = []
             for d in bsongs:
                 s = Song()
                 s.init_from_dict(d, cmp_key="sid")
                 songs.append(s)
             item.add_songs(songs)
             items.append(item)
         self.category_list.add_items(items, insert_pos=1)
    def load_collect_data(self):
        try:
            collected_objs = utils.load_db(self.collected_db_file)
        except:
            collected_objs = None

        if collected_objs:
            songs = [WebcastDB.get_song(uri) for uri in collected_objs]
        else:
            songs = None

        if songs:
            songs = [song for song in songs if song.get("collected", False)]
            if songs:
                self.collected_view.add_webcasts(songs)
    def load_collect_data(self):        
        try:
            collected_objs = utils.load_db(self.collected_db_file)
        except:    
            collected_objs = None

        if collected_objs:    
            songs = [ WebcastDB.get_song(uri) for uri in collected_objs]
        else:    
            songs = None
            
        if songs:
            songs = [ song for song in songs if song.get("collected", False)]            
            if songs:
                self.collected_view.add_webcasts(songs)
Пример #25
0
def record_recent_play(appid, conf_db):
    if os.path.exists(conf_db):
        data = utils.load_db(conf_db)
        recent_list = data.get('recent')
        if recent_list:
            if appid in recent_list:
                data['recent'].remove(appid)
            data['recent'].insert(0, appid)
        else:
            data['recent'] = [appid]
    else:
        data = dict(recent=[appid])

    utils.save_db(data, conf_db)
    utils.ThreadMethod(utils.send_analytics, ('play', appid)).start()
Пример #26
0
    def create_toolbar(self, widget_display=[]):
        control_toolbar = ControlToolbar(self.appid, widget_display)
        control_toolbar.mute_button.connect('clicked', self.mute_handler)
        control_toolbar.pause_button.connect('button-press-event', self.pause_handler)
        control_toolbar.replay_button.connect('clicked', self.replay_action)
        control_toolbar.fullscreen_button.connect('button-release-event', self.fullscreen_handler)
        control_toolbar.share_button.connect('clicked', self.share_action)
        control_toolbar.favorite_button.connect('button-release-event', self.favorite_action)
        control_toolbar.leave_callback = self.leave_callback
        
        if os.path.exists(self.conf_db):
            data = utils.load_db(self.conf_db)
            if data.get('favorite') and self.appid in data['favorite']:
                control_toolbar.favorite_button.set_active(True)

        return control_toolbar
Пример #27
0
    def create_toolbar(self, widget_display=[]):
        control_toolbar = ControlToolbar(self.appid, widget_display)
        control_toolbar.mute_button.connect('clicked', self.mute_handler)
        control_toolbar.pause_button.connect('button-press-event',
                                             self.pause_handler)
        control_toolbar.replay_button.connect('clicked', self.replay_action)
        control_toolbar.fullscreen_button.connect('button-release-event',
                                                  self.fullscreen_handler)
        control_toolbar.share_button.connect('clicked', self.share_action)
        control_toolbar.favorite_button.connect('button-release-event',
                                                self.favorite_action)
        control_toolbar.leave_callback = self.leave_callback

        if os.path.exists(self.conf_db):
            data = utils.load_db(self.conf_db)
            if data.get('favorite') and self.appid in data['favorite']:
                control_toolbar.favorite_button.set_active(True)

        return control_toolbar
Пример #28
0
 def initialize(self, db=settings.SUBSCRIPTIONS_FILE, ut=False):
     try:
         data = utils.load_db(db)
         if self.url not in data['subscriptions']:
             self.content = self.get(self.url, ut)
             if self.content:
                 self.created_at = datetime.datetime.now()
                 data['subscriptions'][self.url] = {
                     'created_at': str(self.created_at),
                     'updated_at': None,
                     'content': self.content,
                 }
                 utils.dump_db(db, data)
                 logger.info('subscribed => %s' % self.url)
                 print('a new face\'s in => %s' % self.url)
         else:
             print('subscribed. checking for updates...')
             self.update()
     except Exception as e:
         logging.exception(e)
Пример #29
0
 def update(self, db=settings.SUBSCRIPTIONS_FILE, ut=False):
     try:
         data = utils.load_db(db)
         if self.url in data['subscriptions']:
             content_new = self.get(self.url, ut)
             if content_new:
                 if content_new != data['subscriptions'][
                         self.url]['content']:
                     self.content = content_new
                     self.updated_at = datetime.datetime.now()
                     data['subscriptions'][self.url]['updated_at'] = str(
                         self.updated_at)
                     data['subscriptions'][
                         self.url]['content'] = self.content
                     utils.dump_db(db, data)
                     logger.info('renewed => %s' % self.url)
                     print('CHANGES! => %s' % self.url)
                 else:
                     print('nothing changed => %s' % self.url)
         else:
             print('a new face. new it if required.')
     except Exception as e:
         logging.exception(e)
 def load_cookie(self):
     try:
         return utils.load_db(self.cookie_db_file)
     except:
         print 'load cookie failed'
         return None
Пример #31
0
 def load(self):    
     objs = utils.load_db(self._db)
     if objs:
         self._data = objs
 def load_cookie(self):
     try:
         return utils.load_db(self.cookie_db_file)
     except:
         return None
 def load(self):
     songs = utils.load_db(self.listen_db_file)
     if songs:
         self.playing_list_item.add_songs([Song(song) for song in songs])
 def load(self):
     obj = utils.load_db(self.config_db)
     if obj:
         for key, value, in obj.items():
             setattr(self, key, value)
Пример #35
0
 def load_status(self):        
     self.channel_info = utils.load_db(self.status_db_file)
 def load_cookie(self):
     try:
         return utils.load_db(self.cookie_db_file)
     except:
         return None
Пример #37
0
 def load(self):
     songs = utils.load_db(self.listen_db_file)
     if songs:
         self.playing_list_item.add_songs([Song(song) for song in songs])
Пример #38
0
 def load_all_data(self):
     objs = utils.load_db(self._db)
     if objs:
         self._all_data = objs
     self._total_page = self.get_total_page()
     self.reload_data()
Пример #39
0
 def loadDB(self):
     self.toxic_db, self.msms_db = utils.load_db()
Пример #40
0
 def load(self):
     # Load the db file.
     try:
         self.dict_objs = load_db(self.PINYIN_DICT_FILE)
     except:
         self.dict_objs = {}
Пример #41
0
 def load(self):    
     objs = utils.load_db(self._db)
     if objs:
         self._data = objs
Пример #42
0
 def load_status(self):
     self.channel_info = utils.load_db(self.status_db_file)
Пример #43
0
    def load(self):
        '''load songs and playlists from db file'''
        self.logdebug("Loading library...")

        # Load songs
        try:
            db_objs = utils.load_db(get_config_file("songs.db"))
        except:
            self.logexception("Failed to load library")
            db_objs = []

        # Load playlists
        try:
            pls_objs = utils.load_db(get_config_file("playlists.db"))
        except:
            self.logexception("Failed load playlists")
            pls_objs = []

        if db_objs:
            for obj in db_objs:
                try:
                    song_type = obj["song_type"]
                except KeyError:
                    self.logerror("Song with no type found, %s",
                                  obj.get("uri"))

                if song_type not in self.__song_types:
                    self.logwarn("Song type %s not exist, for registration",
                                 song_type)
                    self.register_type(song_type)

                if self.__force_check:
                    s = Song()
                    s.init_from_dict(obj)
                    s["uri"] = utils.realuri(s.get("uri"))
                else:
                    s = Song(obj)
                s.set_type(song_type)
                if not self.__force_check or not self.__songs.has_key(
                        s.get("uri")):
                    self.add(s)

        if pls_objs:
            for pl_obj in pls_objs:
                name, infos = pl_obj
                if self.__force_check:
                    infos = map(utils.realuri, infos)
                self.create_playlist("local", name, infos)
        if self.__force_check:
            self.save()
        self.__dirty = False

        # fire signal
        self.__reset_queued_signal()
        gobject.timeout_add(AUTOSAVE_TIMEOUT, self.interval_async_save)
        gobject.timeout_add(SIGNAL_DB_QUERY_FIRED * 20,
                            self.__fire_queued_signal)

        self.logdebug("%s songs loaded in %s types", len(self.__songs),
                      len(self.__song_types))
        self.logdebug("Finish loading library")
        gobject.idle_add(self.__delay_post_load)
Пример #44
0
 def load_all_data(self):
     objs = utils.load_db(self._db)
     if objs:
         self._all_data = objs
     self._total_page = self.get_total_page()
     self.reload_data()
Пример #45
0
 def load(self):
     # Load the db file.
     try:
         self.dict_objs = load_db(self.PINYIN_DICT_FILE)
     except:
         self.dict_objs = {}
 def load_cookie(self):
     try:
         return utils.load_db(self.cookie_db_file)
     except:
         print 'load cookie failed'
         return None
Пример #47
0
def setup(url, func_name):
    utils.sketch_meta('subscriptions', settings.SUBSCRIPTIONS_FILE_FOR_TEST)
    if func_name == 'update':
        setup_funcs('https://en.wikipedia.org/', 'initialize')
    setup_funcs(url, func_name)
    return utils.load_db('subscriptions.json')
 def load(self):
     obj = utils.load_db(self.config_db)
     if obj:
         for key, value, in obj.items():
             setattr(self, key, value)