MCPcopy
hub / github.com/blacktwin/JBOPS / action_show

Function action_show

utility/media_manager.py:575–619  ·  view source on GitHub ↗
(items, selector, date, users=None)

Source from the content-addressed store, hash-verified

573
574
575def action_show(items, selector, date, users=None):
576 sizes = []
577
578 print("{} item(s) have been found.".format(len(items)))
579 if selector == 'lastPlayed':
580 print("The following items were last played before {}".format(date))
581 elif selector == 'watched':
582 print("The following items were watched by {}".format(", ".join([user.name for user in users])))
583 elif selector == 'unwatched':
584 print("The following items were added before {} and are unwatched".format(date))
585 elif selector == 'rating':
586 print("The following item(s) meet the criteria")
587 else:
588 print("The following items were added before {}".format(date))
589
590 for item in items:
591 try:
592 if selector == 'watched':
593 item = users[0].watch[item]
594 added_at = datetime.datetime.utcfromtimestamp(float(item.added_at)).strftime("%Y-%m-%d")
595 size = int(item.file_size) if item.file_size else 0
596 sizes.append(size)
597
598 if selector == 'lastPlayed':
599 last_played = datetime.datetime.utcfromtimestamp(float(item.last_played)).strftime("%Y-%m-%d")
600 print(u"\t{} added {} and last played {}\tSize: {}\n\t\tFile: {}".format(
601 item.title, added_at, last_played, sizeof_fmt(size), item.file))
602
603 elif selector == 'rating':
604 print(u"\t{} added {}\tSize: {}\tRating: {}\n\t\tFile: {}".format(
605 item.title, added_at, sizeof_fmt(size), item.audience_rating, item.file))
606
607 elif selector == 'transcoded':
608 print(u"\t{} added {}\tSize: {}\tTransocded: {} time(s)\n\t\tFile: {}".format(
609 item.title, added_at, sizeof_fmt(size), item.transcode_count, item.file))
610
611 else:
612 print(u"\t{} added {}\tSize: {}\n\t\tFile: {}".format(
613 item.title, added_at, sizeof_fmt(size), item.file))
614
615 except TypeError as e:
616 print("Item: {} caused the following error: {}".format(item.rating_key, e))
617
618 total_size = sum(sizes)
619 print("Total size: {}".format(sizeof_fmt(total_size)))
620
621if __name__ == '__main__':
622

Callers 1

media_manager.pyFile · 0.85

Calls 1

sizeof_fmtFunction · 0.70

Tested by

no test coverage detected