 
 
   def get(episode_map, podcast_id) do
-    case Repo.get_by(PanWeb.Episode, guid: episode_map[:guid], podcast_id: podcast_id) do
+    case Repo.get_by(PanWeb.Episode, guid: episode_map.guid, podcast_id: podcast_id) do
       nil ->
-        case Repo.get_by(PanWeb.Episode, title: episode_map[:title], podcast_id: podcast_id) do
+        case Repo.get_by(PanWeb.Episode, title: episode_map.title, podcast_id: podcast_id) do
           nil ->
             {:error, "not_found"}
           episode ->

    episodes = Repo.all(PanWeb.Episode)

    for episode <- episodes do
      PanWeb.Episode.changeset(episode, %{description: HtmlSanitizeEx2.basic_html_reduced(episode.description),
                                          summary:     HtmlSanitizeEx2.basic_html_reduced(episode.summary)})
      |> Repo.update()
    end
  end
end
  def persist_many(episodes_map, podcast) do
    for {_, episode_map} <- episodes_map do

      if episode_map.enclosures do
        first_enclosure = episode_map.enclosures |> Map.to_list |> List.first |> elem(1)
        fallback_url = if episode_map.link, do: episode_map.link, else: first_enclosure.url

        plain_episode_map = episode_map
        |> Map.drop([:chapters, :enclosures, :contributors])
        |> Map.put_new(:guid, fallback_url)

        case get_or_insert(plain_episode_map, podcast.id) do
          {:ok, episode} ->
            if episode_map.chapters do
              for {_, chapter_map} <- episode_map.chapters do
                Chapter.get_or_insert(chapter_map, episode.id)
              end
            end

            if episode_map.enclosures do
              for {_, enclosure_map} <- episode_map.enclosures do
                Enclosure.get_or_insert(enclosure_map, episode.id)
              end
            end

            Contributor.persist_many(episode_map.contributors, episode)
            Author.get_or_insert_persona_and_gig(episode_map.author, episode, podcast)
            Logger.info "\n\e[33m === Importing new episode: #{episode.title} ===\e[0m"
          {:exists, _episode} ->
            true
