Esempio n. 1
0
  def at(start, duration_string='1hr'):
    """
    Sends a stream using a human-readable (and human-writable) definition 
    at start time.  This uses the dateutils.parser library and so strings 
    such as "Monday 2pm" are accepted.

    Because the space, 0x20 is such a pain in HTTP, you can use "_", 
    "-" or "+" to signify it.  For instance,

        /at/monday_2pm/1hr

    Will work fine
    """
    dt = TS.str_to_time(start)
    duration_min = TS.duration_parse(duration_string)
    endpoint = '%s-%s_%d.mp3' % (misc.config['callsign'], TS.ts_to_name(dt), duration_min)
    return send_stream(endpoint, download_name=endpoint)
Esempio n. 2
0
File: server.py Progetto: EQ4/DRR
    def at(start, duration_string='1hr'):
        """
    Sends a stream using a human-readable (and human-writable) definition 
    at start time.  This uses the dateutils.parser library and so strings 
    such as "Monday 2pm" are accepted.

    Because the space, 0x20 is such a pain in HTTP, you can use "_", 
    "-" or "+" to signify it.  For instance,

        /at/monday_2pm/1hr

    Will work fine
    """
        dt = TS.str_to_time(start)
        duration_min = TS.duration_parse(duration_string)
        endpoint = '%s-%s_%d.mp3' % (misc.config['callsign'],
                                     TS.ts_to_name(dt), duration_min)
        return send_stream(endpoint, download_name=endpoint)
Esempio n. 3
0
#!/usr/bin/python -O
import json
import lib.ts as TS

all_data = raw_input()

res = []
for data in all_data.split('_'):
    parts = data.strip().split(' ')
    res.append((TS.to_utc(parts[0], parts[1]), TS.duration_parse(parts[2])))

print json.dumps(res)
Esempio n. 4
0
    def stream(weekday, start, duration_string, showname):
        """
    Returns a podcast, m3u, pls or mp3 file based on the weekday, start and duration.
    This is designed to be read by podcasting software such as podkicker, 
    itunes, and feedburner.

    weekdays are defined as mon, tue, wed, thu, fri, sat, sun.

    If a show occurs multiple times per week, this can be specified with
    a comma.  for instance,

    /mon,tue,fri/4pm/1hr
    
    The showname should be followed by an xml, pls, m3u, or mp3 extension.
    In the case of using the .mp3 extension, it only returns the most recent 
    episode.

    It should also be viewable in a modern web browser.

    If you can find a podcaster that's not supported, please send an email 
    to [email protected].
    """

        if isinstance(weekday, (float)):
            start_time_list = [weekday]
            weekday_list = [TS.WEEKDAY_LIST[int(weekday / (60 * 24))]]

        else:
            # Supports multiple weekdays
            weekday_list = weekday.split(',')
            start_time_list = [TS.to_utc(day, start) for day in weekday_list]

        duration_min = TS.duration_parse(duration_string)

        # This means we failed to parse
        if not duration_min:
            return do_error("duration '%s' is not set correctly" %
                            duration_string)

        if not isinstance(start_time_list[0], (int, float)):
            return do_error('weekday and start times are not set correctly')

        buffer_show = 2
        # In #22 We're going to add 2 minutes to the duration to make sure that we get
        # the entire episode.
        duration_min += (buffer_show * 2)

        # And according to #149 we also go a minute back for the start time ...
        # we need to do a little math to make sure we don't get a -1 edge case
        start_time_list = [
            (TS.MINUTES_PER_WEEK + offset - buffer_show) % TS.MINUTES_PER_WEEK
            for offset in start_time_list
        ]

        # If we are here then it looks like our input is probably good.

        # Strip the .xml from the showname ... this will be used in our xml.
        file_type = showname[-3:]
        showname = showname[:-4]

        # We come in with spaces as underscores so here we translate that back
        showname = re.sub('_', ' ', showname)

        # Make sure that we have all of our streams registered before trying
        # to infer what we can send to the user.
        cloud.register_stream_list()

        # Look for streams that we have which match this query and duration.
        # This will also create slices if necessary in a sub process.
        # The list of files that returns will include this not-yet-created
        # file-name as essentially a "promise" to when it will be made.
        feed_list = cloud.find_and_make_slices(start_time_list, duration_min)
        # print feed_list

        # Then, taking those two things, make a feed list from them.
        return generate_feed(file_type=file_type,
                             showname=showname,
                             feed_list=feed_list,
                             duration_min=duration_min,
                             weekday_list=weekday_list,
                             start=start,
                             duration_string=duration_string)
Esempio n. 5
0
  def stream(weekday, start, duration_string, showname):
    """
    Returns a podcast, m3u, pls, html or mp3 file based on the weekday, 
    start and duration.  This is designed to be read by podcasting 
    software such as podkicker, itunes, and feedburner.

    The default format if nothing is specified is XML.

    weekdays are defined as mon, tue, wed, thu, fri, sat, sun.

    If a show occurs multiple times per week, this can be specified with
    a comma.  for instance,

    /mon,tue,fri/4pm/1hr
    
    The showname should be followed by an xml, pls, m3u, or mp3 extension.
    In the case of using the .mp3 extension, it only returns the most recent 
    episode.

    It should also be viewable in a modern web browser.

    If you can find a podcaster that's not supported, please send an email 
    to [email protected].
    """
    
    if isinstance(weekday, (float)):
      start_time_list = [weekday]
      weekday_list = [ TS.WEEKDAY_LIST[ int(weekday / (60 * 24)) ] ]

    else:
      # Supports multiple weekdays
      weekday_list = weekday.split(',')
      start_time_list = [TS.to_utc(day, start) for day in weekday_list]

    duration_min = TS.duration_parse(duration_string)

    # This means we failed to parse
    if not duration_min:
      return do_error("duration '%s' is not set correctly" % duration_string)

    if not isinstance(start_time_list[0], (int, float)):
      return do_error('weekday and start times are not set correctly')

    buffer_show = 2
    # In #22 We're going to add 2 minutes to the duration to make sure that we get
    # the entire episode.
    duration_min += (buffer_show * 2)

    # And according to #149 we also go a minute back for the start time ... 
    # we need to do a little math to make sure we don't get a -1 edge case
    start_time_list = [(TS.MINUTES_PER_WEEK + offset - buffer_show) % TS.MINUTES_PER_WEEK for offset in start_time_list]

    # If we are here then it looks like our input is probably good.
    
    # Strip the .xml from the showname ... this will be used in our xml.
    parts = showname.split('.')
    file_type = parts.pop()
    showname = '.'.join(parts)

    # We come in with spaces as underscores so here we translate that back
    showname = re.sub('_', ' ', showname)

    # Make sure that we have all of our streams registered before trying
    # to infer what we can send to the user.
    cloud.register_stream_list()

    # Look for streams that we have which match this query and duration.
    # This will also create slices if necessary in a sub process.
    # The list of files that returns will include this not-yet-created
    # file-name as essentially a "promise" to when it will be made.
    feed_list = cloud.find_and_make_slices(start_time_list, duration_min)
    # print feed_list

    # Then, taking those two things, make a feed list from them.
    return generate_feed(
      file_type=file_type,
      showname=showname, 
      feed_list=feed_list, 
      duration_min=duration_min, 
      weekday_list=weekday_list, 
      start=start, 
      duration_string=duration_string
    )
Esempio n. 6
0
#!/usr/bin/python -O
import json
import lib.ts as TS

all_data = raw_input()

res = []
for data in all_data.split('_'):
  parts = data.strip().split(' ')
  res.append((TS.to_utc(parts[0], parts[1]), TS.duration_parse(parts[2])))

print json.dumps(res)