Repository: ytdl-org/youtube-dl

Issue:
Rai raiTV Unable to extract relinker URL
### Make sure you are using the *latest* version: run `youtube-dl --version` and ensure your version is *2017.04.03*. If it's not read [this FAQ entry](https://github.com/rg3/youtube-dl/blob/master/README.md#how-do-i-update-youtube-dl) and update. Issues with outdated version will be rejected.
- [x] I've **verified** and **I assure** that I'm running youtube-dl **2017.04.03**

### Before submitting an *issue* make sure you have:
- [x] At least skimmed through [README](https://github.com/rg3/youtube-dl/blob/master/README.md) and **most notably** [FAQ](https://github.com/rg3/youtube-dl#faq) and [BUGS](https://github.com/rg3/youtube-dl#bugs) sections
- [x] [Searched](https://github.com/rg3/youtube-dl/search?type=Issues) the bugtracker for similar issues including closed ones

### What is the purpose of your *issue*?
- [x] Bug report (encountered problems with youtube-dl)
- [ ] Site support request (request for adding support for a new site)
- [ ] Feature request (request for a new functionality)
- [ ] Question
- [ ] Other

---

### If the purpose of this *issue* is a *bug report*, *site support request* or you are not completely sure provide the full verbose output as follows:

Add `-v` flag to **your command line** you run youtube-dl with, copy the **whole** output and insert it here. It should look similar to one below (replace it with **your** log inserted between triple ```):
```
pi@raspberrypi:~/EXT/PresaDiretta $ youtube-dl --fragment-retries 500 --download-archive riusciti.txt -f 'best[height<=480]' -o '%(upload_date)s.%(title)s.%(ext)s' -v http://www.presadiretta.rai.it/dl/portali/site/puntata/ContentItem-c62037e8-e6fd-47b7-9a56-3ca69a892c91.html
[debug] System config: []                                                                                                             
[debug] User config: []                                                                                                               
[debug] Custom config: []                                                                                                             
[debug] Command-line args: [u'--fragment-retries', u'500', u'--download-archive', u'riusciti.txt', u'-f', u'best[height<=480]', u'-o', u'%(upload_date)s.%(title)s.%(ext)s', u'-v', u'http://www.presadiretta.rai.it/dl/portali/site/puntata/ContentItem-c62037e8-e6fd-47b7-9a56-3ca69a892c91.html']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8                                                                      
[debug] youtube-dl version 2017.04.03                                                                                                 
[debug] Python version 2.7.9 - Linux-4.9.19-v7+-armv7l-with-debian-8.0                                                                
[debug] exe versions: ffmpeg 3.2.4-static, ffprobe 3.2.4-static                                                                       
[debug] Proxy map: {}                                                                                                                 
[Rai] c62037e8-e6fd-47b7-9a56-3ca69a892c91: Downloading webpage                                                                       
[Rai] c62037e8-e6fd-47b7-9a56-3ca69a892c91: Downloading video JSON                                                                    
ERROR: Unable to extract relinker URL; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type  youtube-dl -U  to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
Traceback (most recent call last):                                                                                                    
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/rai.py", line 372, in _real_extract                                            
    return self._extract_from_content_id(content_item_id, url)                                                                        
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/rai.py", line 282, in _extract_from_content_id                                 
    content_id, 'Downloading video JSON')                                                                                             
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 662, in _download_json                                        
    encoding=encoding, data=data, headers=headers, query=query)                                                                       
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 630, in _download_webpage                                     
    res = self._download_webpage_handle(url_or_request, video_id, note, errnote, fatal, encoding=encoding, data=data, headers=headers,
 query=query)                                                                                                                         
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 527, in _download_webpage_handle                              
    urlh = self._request_webpage(url_or_request, video_id, note, errnote, fatal, data=data, headers=headers, query=query)             
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 507, in _request_webpage                                      
    raise ExtractorError(errmsg, sys.exc_info()[2], cause=err)                                                                        
ExtractorError: Unable to download JSON metadata: HTTP Error 404: Not Found (caused by HTTPError()); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type  youtube-dl -U  to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
Traceback (most recent call last):                                                                                                    
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 761, in extract_info                                                 
    ie_result = ie.extract(url)                                                                                                       
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 429, in extract                                               
    ie_result = self._real_extract(url)                                                                                               
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/rai.py", line 390, in _real_extract                                            
    webpage, 'relinker URL', group='url')                                                                                             
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 778, in _search_regex                                         
    raise RegexNotFoundError('Unable to extract %s' % _name)                                                                          
RegexNotFoundError: Unable to extract relinker URL; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type  youtube-dl -U  to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
pi@raspberrypi:~/EXT/PresaDiretta $
```

---

### Description of your *issue*, suggested solution and other information
I try to download some video from presadiretta.rai.it. I try with version **2017.03.26** (because with the version **2017.04.03** i got an error) and i successful download video like this:
http://www.presadiretta.rai.it/dl/portali/site/puntata/ContentItem-3ed19d13-26c2-46ff-a551-b10828262f1b.html

when i try to download video like this
http://www.presadiretta.rai.it/dl/portali/site/puntata/ContentItem-c62037e8-e6fd-47b7-9a56-3ca69a892c91.html  

i got the error pasted in the verbose log ahead. The error is still the same with **2017.03.26** and  **2017.04.03** version.




Discussion:
I see right now that the second link don't have the video embedded in the page but have a link to another page. So i think there is no bug.. i try to download that link

there is no video on this page, if you want to download the linked video use the URL to the actual video.
@remitamine there is definitely  a video on this page.

`http://www.presadiretta.rai.it/dl/portali/site/puntata/ContentItem-3ed19d13-26c2-46ff-a551-b10828262f1b.html`
ok, it appears that the second link is valid(the first one used in the command is not).

Resolving patch:
diff --git a/youtube_dl/extractor/rai.py b/youtube_dl/extractor/rai.py
--- a/youtube_dl/extractor/rai.py
+++ b/youtube_dl/extractor/rai.py
@@ -326,6 +326,19 @@ class RaiIE(RaiBaseIE):
         'params': {
             'skip_download': True,
         },
+    }, {
+        # ContentItem in iframe (see #12652)
+        'url': 'http://www.presadiretta.rai.it/dl/portali/site/puntata/ContentItem-3ed19d13-26c2-46ff-a551-b10828262f1b.html',
+        'info_dict': {
+            'id': '1ad6dc64-444a-42a4-9bea-e5419ad2f5fd',
+            'ext': 'mp4',
+            'title': 'Partiti acchiappavoti - Presa diretta del 13/09/2015',
+            'description': 'md5:d291b03407ec505f95f27970c0b025f4',
+            'upload_date': '20150913',
+        },
+        'params': {
+            'skip_download': True,
+        },
     }, {
         # Direct MMS URL
         'url': 'http://www.rai.it/dl/RaiTV/programmi/media/ContentItem-b63a4089-ac28-48cf-bca5-9f5b5bc46df5.html',
@@ -403,7 +416,8 @@ def _real_extract(self, url):
                 r'''(?x)
                     (?:
                         (?:initEdizione|drawMediaRaiTV)\(|
-                        <(?:[^>]+\bdata-id|var\s+uniquename)=
+                        <(?:[^>]+\bdata-id|var\s+uniquename)=|
+                        <iframe[^>]+\bsrc=
                     )
                     (["\'])
                     (?:(?!\1).)*\bContentItem-(?P<id>%s)


Test patch: