# noinspection PyProtectedMember
from crawler_fetcher.handlers.feed_podcast import (
    _get_feed_url_from_itunes_podcasts_url,
    _get_feed_url_from_google_podcasts_url,
)


def test_get_feed_url_from_itunes_podcasts_url():
    # noinspection PyTypeChecker
    assert _get_feed_url_from_itunes_podcasts_url(None) is None
    assert _get_feed_url_from_itunes_podcasts_url('') == ''
    assert _get_feed_url_from_itunes_podcasts_url('http://www.example.com/') == 'http://www.example.com/'
    assert _get_feed_url_from_itunes_podcasts_url('totally not an URL') == 'totally not an URL'

    # Let's just kind of hope RA doesn't change their underlying feed URL
    ra_feed_url = 'https://ra.co/xml/podcast.xml'

    ra_itunes_url = 'https://podcasts.apple.com/lt/podcast/ra-podcast/id129673441'
    assert _get_feed_url_from_itunes_podcasts_url(ra_itunes_url) == ra_feed_url

    # Try uppercase host
    ra_itunes_url = 'https://PODCASTS.APPLE.COM/lt/podcast/ra-podcast/id129673441'
    assert _get_feed_url_from_itunes_podcasts_url(ra_itunes_url) == ra_feed_url

    # Try old style URL
    ra_itunes_url = 'https://itunes.apple.com/lt/podcast/ra-podcast/id129673441'
    assert _get_feed_url_from_itunes_podcasts_url(ra_itunes_url) == ra_feed_url


def test_get_feed_url_from_google_podcasts_url():
    # noinspection PyTypeChecker
    assert _get_feed_url_from_google_podcasts_url(None) is None
    assert _get_feed_url_from_google_podcasts_url('') == ''
    assert _get_feed_url_from_google_podcasts_url('http://www.example.com/') == 'http://www.example.com/'
    assert _get_feed_url_from_google_podcasts_url('totally not an URL') == 'totally not an URL'

    npr_feed_url = 'https://www.npr.org/rss/podcast.php?id=381444908'

    # Test with URL pointing to a show's homepage (not invidual episode)

    npr_google_show_url = (
        'https://podcasts.google.com/feed/aHR0cHM6Ly9mZWVkcy5ucHIub3JnLzM4MTQ0NDkwOC9wb2RjYXN0LnhtbA?sa=X'
        '&ved=2ahUKEwjKm6fimbjuAhWMjoQIHUrSCW0Qjs4CKAl6BAgBEH4'
    )

    assert _get_feed_url_from_google_podcasts_url(npr_google_show_url) == npr_feed_url

    # Test with URL that points to a specific episode
    npr_google_ep_url = (
        'https://podcasts.google.com/feed/aHR0cHM6Ly9mZWVkcy5ucHIub3JnLzM4MTQ0NDkwOC9wb2RjYXN0LnhtbA/episode/'
        'MjA5MmZjM2ItYmMwZi00NGFiLWFlNDktM2I3YmFhMjA4ODVi?sa=X&ved=0CAUQkfYCahcKEwjg4s3umbjuAhUAAAAAHQAAAAAQAQ'
    )

    assert _get_feed_url_from_google_podcasts_url(npr_google_ep_url) == npr_feed_url

@@ -1659,19 +1659,18 @@
 L'%0A%0A    
-npr
+ft
 _feed_ur
@@ -1686,48 +1686,36 @@
 s://
-www.npr.org/rss/podcast.php?id=381444908
+rss.acast.com/ftnewsbriefing
 '%0A%0A 
@@ -1787,27 +1787,26 @@
 isode)%0A%0A    
-npr
+ft
 _google_show
@@ -1871,124 +1871,111 @@
 6Ly9
-mZWVkcy5ucHIub3JnLzM4MTQ0NDkwOC9wb2RjYXN0LnhtbA?sa=X'%0A        '&ved=2ahUKEwjKm6fimbjuAhWMjoQIHUrSCW0Qjs4CKAl6BAgBEH4
+yc3MuYWNhc3QuY29tL2Z0bmV3c2JyaWVmaW5n?sa=X'%0A        '&ved=0CH4Qjs4CKARqFwoTCIjZ5ZTNwvECFQAAAAAdAAAAABAL
 '%0A  
@@ -2021,35 +2021,34 @@
 le_podcasts_url(
-npr
+ft
 _google_show_url
@@ -2044,35 +2044,34 @@
 le_show_url) == 
-npr
+ft
 _feed_url%0A%0A    #
@@ -2123,19 +2123,18 @@
 ode%0A    
-npr
+ft
 _google_
@@ -2201,123 +2201,113 @@
 6Ly9
-mZWVkcy5ucHIub3JnLzM4MTQ0NDkwOC9wb2RjYXN0LnhtbA/episode/'%0A        'MjA5MmZjM2ItYmMwZi00NGFiLWFlNDktM2I3YmFhMjA4ODVi
+yc3MuYWNhc3QuY29tL2Z0bmV3c2JyaWVmaW5n/episode/'%0A        'NzM4Y2Q2NWEtMWM5Ni00Y2FjLWI5NDYtN2ExNGVmYThhOWRm
 ?sa=
@@ -2331,18 +2331,18 @@
 cKEw
-jg4s3umbju
+iI2eWUzcLx
 AhUA
@@ -2353,18 +2353,18 @@
 HQAAAAAQ
-AQ
+Dg
 '%0A    )%0A
@@ -2414,19 +2414,18 @@
 sts_url(
-npr
+ft
 _google_
@@ -2439,11 +2439,10 @@
  == 
-npr
+ft
 _fee

use FT in google podcast test