Skip to content

Commit

Permalink
WIP #2 & #7 - Implement helpers:
Browse files Browse the repository at this point in the history
- Parser: caller method to easily get a date's UUIDs generator
- Filter: Generator methods to operate on parser's generator
  • Loading branch information
emibcn committed Nov 12, 2018
1 parent 424a413 commit 0ae9211
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions Rac1.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import unicodedata
import requests
import configargparse
import inspect


'''
Expand Down Expand Up @@ -316,6 +317,10 @@ def __init__(self, date):
self.date = date


def __call__(self):
return self.get_podcasts()


def get_rac1_page(self, page=0):
'''Download HTML with audio UUIDs'''

Expand Down Expand Up @@ -481,8 +486,30 @@ def __init__(self, args=args, parser=None):
self.args = args
self.parser = parser if parser is not None else Parser(date=self.args.date)

# Generator initial state
self._podcasts = self.get_autoreloaded_podcasts()


#
# Generator Implementation
#

def __next__(self):
return next(self._podcasts)

def next(self):
'''Py2 next() generator implementation'''
return self.__next__()

def __iter__(self):
return self

def filter_podcasts(self, podcasts):

#
# Methods
#

def get_filtered_podcasts(self):
'''Generator for filtered podcasts using args'''

is_first = True
Expand All @@ -491,7 +518,7 @@ def filter_podcasts(self, podcasts):
date = u'-'.join(self.args.date.split(u'/')[::-1])

# Process iterable generator and yield filtered podcasts
for podcast in podcasts:
for podcast in self.parser():

play = True

Expand Down Expand Up @@ -535,12 +562,6 @@ def filter_podcasts(self, podcasts):
break


def get_filtered_podcasts(self):
'''Returns filtered podcasts generator'''
return self.filter_podcasts(
self.parser.get_podcasts())


def get_autoreloaded_podcasts(self):
'''Generator for an autoreloaded list of podcasts'''

Expand Down Expand Up @@ -706,7 +727,6 @@ def signal_handler(self, sign, *_): # Unused frame argument
exit(3)



class MPlayerCommand(PlayerCommand):
'''Class to play Rac1 podcasts using MPlayer command'''

Expand Down Expand Up @@ -748,7 +768,7 @@ def main(argv=None, filter_class=Filter, parser_class=Parser, player_class=MPlay
# - Handling two possible expected Exceptions to exit cleanly
try:
# Iterate over autoreloaded podcasts generator
for podcast in rac1.get_autoreloaded_podcasts():
for podcast in rac1:

try:
# Play podcast or only print command or URL
Expand Down

0 comments on commit 0ae9211

Please sign in to comment.