def select_date(self): # すべての日付 name = '[COLOR lightgreen]%s[/COLOR]' % Common.STR(30912) if self.args.get('ch') is None: mode = 'selectChannel' elif self.args.get('g0') is None: mode = 'selectGenre' else: mode = 'search' self.add_directory_item(name, '%s&sdate=&edate=' % self.query, mode, iconimage=Common.CALENDAR) # 月,火,水,木,金,土,日 w = Common.STR(30920).split(',') for i in range(120): d = datetime.date.today() - datetime.timedelta(i) wd = d.weekday() # 月日 # date1 = '%s(%s)' % (d.strftime(Common.STR(30919)), w[wd]) date1 = '%s(%s)' % (Common.strftime(d, Common.STR(30919)), w[wd]) date2 = d.strftime('%Y-%m-%d') if Common.isholiday(date2) or wd == 6: name = '[COLOR red]%s[/COLOR]' % date1 elif wd == 5: name = '[COLOR blue]%s[/COLOR]' % date1 else: name = date1 query = '%s&sdate=%s 00:00:00&edate=%s 23:59:59' % (self.query, date2, date2) if self.args.get('ch') is None: mode = 'selectChannel' elif self.args.get('g0') is None: mode = 'selectGenre' else: mode = 'search' self.add_directory_item(name, query, mode, iconimage=Common.CALENDAR) # end of directory xbmcplugin.endOfDirectory(int(sys.argv[1]))
def show_history(self, name): # ディレクトリ cache_dir = os.path.join(Common.CACHE_PATH, name) if not os.path.isdir(cache_dir): os.makedirs(cache_dir) # ファイルリスト count = 0 files = sorted(os.listdir(cache_dir), key=lambda message: os.stat( os.path.join(cache_dir, message)).st_mtime, reverse=True) for filename in files: path = os.path.join(cache_dir, filename) if os.path.isfile(path) and not filename.startswith('.'): if self.listsize == 0 or count < self.listsize: content = Common.read_file(path) # 日付文字列 d = datetime.datetime.fromtimestamp(os.stat(path).st_mtime) weekday = d.weekday() date1 = Common.strftime( d, Common.STR(32901) ) + '(%s)' % Common.STR(32902).split(',')[weekday] time1 = d.strftime('%H:%M:%S') if weekday == 6 or Common.isholiday( d.strftime('%Y-%m-%d')): template = '[COLOR red]%s %s[/COLOR]' elif weekday == 5: template = '[COLOR blue]%s %s[/COLOR]' else: template = '%s %s' fd = template % (date1, time1) # リストアイテム label = '%s %s' % (fd, content) listitem = xbmcgui.ListItem(label) listitem.setArt({ 'iconImage': 'DefaultFile.png', 'thumb': 'DefaultFile.png' }) values = {'action': 'message', 'name': name, 'path': path} query = '%s?%s' % (sys.argv[0], urlencode(values)) # コンテクストメニュー menu = [] # アドオン設定 menu.append((Common.STR(32900), 'Addon.OpenSettings(%s)' % Common.ADDON_ID)) # 追加 listitem.addContextMenuItems(menu, replaceItems=True) xbmcplugin.addDirectoryItem(int(sys.argv[1]), query, listitem, False) # カウントアップ count += 1 else: os.remove(path) # end of directory xbmcplugin.endOfDirectory(int(sys.argv[1]))
def show(self): # 曜日表記 w = Common.STR(32900).split(',') # 履歴表示 for h in reversed(self.data): # 履歴 date = h['date'] time = h['time'] wday = h['weekday'] uri = h['uri'] key = h['key'] name = h['name'] datetime = '%s(%s) %s' % (date, w[wday], time) # コンテクストメニュー menu = [] if re.compile('^0[0-9]{8,}').search(key): if PhoneBook().lookup(key): template2 = '[COLOR lightgreen]%s[/COLOR]' action = 'RunPlugin({url}?action=beginEditPhoneBookItem&{query})'.format( url=sys.argv[0], query=urlencode({ 'key': key, 'name': name })) menu.append((Common.STR(32904), action)) else: template2 = '[COLOR khaki]%s[/COLOR]' action = 'RunPlugin({url}?action=addPhoneBookItem&{query})'.format( url=sys.argv[0], query=urlencode({ 'key': key, 'name': name })) menu.append((Common.STR(32903), action)) else: key = '' template2 = '[COLOR orange]%s[/COLOR]' action = 'Container.Update(%s?action=showPhoneBook)' % ( sys.argv[0]) menu.append((Common.STR(32907), action)) action = 'RunPlugin(%s?action=settings)' % (sys.argv[0]) menu.append((Common.STR(32902), action)) # 書式 if Common.isholiday(date) or wday == 6: template1 = '[COLOR red]%s[/COLOR]' elif wday == 5: template1 = '[COLOR blue]%s[/COLOR]' else: template1 = '%s' template3 = '%s' template = '%s %s %s' % (template1, template3, template2) title = template % (datetime, key, name) li = xbmcgui.ListItem(title) li.setArt({ 'icon': Common.RINGER_VOLUME, 'thumb': Common.RINGER_VOLUME }) li.addContextMenuItems(menu, replaceItems=True) # 履歴 - 追加 url = '' xbmcplugin.addDirectoryItem(int(sys.argv[1]), url, listitem=li) # リストアイテム追加完了 xbmcplugin.endOfDirectory(int(sys.argv[1]))