From f6368b642ab31e65cd39183adc97c3a4e203fff8 Mon Sep 17 00:00:00 2001 From: Eren Dogan Date: Fri, 22 Dec 2023 01:34:31 -0800 Subject: [PATCH 1/2] [cnnturk] Add new extractor --- youtube_dl/extractor/cnnturk.py | 132 +++++++++++++++++++++++++++++ youtube_dl/extractor/extractors.py | 1 + 2 files changed, 133 insertions(+) create mode 100644 youtube_dl/extractor/cnnturk.py diff --git a/youtube_dl/extractor/cnnturk.py b/youtube_dl/extractor/cnnturk.py new file mode 100644 index 000000000..108624894 --- /dev/null +++ b/youtube_dl/extractor/cnnturk.py @@ -0,0 +1,132 @@ +# coding: utf-8 +from __future__ import unicode_literals + +from .common import InfoExtractor + + +class CNNTurkIE(InfoExtractor): + _VALID_URL = r'''(?x) + https?:// + (?:www\.)?cnnturk\.com/ + (?: + tv-cnn-turk/programlar/| + video/| + turkiye/| + dunya/| + ekonomi/ + ) + (?:[^/]+/)* + (?P[^/?#&]+) + ''' + _TESTS = [ + { + 'url': 'https://www.cnnturk.com/tv-cnn-turk/programlar/' + 'dort-bir-taraf/dort-bir-taraf-43', + 'md5': 'ea49375a769545afdb8d63d4efb46f8b', + 'info_dict': { + 'id': 'dort-bir-taraf-43', + 'ext': 'mp4', + 'title': 'Dört Bir Taraf', + 'description': 'Altan Öymen, Nazlı Ilıcak, Enver Aysever ve ' + 'Nagehan Alçı ülke gündemini dört farklı ' + 'açıdan değerlendiriyor. Sezaryen ve kürtaj ' + 'polemiğinde gerçekler ve yanıl...', + 'thumbnail': 'https://image.cnnturk.com/i/cnnturk/75/1200x675/' + '542174c1cecfbe19c07cacea.jpg', + 'upload_date': '20120601', + } + }, + { + 'url': 'https://www.cnnturk.com/tv-cnn-turk/programlar/' + 'tarafsiz-bolge/mahalle-baskisi-anayasa-tartismasi', + 'md5': 'c3999fbe0fb3366b36cb2ea56d692697', + 'info_dict': { + 'id': 'mahalle-baskisi-anayasa-tartismasi', + 'ext': 'mp4', + 'title': 'MAHALLE BASKISI - ANAYASA TARTIŞMASI', + 'description': 'MAHALLE BASKISI , ANAYASA TARTIŞMASI ,' + 'ŞAHİN MENGÜ , YAVUZ ATAR , FARUK BAL , ' + 'NURAY MERT , TOKTAMIŞ ATEŞ , EMRE AKÖZ , ' + 'AYŞE BÖHÜRLER...', + 'thumbnail': 'https://image.cnnturk.com/i/cnnturk/75/1200x675/' + '63530cb4bf773b1104bb482d.jpg', + 'upload_date': '20120330', + } + }, + { + 'url': 'https://www.cnnturk.com/tv-cnn-turk/programlar/' + 'edip-akbayram-enver-aysever-in-sorularini-yanitladi-' + 'aykiri-sorular-09-07-2012', + 'md5': '36814483fe64d450f35c985d5a2d2d18', + 'info_dict': { + 'id': 'edip-akbayram-enver-aysever-in-sorularini-yanitladi-' + 'aykiri-sorular-09-07-2012', + 'ext': 'mp4', + 'title': 'Edip Akbayram, Enver Aysever’in sorularını yanıtladı' + ' - Aykırı Sorular (09.07.2012)', + 'description': 'Anadolu Pop Müziğinin önde gelen isimlerinden ' + 'Edip Akbayram 9 Temmuz 2012 tarihli ' + 'Aykırı Sorular programında Enver Ayseverin ' + 'konuğu oldu....', + 'thumbnail': 'https://image.cnnturk.com/i/cnnturk/75/1200x675/' + '54353b6dcecfbe1578205c80.jpg', + 'upload_date': '20120710', + } + }, + { + 'url': 'https://www.cnnturk.com/tv-cnn-turk/programlar/' + 'aykiri-sorular/ilber-ortayli-enver-ayseverin-sorularini-' + 'yanitladi-aykiri-sorular-16-06-2014', + 'md5': '36814483fe64d450f35c985d5a2d2d18', + 'info_dict': { + 'id': 'ilber-ortayli-enver-ayseverin-sorularini-yanitladi-' + 'aykiri-sorular-16-06-2014', + 'ext': 'm3u8', + 'title': 'İlber Ortaylı Enver Aysever\'in sorularını yanıtladı:' + ' Aykırı Sorular - 16.06.2014', + 'description': 'Aykırı Sorular, Tarihçi ' + 'Prof. Dr. İlber Ortaylıyı konuk etti. ' + 'Cumhurbaşkanı seçimi Türkiye açısından ne ' + 'ifade ediyor? Çatı adayı muhalefeti ' + 'birleştirebilece...', + 'thumbnail': 'https://image.cnnturk.com/i/cnnturk/75/1200x675/' + '54353e78cecfbe15782068ae.jpg', + 'upload_date': '20140617', + }, + 'params': { + # m3u8 download + 'skip_download': True, + } + } + ] + + def _real_extract(self, url): + video_id = self._match_id(url) + + webpage = self._download_webpage(url, video_id) + + # Video info is a JSON object inside a script tag + video_info = self._parse_json( + self._search_regex( + r'({"Ancestors":.+?\);)', webpage, 'stream')[:-2], + video_id) + + video_url = video_info['MediaFiles'][0]['Path'] + if not video_url.startswith("http"): + video_url = 'https://cnnvod.duhnet.tv/' + video_url + extension = 'mp4' if video_url.endswith('mp4') else 'm3u8' + formats = [{ + 'url': video_url, + 'ext': extension, + 'language': 'tr', + }] + + return { + 'id': video_id, + 'title': self._og_search_title(webpage), + 'description': self._og_search_description(webpage), + 'thumbnail': self._og_search_thumbnail(webpage), + 'release_date': video_info['published_date'], + 'upload_date': video_info['created_date'], + 'formats': formats, + } diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 82221445f..544087c53 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -246,6 +246,7 @@ from .cnn import ( CNNBlogsIE, CNNArticleIE, ) +from .cnnturk import CNNTurkIE from .coub import CoubIE from .comedycentral import ( ComedyCentralIE, From f295f4f6e4e7a49ba562a993859c10de1f978ae8 Mon Sep 17 00:00:00 2001 From: dirkf Date: Thu, 22 Feb 2024 15:54:20 +0000 Subject: [PATCH 2/2] Lay out `_TESTS` more compactly --- youtube_dl/extractor/cnnturk.py | 125 ++++++++++++-------------------- 1 file changed, 46 insertions(+), 79 deletions(-) diff --git a/youtube_dl/extractor/cnnturk.py b/youtube_dl/extractor/cnnturk.py index 108624894..dfbbe8867 100644 --- a/youtube_dl/extractor/cnnturk.py +++ b/youtube_dl/extractor/cnnturk.py @@ -18,87 +18,54 @@ class CNNTurkIE(InfoExtractor): (?:[^/]+/)* (?P[^/?#&]+) ''' - _TESTS = [ - { - 'url': 'https://www.cnnturk.com/tv-cnn-turk/programlar/' - 'dort-bir-taraf/dort-bir-taraf-43', - 'md5': 'ea49375a769545afdb8d63d4efb46f8b', - 'info_dict': { - 'id': 'dort-bir-taraf-43', - 'ext': 'mp4', - 'title': 'Dört Bir Taraf', - 'description': 'Altan Öymen, Nazlı Ilıcak, Enver Aysever ve ' - 'Nagehan Alçı ülke gündemini dört farklı ' - 'açıdan değerlendiriyor. Sezaryen ve kürtaj ' - 'polemiğinde gerçekler ve yanıl...', - 'thumbnail': 'https://image.cnnturk.com/i/cnnturk/75/1200x675/' - '542174c1cecfbe19c07cacea.jpg', - 'upload_date': '20120601', - } - }, - { - 'url': 'https://www.cnnturk.com/tv-cnn-turk/programlar/' - 'tarafsiz-bolge/mahalle-baskisi-anayasa-tartismasi', - 'md5': 'c3999fbe0fb3366b36cb2ea56d692697', - 'info_dict': { - 'id': 'mahalle-baskisi-anayasa-tartismasi', - 'ext': 'mp4', - 'title': 'MAHALLE BASKISI - ANAYASA TARTIŞMASI', - 'description': 'MAHALLE BASKISI , ANAYASA TARTIŞMASI ,' - 'ŞAHİN MENGÜ , YAVUZ ATAR , FARUK BAL , ' - 'NURAY MERT , TOKTAMIŞ ATEŞ , EMRE AKÖZ , ' - 'AYŞE BÖHÜRLER...', - 'thumbnail': 'https://image.cnnturk.com/i/cnnturk/75/1200x675/' - '63530cb4bf773b1104bb482d.jpg', - 'upload_date': '20120330', - } - }, - { - 'url': 'https://www.cnnturk.com/tv-cnn-turk/programlar/' - 'edip-akbayram-enver-aysever-in-sorularini-yanitladi-' - 'aykiri-sorular-09-07-2012', - 'md5': '36814483fe64d450f35c985d5a2d2d18', - 'info_dict': { - 'id': 'edip-akbayram-enver-aysever-in-sorularini-yanitladi-' - 'aykiri-sorular-09-07-2012', - 'ext': 'mp4', - 'title': 'Edip Akbayram, Enver Aysever’in sorularını yanıtladı' - ' - Aykırı Sorular (09.07.2012)', - 'description': 'Anadolu Pop Müziğinin önde gelen isimlerinden ' - 'Edip Akbayram 9 Temmuz 2012 tarihli ' - 'Aykırı Sorular programında Enver Ayseverin ' - 'konuğu oldu....', - 'thumbnail': 'https://image.cnnturk.com/i/cnnturk/75/1200x675/' - '54353b6dcecfbe1578205c80.jpg', - 'upload_date': '20120710', - } + _TESTS = [{ + 'url': 'https://www.cnnturk.com/tv-cnn-turk/programlar/dort-bir-taraf/dort-bir-taraf-43', + 'md5': 'ea49375a769545afdb8d63d4efb46f8b', + 'info_dict': { + 'id': 'dort-bir-taraf-43', + 'ext': 'mp4', + 'title': 'Dört Bir Taraf', + 'description': r're:Altan Öymen, Nazlı Ilıcak, Enver Aysever ve .{116}$', + 'thumbnail': 'https://image.cnnturk.com/i/cnnturk/75/1200x675/542174c1cecfbe19c07cacea.jpg', + 'upload_date': '20120601', + } + }, { + 'url': 'https://www.cnnturk.com/tv-cnn-turk/programlar/tarafsiz-bolge/mahalle-baskisi-anayasa-tartismasi', + 'md5': 'c3999fbe0fb3366b36cb2ea56d692697', + 'info_dict': { + 'id': 'mahalle-baskisi-anayasa-tartismasi', + 'ext': 'mp4', + 'title': 'MAHALLE BASKISI - ANAYASA TARTIŞMASI', + 'description': r're:MAHALLE BASKISI , ANAYASA TARTIŞMASI .{96}$', + 'thumbnail': 'https://image.cnnturk.com/i/cnnturk/75/1200x675/63530cb4bf773b1104bb482d.jpg', + 'upload_date': '20120330', + } + }, { + 'url': 'https://www.cnnturk.com/tv-cnn-turk/programlar/edip-akbayram-enver-aysever-in-sorularini-yanitladi-aykiri-sorular-09-07-2012', + 'md5': '36814483fe64d450f35c985d5a2d2d18', + 'info_dict': { + 'id': 'edip-akbayram-enver-aysever-in-sorularini-yanitladi-aykiri-sorular-09-07-2012', + 'ext': 'mp4', + 'title': 'Edip Akbayram, Enver Aysever’in sorularını yanıtladı - Aykırı Sorular (09.07.2012)', + 'description': 'Anadolu Pop Müziğinin önde gelen isimlerinden .{94}$', + 'thumbnail': 'https://image.cnnturk.com/i/cnnturk/75/1200x675/54353b6dcecfbe1578205c80.jpg', + 'upload_date': '20120710', + } + }, { + 'url': 'https://www.cnnturk.com/tv-cnn-turk/programlar/aykiri-sorular/ilber-ortayli-enver-ayseverin-sorularini-yanitladi-aykiri-sorular-16-06-2014', + 'md5': '36814483fe64d450f35c985d5a2d2d18', + 'info_dict': { + 'id': 'ilber-ortayli-enver-ayseverin-sorularini-yanitladi-aykiri-sorular-16-06-2014', + 'ext': 'm3u8', + 'title': 'İlber Ortaylı Enver Aysever\'in sorularını yanıtladı: Aykırı Sorular - 16.06.2014', + 'description': 'Aykırı Sorular, Tarihçi Prof. Dr. İlber Ortaylıyı .{109}', + 'thumbnail': 'https://image.cnnturk.com/i/cnnturk/75/1200x675/54353e78cecfbe15782068ae.jpg', + 'upload_date': '20140617', }, - { - 'url': 'https://www.cnnturk.com/tv-cnn-turk/programlar/' - 'aykiri-sorular/ilber-ortayli-enver-ayseverin-sorularini-' - 'yanitladi-aykiri-sorular-16-06-2014', - 'md5': '36814483fe64d450f35c985d5a2d2d18', - 'info_dict': { - 'id': 'ilber-ortayli-enver-ayseverin-sorularini-yanitladi-' - 'aykiri-sorular-16-06-2014', - 'ext': 'm3u8', - 'title': 'İlber Ortaylı Enver Aysever\'in sorularını yanıtladı:' - ' Aykırı Sorular - 16.06.2014', - 'description': 'Aykırı Sorular, Tarihçi ' - 'Prof. Dr. İlber Ortaylıyı konuk etti. ' - 'Cumhurbaşkanı seçimi Türkiye açısından ne ' - 'ifade ediyor? Çatı adayı muhalefeti ' - 'birleştirebilece...', - 'thumbnail': 'https://image.cnnturk.com/i/cnnturk/75/1200x675/' - '54353e78cecfbe15782068ae.jpg', - 'upload_date': '20140617', - }, - 'params': { - # m3u8 download - 'skip_download': True, - } + 'params': { + 'skip_download': 'm3u8', } - ] + }] def _real_extract(self, url): video_id = self._match_id(url)