Beispiel #1
0
def unmerged_podcasts_from_feed(channel: Channel,
                                limit: int) -> typing.List[Podcast]:
    feed = _podcasts_from_feed(channel.channel_info.url)
    podcasts = [
        Podcast(data=PodcastData(title=item['title'],
                                 subtitle=item['subtitle'],
                                 published=mktime(item['published_parsed']),
                                 audio_link=_find_mp3_link_in_feed_item_links(
                                     item['links'])),
                status=UnmergedStatus()) for item in feed
    ]

    return sorted(podcasts, key=lambda p: p.data.published,
                  reverse=True)[:limit]
Beispiel #2
0
def download_podcast(directory: RadioDirectory, channel: Channel,
                     podcast: Podcast) -> Podcast:
    location = download_location(directory, channel, podcast)
    url = get_podcast_audio_link(podcast)

    # TODO: This takes some time, especially when there are a lot to
    # download. I could have this spawn threads, or add priorities,
    # and so on. For now, since it runs every few hours, and is more
    # of a push than a pull situation for the user, I'm leaving it
    # simple
    success = _download_from_url(url, location)

    if success:
        return podcast._replace(status=NewStatus())
    else:
        return podcast
Beispiel #3
0
def test_download_location():
    podcast_data = Podcast(
        status=RequestedStatus(),
        data=podcast_data_factory(
            audio_link={
                'length': u'0',
                'href': u'http://feed.thisamericanlife.org/~r/talpodcast/~5/R0qvREKxypU/597.mp3',  # noqa
                'type': u'audio/mpeg',
                'rel': u'enclosure',
            }))

    channel = channel_factory()

    actual = download_location(
        RadioDirectory('dir'),
        channel,
        podcast_data)

    expected = 'dir/{0}/597.mp3'.format(DEFAULT_CHANNEL_INFO_DIRECTORY)

    assert actual == expected
Beispiel #4
0
def deleted_podcast_factory() -> Podcast:
    return Podcast(status=DeletedStatus(), data=podcast_data_factory())
Beispiel #5
0
def finished_podcast_factory() -> Podcast:
    return Podcast(status=FinishedStatus(), data=podcast_data_factory())
Beispiel #6
0
def started_podcast_factory() -> Podcast:
    return Podcast(status=StartedStatus(), data=podcast_data_factory())
Beispiel #7
0
def new_podcast_factory() -> Podcast:
    return Podcast(status=NewStatus(), data=podcast_data_factory())
Beispiel #8
0
def cancelled_podcast_factory() -> Podcast:
    return Podcast(status=CancelledStatus(), data=podcast_data_factory())
Beispiel #9
0
def requested_podcast_factory() -> Podcast:
    return Podcast(status=RequestedStatus(), data=podcast_data_factory())
Beispiel #10
0
def unmerged_podcast_factory() -> Podcast:
    return Podcast(status=UnmergedStatus(), data=podcast_data_factory())
Beispiel #11
0
import podcast.feeds
from podcast.feeds import _podcasts_from_feed
from podcast.feeds import unmerged_podcasts_from_feed
from podcast.models import Podcast
from podcast.models import PodcastData
from podcast.models import UnmergedStatus

EXPECTED_FROM_TEST_FEED = [
    Podcast(
        status=UnmergedStatus(),
        data=PodcastData(
            title=u'#502: This Call May Be Recorded... To Save Your Life',
            subtitle=
            u"A journalist named Meron Estefanos gets a disturbing tip. She's given a phone number that supposedly belongs to a group of refugees being held hostage in the Sinai desert. She dials the number, and soon dozens of strangers are begging her to rescue them.",  # noqa
            published=1476691200.0,
            audio_link={
                'length': u'0',
                'href':
                u'http://feed.thisamericanlife.org/~r/talpodcast/~5/S12K6GFrc7g/502.mp3',  # noqa
                'type': u'audio/mpeg',
                'rel': u'enclosure'
            })),
    Podcast(
        status=UnmergedStatus(),
        data=PodcastData(
            title=u'#598: My Undesirable Talent',
            subtitle=
            u'San Francisco\u2019s Spider-Man burglar was remarkable. He dropped into buildings from skylights, leapt 10 feet from one roof to another. But mostly, his talent got him into trouble. This week, his story, and stories of other undesirable talents.',  # noqa
            published=1476086400.0,
            audio_link={
                'length': u'0',
Beispiel #12
0
 def apply_delete_on_right_podcast(channel: Channel,
                                   podcast: Podcast) -> Podcast:
     if get_podcast_id(podcast) == podcast_id:
         _delete_podcast_file(radio.directory, channel, podcast)
         podcast = podcast._replace(status=DeletedStatus())
     return podcast
def load_podcasts():
    """
    Transfers all podcasts from the old database API
    for all programs into the new database
    creating objects of the Podcast model
    """
    for post, program_id in NAClient().get_podcasts():
        if post['status'] == "published":
            try:
                post_parent_program = get_program(program_id)
                
                parent_program_podcasts_homepage = get_content_homepage(
                    post_parent_program, 
                    ProgramPodcastsPage,
                    'Podcasts',
                )

                podcast_slug = slugify(post['title'])

                new_podcast = Podcast.objects.filter(slug=podcast_slug).first()

                if not new_podcast and podcast_slug:
                    new_podcast = Podcast(
                        search_description='',
                        seo_title='',
                        depth=5,
                        show_in_menus=False,
                        slug=podcast_slug,
                        title=post['title'],
                        date=get_post_date(post['publish_at']),
                        subheading=post['sub_headline'],
                        body=json.dumps([
                            {
                                'type': 'paragraph',
                                'value': post['content']
                            }
                        ]),
                        soundcloud=json.dumps([
                            {
                                'type': 'soundcloud_embed',
                                'value': post['soundcloud_url']
                            }
                        ]),
                        story_excerpt=get_summary(post['summary']),
                    )
                    parent_program_podcasts_homepage.add_child(
                    	instance=new_podcast
                    )
                    print("new podcast")
                    print(post['id'])
                    new_podcast.save()
                    get_post_authors(new_podcast, post['authors'])
                    connect_programs_to_post(new_podcast, post['programs'])
                elif new_podcast and podcast_slug and need_to_update_post(post['modified']):
                    new_podcast.search_description = ''
                    new_podcast.seo_title = ''
                    new_podcast.depth = 5
                    new_podcast.date = get_post_date(post['publish_at'])
                    new_podcast.show_in_menus = False
                    new_podcast.slug = podcast_slug
                    new_podcast.title = post['title']
                    new_podcast.body = json.dumps([
                            {
                                'type': 'paragraph',
                                'value': post['content']
                            }
                        ])
                    new_podcast.soundcloud=json.dumps([
                            {
                                'type': 'soundcloud_embed',
                                'value': post['soundcloud_url']
                            }
                        ])
                    new_podcast.subheading=post['sub_headline']
                    print("updating podcast")
                    print(post['id'])
                    new_podcast.save()
                    get_post_authors(new_podcast, post['authors'])
                    connect_programs_to_post(new_podcast, post['programs'])
            except django.db.utils.IntegrityError:
                pass