@@ -24,17 +24,54 @@ export const route: Route = {
2424 } ,
2525 radar : [
2626 {
27- source : [ 'www3.nhk.or.jp /news/easy/' , 'www3.nhk.or.jp /' ] ,
27+ source : [ 'news.web.nhk /news/easy/' , 'news.web.nhk /' ] ,
2828 } ,
2929 ] ,
3030 name : 'News Web Easy' ,
3131 maintainers : [ 'Andiedie' ] ,
3232 handler,
33- url : 'www3.nhk.or.jp /news/easy/' ,
33+ url : 'news.web.nhk /news/easy/' ,
3434} ;
3535
3636async function handler ( ctx ) {
37- const data = await ofetch ( 'https://www3.nhk.or.jp/news/easy/news-list.json' ) ;
37+ const buildAuthorizeResponse = await ofetch . raw ( 'https://news.web.nhk/tix/build_authorize' , {
38+ query : {
39+ idp : 'a-alaz' ,
40+ profileType : 'abroad' ,
41+ redirect_uri : 'https://news.web.nhk/news/easy/' ,
42+ entity : 'none' ,
43+ area : '130' ,
44+ pref : '13' ,
45+ jisx0402 : '13101' ,
46+ postal : '1000001' ,
47+ } ,
48+ redirect : 'manual' ,
49+ } ) ;
50+ const buildAuthorizeCookie = buildAuthorizeResponse . headers
51+ . getSetCookie ( )
52+ . map ( ( c ) => c . split ( ';' ) [ 0 ] )
53+ . join ( '; ' ) ;
54+
55+ const authorizeResponse = await ofetch . raw ( buildAuthorizeResponse . headers . get ( 'location' ) , {
56+ redirect : 'manual' ,
57+ } ) ;
58+
59+ const idpResponse = await ofetch . raw ( authorizeResponse . headers . get ( 'location' ) , {
60+ headers : {
61+ cookie : buildAuthorizeCookie ,
62+ } ,
63+ redirect : 'manual' ,
64+ } ) ;
65+ const idpCookie = idpResponse . headers
66+ . getSetCookie ( )
67+ . map ( ( c ) => c . split ( ';' ) [ 0 ] )
68+ . join ( '; ' ) ;
69+
70+ const data = await ofetch ( 'https://news.web.nhk/news/easy/news-list.json' , {
71+ headers : {
72+ cookie : buildAuthorizeCookie + '; ' + idpCookie ,
73+ } ,
74+ } ) ;
3875 const dates = data [ 0 ] ;
3976
4077 let items = Object . values ( dates ) . flatMap ( ( articles ) =>
@@ -46,7 +83,7 @@ async function handler(ctx) {
4683 } ) ,
4784 guid : article . news_id ,
4885 pubDate : timezone ( parseDate ( article . news_prearranged_time ) , + 9 ) ,
49- link : `https://www3.nhk.or.jp /news/easy/${ article . news_id } /${ article . news_id } .html` ,
86+ link : `https://news.web.nhk /news/easy/${ article . news_id } /${ article . news_id } .html` ,
5087 } ) )
5188 ) ;
5289
@@ -55,7 +92,11 @@ async function handler(ctx) {
5592 items = await Promise . all (
5693 items . map ( ( item ) =>
5794 cache . tryGet ( item . link , async ( ) => {
58- const data = await ofetch ( item . link ) ;
95+ const data = await ofetch ( item . link , {
96+ headers : {
97+ cookie : buildAuthorizeCookie + '; ' + idpCookie ,
98+ } ,
99+ } ) ;
59100 const $ = load ( data ) ;
60101 item . description += $ ( '.article-body' ) . html ( ) ;
61102 return item ;
@@ -65,7 +106,7 @@ async function handler(ctx) {
65106
66107 return {
67108 title : 'NEWS WEB EASY' ,
68- link : 'https://www3.nhk.or.jp /news/easy/' ,
109+ link : 'https://news.web.nhk /news/easy/' ,
69110 description : 'NEWS WEB EASYは、小学生・中学生の皆さんや、日本に住んでいる外国人のみなさんに、わかりやすいことば でニュースを伝えるウェブサイトです。' ,
70111 item : items ,
71112 } ;
0 commit comments