Skip to content

Commit

Permalink
[FR - CNEWS] Add headers for requests
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopa00 committed Nov 11, 2023
1 parent c078086 commit 6395159
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions resources/lib/channels/fr/cnews.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
# num Page
URL_VIDEOS_CNEWS = URL_ROOT_SITE + '/service/dm_loadmore/dm_emission_index_sujets/%s/0'

GENERIC_HEADERS = {'User-Agent': web_utils.get_random_ua()}


# num Page

Expand Down Expand Up @@ -54,7 +56,7 @@ def list_categories(plugin, item_id, **kwargs):

@Route.register
def list_videos(plugin, item_id, category_url, page, **kwargs):
resp = urlquick.get(category_url % page, max_age=-1)
resp = urlquick.get(category_url % page, headers=GENERIC_HEADERS, max_age=-1)
parser = htmlement.HTMLement()
parser.feed(resp.json())
data = parser.close()
Expand All @@ -80,7 +82,7 @@ def get_video_id(plugin, video_id, download_mode=False, **kwargs):

@Route.register
def list_emissions(plugin, item_id, category_url, page, **kwargs):
resp = urlquick.get(URL_REPLAY_CNEWS, max_age=-1)
resp = urlquick.get(URL_REPLAY_CNEWS, headers=GENERIC_HEADERS, max_age=-1)
data = resp.parse("div", attrs={"class": "les-emissions"})

for video_datas in data.iterfind(".//a[@class='emission-item-wrapper']"):
Expand All @@ -97,7 +99,7 @@ def list_emissions(plugin, item_id, category_url, page, **kwargs):

@Route.register
def list_emissions_old(plugin, item_id, category_url, page, **kwargs):
resp = urlquick.get(category_url % page, max_age=-1)
resp = urlquick.get(category_url % page, header=GENERIC_HEADERS, max_age=-1)
parser = htmlement.HTMLement()
parser.feed(resp.json())
data = parser.close()
Expand All @@ -119,7 +121,7 @@ def list_emissions_old(plugin, item_id, category_url, page, **kwargs):

@Route.register
def list_videos_emission(plugin, item_id, video_url, **kwargs):
resp = urlquick.get(video_url, max_age=-1)
resp = urlquick.get(video_url, headers=GENERIC_HEADERS, max_age=-1)
root = resp.parse()

info = root.findall(".//p")[0].text
Expand Down Expand Up @@ -151,7 +153,7 @@ def list_videos_emission(plugin, item_id, video_url, **kwargs):

@Resolver.register
def get_video_url(plugin, item_id, video_url, download_mode=False, **kwargs):
root = urlquick.get(video_url, headers={'User-Agent': web_utils.get_random_ua()}, max_age=-1).parse()
root = urlquick.get(video_url, headers=GENERIC_HEADERS, max_age=-1).parse()
video_id = root.find(".//div[@id='embed-main-video']").get('data-videoid')
# video_id = re.compile(r'data-videoid\"\=\"(.*?)[\?\"]').findall(resp.text)[0]

Expand All @@ -160,9 +162,7 @@ def get_video_url(plugin, item_id, video_url, download_mode=False, **kwargs):

@Resolver.register
def get_live_url(plugin, item_id, **kwargs):
root = urlquick.get(URL_LIVE_CNEWS,
headers={'User-Agent': web_utils.get_random_ua()},
max_age=-1).parse()
root = urlquick.get(URL_LIVE_CNEWS, headers=GENERIC_HEADERS, max_age=-1).parse()
try:
live_id = root.find(".//div[@id='player_live']").get('data-videoid')
except Exception:
Expand Down

0 comments on commit 6395159

Please sign in to comment.