4 import rtv_programmeinfo
, rtv_utils
, rtv_favourite
7 "^(\\S*)-(\\d{4}-\\d{2}-\\d{2}_\\d{2}_\\d{2})-(\S*)$" )
9 FILENAME_DATETIME_FORMAT
= "%Y-%m-%d_%H_%M"
11 class Selection( object ):
17 self
.deleteAfterDays
= None
20 def load( self
, filename
):
21 m
= fn_re
.match( filename
)
23 print( "Selection not recognised - filename '%s'" % filename
24 + "is not of the recognised format." )
26 self
.title
= m
.group( 1 )
27 self
.channel
= m
.group( 3 )
28 self
.startTime
= rtv_utils
.parse_datetime( m
.group( 2 ),
29 FILENAME_DATETIME_FORMAT
)
31 def matches( self
, pi
):
33 return ( self
.title
== rtv_utils
.prepare_filename( pi
.title
) and
34 self
.channel
== pi
.channel
and
35 self
.startTime
== pi
.startTime
)
39 def read_favs_and_selections( config
, record_only
= False ):
42 rtv_utils
.ensure_dir_exists( config
.favourites_dir
)
44 for fn
in os
.listdir( config
.favourites_dir
):
46 if fn
[-7:] == ".rtvfav":
47 full_fn
= os
.path
.join( config
.favourites_dir
, fn
)
49 fav
= rtv_favourite
.Favourite()
52 if ( not record_only
) or ( fav
.record
== "yes" ):
55 rtv_utils
.ensure_dir_exists( config
.selections_dir
)
57 for fn
in os
.listdir( config
.selections_dir
):
59 if fn
[-7:] == ".rtvsel":
60 # Note: no need for full path, as the filename itself
61 # contains all the information we need, so we don't need
62 # to read the file at all.