Skip to content

Commit

Permalink
Merge pull request #34 from rg3/master
Browse files Browse the repository at this point in the history
[pull] master from rg3:master
  • Loading branch information
pull[bot] authored Jan 1, 2019
2 parents a4d5b3d + d226c56 commit 36ffc45
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 43 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,25 @@ title = self._search_regex(
webpage, 'title', group='title')
```

### Long lines policy

There is a soft limit to keep lines of code under 80 characters long. This means it should be respected if possible and if it does not make readability and code maintenance worse.

For example, you should **never** split long string literals like URLs or some other often copied entities over multiple lines to fit this limit:

Correct:

```python
'https://www.youtube.com/watch?v=FqZTN594JQw&list=PLMYEtVRpaqY00V9W81Cwmzp6N6vZqfUKD4'
```

Incorrect:

```python
'https://www.youtube.com/watch?v=FqZTN594JQw&list='
'PLMYEtVRpaqY00V9W81Cwmzp6N6vZqfUKD4'
```

### Use safe conversion functions

Wrap all extracted numeric data into safe functions from [`youtube_dl/utils.py`](https://github.com/rg3/youtube-dl/blob/master/youtube_dl/utils.py): `int_or_none`, `float_or_none`. Use them for string to number conversions as well.
Expand Down
2 changes: 1 addition & 1 deletion youtube_dl/extractor/audiomack.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _real_extract(self, url):
# Audiomack wraps a lot of soundcloud tracks in their branded wrapper
# if so, pass the work off to the soundcloud extractor
if SoundcloudIE.suitable(api_response['url']):
return {'_type': 'url', 'url': api_response['url'], 'ie_key': 'Soundcloud'}
return self.url_result(api_response['url'], SoundcloudIE.ie_key())

return {
'id': compat_str(api_response.get('id', album_url_tag)),
Expand Down
12 changes: 2 additions & 10 deletions youtube_dl/extractor/cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ class CNNBlogsIE(InfoExtractor):
def _real_extract(self, url):
webpage = self._download_webpage(url, url_basename(url))
cnn_url = self._html_search_regex(r'data-url="(.+?)"', webpage, 'cnn url')
return {
'_type': 'url',
'url': cnn_url,
'ie_key': CNNIE.ie_key(),
}
return self.url_result(cnn_url, CNNIE.ie_key())


class CNNArticleIE(InfoExtractor):
Expand All @@ -145,8 +141,4 @@ class CNNArticleIE(InfoExtractor):
def _real_extract(self, url):
webpage = self._download_webpage(url, url_basename(url))
cnn_url = self._html_search_regex(r"video:\s*'([^']+)'", webpage, 'cnn url')
return {
'_type': 'url',
'url': 'http://cnn.com/video/?/video/' + cnn_url,
'ie_key': CNNIE.ie_key(),
}
return self.url_result('http://cnn.com/video/?/video/' + cnn_url, CNNIE.ie_key())
7 changes: 2 additions & 5 deletions youtube_dl/extractor/freespeech.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import unicode_literals

from .common import InfoExtractor
from .youtube import YoutubeIE


class FreespeechIE(InfoExtractor):
Expand All @@ -27,8 +28,4 @@ def _real_extract(self, url):
r'data-video-url="([^"]+)"',
webpage, 'youtube url')

return {
'_type': 'url',
'url': youtube_url,
'ie_key': 'Youtube',
}
return self.url_result(youtube_url, YoutubeIE.ie_key())
5 changes: 1 addition & 4 deletions youtube_dl/extractor/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2197,10 +2197,7 @@ def _extract_camtasia(self, url, video_id, webpage):

def _real_extract(self, url):
if url.startswith('//'):
return {
'_type': 'url',
'url': self.http_scheme() + url,
}
return self.url_result(self.http_scheme() + url)

parsed_url = compat_urlparse.urlparse(url)
if not parsed_url.scheme:
Expand Down
5 changes: 1 addition & 4 deletions youtube_dl/extractor/livestream.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,4 @@ def _real_extract(self, url):
id = mobj.group('id')
webpage = self._download_webpage(url, id)

return {
'_type': 'url',
'url': self._og_search_url(webpage),
}
return self.url_result(self._og_search_url(webpage))
7 changes: 2 additions & 5 deletions youtube_dl/extractor/savefrom.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,5 @@ class SaveFromIE(InfoExtractor):
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = os.path.splitext(url.split('/')[-1])[0]
return {
'_type': 'url',
'id': video_id,
'url': mobj.group('url'),
}

return self.url_result(mobj.group('url'), video_id=video_id)
6 changes: 2 additions & 4 deletions youtube_dl/extractor/ted.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ def _talk_info(self, url, video_name):
ext_url = None
if service.lower() == 'youtube':
ext_url = external.get('code')
return {
'_type': 'url',
'url': ext_url or external['uri'],
}

return self.url_result(ext_url or external['uri'])

resources_ = player_talk.get('resources') or talk_info.get('resources')

Expand Down
6 changes: 1 addition & 5 deletions youtube_dl/extractor/testurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,4 @@ def _real_extract(self, url):

self.to_screen('Test URL: %s' % tc['url'])

return {
'_type': 'url',
'url': tc['url'],
'id': video_id,
}
return self.url_result(tc['url'], video_id=video_id)
6 changes: 1 addition & 5 deletions youtube_dl/extractor/wimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ def _real_extract(self, url):
r'data-id=["\']([0-9A-Za-z_-]{11})'),
webpage, 'video URL', default=None)
if youtube_id:
return {
'_type': 'url',
'url': youtube_id,
'ie_key': YoutubeIE.ie_key(),
}
return self.url_result(youtube_id, YoutubeIE.ie_key())

info_dict = self._extract_jwplayer_data(
webpage, video_id, require_title=False)
Expand Down

0 comments on commit 36ffc45

Please sign in to comment.