Ejemplo n.º 1
0
def rm_get_main_url(date_s):
    if not npr_utils.is_saturday(date_s):
        raise ValueError("Error, this date given by '%s' is not a Saturday." %
                         npr_utils.get_datestring(date_s) )
    
    mon_lower = date_s.strftime('%b').lower()
    year = date_s.year
    dsub = date_s.strftime('%y%m%d')
    full_rm_url = 'http://www.npr.org/programs/waitwait/archrndwn/%04d/%s/%s.waitwait.html' % (
        year, mon_lower, dsub )
    return full_rm_url
Ejemplo n.º 2
0
def rm_get_main_url(date_s):
    if not npr_utils.is_saturday(date_s):
        raise ValueError("Error, this date given by '%s' is not a Saturday." %
                         npr_utils.get_datestring(date_s))

    mon_lower = date_s.strftime('%b').lower()
    year = date_s.year
    dsub = date_s.strftime('%y%m%d')
    full_rm_url = 'http://www.npr.org/programs/waitwait/archrndwn/%04d/%s/%s.waitwait.html' % (
        year, mon_lower, dsub)
    return full_rm_url
Ejemplo n.º 3
0
def waitwait_crontab():
    """
    This python module downloads a Wait Wait... episode on a particular Saturday
    """

    # get current time
    current_date = datetime.date.fromtimestamp( time.time())
    if not npr_utils.is_saturday( current_date ):
        print "Error, today is not a Saturday. Instead, today is %s." % \
            current_date.strftime('%A')
        return
    
    # now download the episode into the correct directory
    waitwait.get_waitwait('/mnt/media/waitwait', current_date)
Ejemplo n.º 4
0
def waitwait_crontab():
    """
    This python module downloads a Wait Wait... episode on a particular Saturday
    """

    # get current time
    current_date = datetime.date.fromtimestamp(time.time())
    if not npr_utils.is_saturday(current_date):
        print "Error, today is not a Saturday. Instead, today is %s." % \
            current_date.strftime('%A')
        return

    # now download the episode into the correct directory
    waitwait.get_waitwait('/mnt/media/waitwait', current_date)
Ejemplo n.º 5
0
def get_waitwait(outputdir, date_s, order_totnum=None, file_data=None, debugonly=False, exec_dict=None):

    # check if outputdir is a directory
    if not os.path.isdir(outputdir):
        raise ValueError("Error, %s is not a directory." % outputdir)

    # check if actually saturday
    if not npr_utils.is_saturday(date_s):
        raise ValueError("Error, date = %s not a Saturday." % npr_utils.get_datestring(date_s))

    if exec_dict is None:
        exec_dict = npr_utils.find_necessary_executables()
    assert exec_dict is not None
    avconv_exec = exec_dict["avconv"]

    if order_totnum is None:
        order_totnum = npr_utils.get_order_number_saturday_in_year(date_s)
    order_in_year, tot_in_year = order_totnum

    if file_data is None:
        file_data = get_waitwait_image()

    year = date_s.year
    decdate = npr_utils.get_decdate(date_s)
    m4afile = os.path.join(outputdir, "NPR.WaitWait.%s.m4a" % decdate)

    if year >= 2006:
        tup = get_title_wavfile_standard(date_s, outputdir, avconv_exec, debugonly=debugonly)
        if tup is None:
            return
        title, outfiles = tup
        fnames = [filename.replace(" ", "\ ") for filename in outfiles]
        sox_string_cmd = "concat:%s" % "|".join(fnames)
        split_cmd = [
            avconv_exec,
            "-y",
            "-i",
            sox_string_cmd,
            "-ar",
            "44100",
            "-ac",
            "2",
            "-threads",
            "%d" % multiprocessing.cpu_count(),
            "-strict",
            "experimental",
            "-acodec",
            "aac",
            m4afile,
        ]
        proc = subprocess.Popen(split_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout_val, stderr_val = proc.communicate()
        for filename in outfiles:
            os.remove(filename)
    else:
        title = waitwait_realmedia.rm_get_title_from_url(date_s)
        rmfile = waitwait_realmedia.rm_download_file(date_s, outdir=outputdir)
        wavfile = waitwait_realmedia.rm_create_wav_file(date_s, rmfile, outdir=outputdir)
        os.remove(rmfile)

        # now convert to m4a file
        m4afile = os.path.join(outputdir, "NPR.WaitWait.%s.m4a" % decdate)
        split_cmd = [
            avconv_exec,
            "-y",
            "-i",
            wavfile,
            "-ar",
            "44100",
            "-ac",
            "2",
            "-threads",
            "%d" % multiprocessing.cpu_count(),
            "-strict",
            "experimental",
            "-acodec",
            "aac",
            m4afile,
        ]
        proc = subprocess.Popen(split_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout_val, stderr_val = proc.communicate()

        # remove wav file
        os.remove(wavfile)

    # now put in metadata
    mp4tags = mutagen.mp4.MP4(m4afile)
    mp4tags.tags["\xa9nam"] = [title]
    mp4tags.tags["\xa9alb"] = ["Wait Wait...Don't Tell Me: %d" % year]
    mp4tags.tags["\xa9ART"] = ["Peter Sagal"]
    mp4tags.tags["\xa9day"] = ["%d" % year]
    mp4tags.tags["\xa9cmt"] = ["more info at : NPR Web site"]
    mp4tags.tags["trkn"] = [(order_in_year, tot_in_year)]
    mp4tags.tags["covr"] = [mutagen.mp4.MP4Cover(file_data, mutagen.mp4.MP4Cover.FORMAT_PNG)]
    mp4tags.tags["\xa9gen"] = ["Podcast"]
    mp4tags.save()
    return m4afile
Ejemplo n.º 6
0
def get_waitwait(outputdir,
                 date_s,
                 order_totnum=None,
                 file_data=None,
                 debugonly=False,
                 exec_dict=None,
                 verify=True,
                 justFix=False):

    # check if outputdir is a directory
    if not os.path.isdir(outputdir):
        raise ValueError("Error, %s is not a directory." % outputdir)

    # check if actually saturday
    if not npr_utils.is_saturday(date_s):
        raise ValueError("Error, date = %s not a Saturday." %
                         npr_utils.get_datestring(date_s))

    if exec_dict is None:
        exec_dict = npr_utils.find_necessary_executables()
    assert (exec_dict is not None)
    avconv_exec = exec_dict['avconv']

    if order_totnum is None:
        order_totnum = npr_utils.get_order_number_saturday_in_year(date_s)
    order_in_year, tot_in_year = order_totnum

    if file_data is None:
        file_data = get_waitwait_image(verify=verify)

    year = date_s.year
    decdate = npr_utils.get_decdate(date_s)
    m4afile = os.path.join(outputdir, 'NPR.WaitWait.%s.m4a' % decdate)

    if year >= 2006:
        tup = get_title_wavfile_standard(date_s,
                                         outputdir,
                                         avconv_exec,
                                         debugonly=debugonly,
                                         verify=verify,
                                         justFix=justFix)
        if tup is None:
            return
        title, outfiles = tup
        if justFix:  # works only for year >= 2006
            if not os.path.isfile(m4afile):
                print "Error, %s does not exist." % os.path.basename(m4afile)
                return
            mp4tags = mutagen.mp4.MP4(m4afile)
            mp4tags.tags['\xa9nam'] = [
                title,
            ]
            mp4tags.save()
            logging.debug('fixed title for %s.' % m4afile)
            return m4afile
        fnames = map(lambda filename: filename.replace(' ', '\ '), outfiles)
        sox_string_cmd = 'concat:%s' % '|'.join(fnames)
        split_cmd = [
            avconv_exec, '-y', '-i', sox_string_cmd, '-ar', '44100', '-ac',
            '2', '-threads',
            '%d' % multiprocessing.cpu_count(), '-strict', 'experimental',
            '-acodec', 'aac', m4afile
        ]
        proc = subprocess.Popen(split_cmd,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        stdout_val, stderr_val = proc.communicate()
        if 'Protocol not found' in stderr_val.strip():
            for filename in outfiles:
                os.remove(filename)
            raise ValueError(
                "Error, AVCONV does not have the concatenation protocol.")
        for filename in outfiles:
            os.remove(filename)
    else:
        title = waitwait_realmedia.rm_get_title_from_url(date_s)
        rmfile = waitwait_realmedia.rm_download_file(date_s, outdir=outputdir)
        wavfile = waitwait_realmedia.rm_create_wav_file(date_s,
                                                        rmfile,
                                                        outdir=outputdir)
        os.remove(rmfile)

        # now convert to m4a file
        m4afile = os.path.join(outputdir, 'NPR.WaitWait.%s.m4a' % decdate)
        split_cmd = [
            avconv_exec, '-y', '-i', wavfile, '-ar', '44100', '-ac', '2',
            '-threads',
            '%d' % multiprocessing.cpu_count(), '-strict', 'experimental',
            '-acodec', 'aac', m4afile
        ]
        proc = subprocess.Popen(split_cmd,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        stdout_val, stderr_val = proc.communicate()

        # remove wav file
        os.remove(wavfile)

    # now put in metadata
    mp4tags = mutagen.mp4.MP4(m4afile)
    mp4tags.tags['\xa9nam'] = [
        title,
    ]
    mp4tags.tags['\xa9alb'] = [
        "Wait Wait...Don't Tell Me: %d" % year,
    ]
    mp4tags.tags['\xa9ART'] = [
        'Peter Sagal',
    ]
    mp4tags.tags['\xa9day'] = [
        '%d' % year,
    ]
    mp4tags.tags['\xa9cmt'] = [
        "more info at : NPR Web site",
    ]
    mp4tags.tags['trkn'] = [
        (order_in_year, tot_in_year),
    ]
    mp4tags.tags['covr'] = [
        mutagen.mp4.MP4Cover(file_data, mutagen.mp4.MP4Cover.FORMAT_PNG),
    ]
    mp4tags.tags['\xa9gen'] = [
        'Podcast',
    ]
    mp4tags.save()
    return m4afile