adds basic format to build each playlist
This commit is contained in:
		| @ -10,6 +10,7 @@ channel = "newellijaytelevision" | ||||
| verbose = False | ||||
| from_date = datetime.date.today() | ||||
| to_date = datetime.date.today() | ||||
| playlist_duration = 6 * 60 * 60 # six hours, in seconds | ||||
|  | ||||
| def main(): | ||||
|     parse_config() | ||||
| @ -19,7 +20,7 @@ def main(): | ||||
|         build_day(single_date) | ||||
|  | ||||
| def parse_config(): | ||||
|     global mediadir, playlistdir, channel, verbose, from_date, to_date | ||||
|     global mediadir, playlistdir, channel, verbose, from_date, to_date, playlist_duration | ||||
|     parser = argparse.ArgumentParser( | ||||
|         prog="mt_clockwheel", | ||||
|         description="a simple clockwheel playlist generator for ffplayout", | ||||
| @ -32,6 +33,7 @@ def parse_config(): | ||||
|     parser.add_argument('-v', '--verbose', action='store_true', help='provide verbose output logging') | ||||
|     parser.add_argument('-f', '--from', dest='from_date', help='first date to generate playlist for') | ||||
|     parser.add_argument('-t', '--to', dest='to_date', help='last date to generate playlist for') | ||||
|     parser.add_argument('-l', '--length', dest='playlist_duration', help='duration (in seconds) for each playlist - if a factor of 24 * 60 * 60 then playlist will be duplicated to fill 24 hours') | ||||
|  | ||||
|     args = parser.parse_args() | ||||
|     if args.verbose: | ||||
| @ -46,6 +48,8 @@ def parse_config(): | ||||
|         from_date = datetime.datetime.strptime(args.from_date, "%Y-%m-%d").date() | ||||
|     if args.to_date: | ||||
|         to_date = datetime.datetime.strptime(args.to_date, "%Y-%m-%d").date() | ||||
|     if args.playlist_duration: | ||||
|         playlist_duration = args.playlist_duration | ||||
|  | ||||
|     if verbose: | ||||
|         print("Arguments parsed, config:") | ||||
| @ -56,8 +60,37 @@ def parse_config(): | ||||
|         print("to_date:", to_date) | ||||
|  | ||||
| def build_day(this_date): | ||||
|     # todo | ||||
|     pass | ||||
|     d = {} # empty dict that will become our JSON output | ||||
|  | ||||
|     d["channel"] = channel | ||||
|     d["date"] = this_date.strftime("%Y-%m-%d") | ||||
|     d["program"] = [] # empty list to populate with programs | ||||
|  | ||||
|     total_time = 0 | ||||
|  | ||||
|     while total_time < playlist_duration: | ||||
|         entry, length = get_playlist_entry() | ||||
|         d["program"].append(entry) | ||||
|         total_time += length | ||||
|         if verbose: | ||||
|             print('  added program:', json.dumps(entry), length) | ||||
|  | ||||
|     # TODO: see if playlist_duration is a factor of 24 * 60 * 60 and, if so, duplicate it to fill 24 hours | ||||
|  | ||||
|     if verbose: | ||||
|         print("playlist json:", json.dumps(d)) | ||||
|  | ||||
| def get_playlist_entry(): | ||||
|     entry = { | ||||
|         "in": 0, | ||||
|         "out": 300, | ||||
|         "duration": 300, | ||||
|         "source": "test.mp4" | ||||
|     } | ||||
|  | ||||
|     length = entry["duration"] | ||||
|  | ||||
|     return entry, length | ||||
|  | ||||
| # generator function to yield single dates from a date range | ||||
| def daterange(start_date, end_date): | ||||
|  | ||||
		Reference in New Issue
	
	Block a user