about summary refs log tree commit diff
path: root/CONTRIBUTING.md
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2018-11-07 01:38:25 +0700
committerSergey M․ <dstftw@gmail.com>2018-11-07 01:38:25 +0700
commit532782ade1dab884606dbbd82081ed7ab9c52a13 (patch)
tree752da253137ab9da3fb7c2b613c463b59023e1e4 /CONTRIBUTING.md
parentf81d44aab6d8ee01024a637cb80374251737872e (diff)
downloadyoutube-dl-532782ade1dab884606dbbd82081ed7ab9c52a13.tar.gz
youtube-dl-532782ade1dab884606dbbd82081ed7ab9c52a13.tar.xz
youtube-dl-532782ade1dab884606dbbd82081ed7ab9c52a13.zip
release 2018.11.07 2018.11.07
Diffstat (limited to 'CONTRIBUTING.md')
-rw-r--r--CONTRIBUTING.md23
1 files changed, 22 insertions, 1 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 333acee80..bbcb78808 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -296,5 +296,26 @@ title = self._search_regex(
 
 ### Use safe conversion functions
 
-Wrap all extracted numeric data into safe functions from `utils`: `int_or_none`, `float_or_none`. Use them for string to number conversions as well.
+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.
+
+Use `url_or_none` for safe URL processing.
+
+Use `try_get` for safe metadata extraction from parsed JSON.
+
+Explore [`youtube_dl/utils.py`](https://github.com/rg3/youtube-dl/blob/master/youtube_dl/utils.py) for more useful convenience functions.
+
+#### More examples
+
+##### Safely extract optional description from parsed JSON
+```python
+description = try_get(response, lambda x: x['result']['video'][0]['summary'], compat_str)
+```
+
+##### Safely extract more optional metadata
+```python
+video = try_get(response, lambda x: x['result']['video'][0], dict) or {}
+description = video.get('summary')
+duration = float_or_none(video.get('durationMs'), scale=1000)
+view_count = int_or_none(video.get('views'))
+```