Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add function to download from youtube
- Loading branch information
Showing
9 changed files
with
175 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
.highlight-ipython3 { | ||
background-color: #f8f8c8; | ||
background-color: #dddddd; | ||
} | ||
|
||
div.highlight-ipython3 pre { | ||
background-color: #f8f8c8; | ||
background-color: #dddddd; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
@brief test log(time=1s) | ||
""" | ||
|
||
|
||
import sys | ||
import os | ||
import unittest | ||
|
||
|
||
try: | ||
import pyquickhelper | ||
except ImportError: | ||
path = os.path.normpath( | ||
os.path.abspath( | ||
os.path.join( | ||
os.path.split(__file__)[0], | ||
"..", | ||
"..", | ||
"..", | ||
"pyquickhelper", | ||
"src"))) | ||
if path not in sys.path: | ||
sys.path.append(path) | ||
import pyquickhelper | ||
|
||
|
||
try: | ||
import src | ||
except ImportError: | ||
path = os.path.normpath( | ||
os.path.abspath( | ||
os.path.join( | ||
os.path.split(__file__)[0], | ||
"..", | ||
".."))) | ||
if path not in sys.path: | ||
sys.path.append(path) | ||
import src | ||
|
||
|
||
from pyquickhelper.loghelper import fLOG | ||
from src.code_beatrix.faq.faq_python import instruction_pass | ||
|
||
|
||
class TestPass(unittest.TestCase): | ||
|
||
def test_pass(self): | ||
fLOG( | ||
__file__, | ||
self._testMethodName, | ||
OutputPrint=__name__ == "__main__") | ||
instruction_pass() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@brief test log(time=1s) | ||
""" | ||
|
||
|
||
import sys | ||
import os | ||
import unittest | ||
|
||
|
||
try: | ||
import pyquickhelper | ||
except ImportError: | ||
path = os.path.normpath( | ||
os.path.abspath( | ||
os.path.join( | ||
os.path.split(__file__)[0], | ||
"..", | ||
"..", | ||
"..", | ||
"pyquickhelper", | ||
"src"))) | ||
if path not in sys.path: | ||
sys.path.append(path) | ||
import pyquickhelper | ||
|
||
|
||
try: | ||
import src | ||
except ImportError: | ||
path = os.path.normpath( | ||
os.path.abspath( | ||
os.path.join( | ||
os.path.split(__file__)[0], | ||
"..", | ||
".."))) | ||
if path not in sys.path: | ||
sys.path.append(path) | ||
import src | ||
|
||
|
||
from pyquickhelper.loghelper import fLOG | ||
from pyquickhelper.pycode import get_temp_folder, ExtTestCase | ||
from src.code_beatrix.faq.faq_video import download_youtube_video | ||
|
||
|
||
class TestVideo(ExtTestCase): | ||
|
||
def test_video_download(self): | ||
fLOG( | ||
__file__, | ||
self._testMethodName, | ||
OutputPrint=__name__ == "__main__") | ||
temp = get_temp_folder(__file__, "temp_video_download") | ||
download_youtube_video('vHcfbOqYztU', output_path=temp) | ||
exp = os.path.join(temp, "vidéo tres courte.mp4") | ||
self.assertExists(exp) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ pymmails | |
pymyinstall | ||
pyquickhelper>=1.5.2259 | ||
pyshp | ||
pytube | ||
qgrid | ||
semantic_version | ||
shapely | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@file | ||
@brief Quelques questions d'ordre général autour du langage Python. | ||
""" | ||
from pytube import YouTube | ||
|
||
|
||
def download_youtube_video(tag, output_path=None, res='720p', mime_type="video/mp4", **kwargs): | ||
""" | ||
Downloads a video from :epkg:`youtube`. | ||
@param tag tag of the :epkg:`youtube` video to download | ||
@param output_path output path | ||
@param mime_type see :epkg:`youtube` | ||
@param res see :epkg:`youtube` | ||
@param kwargs see :epkg:`youtube` | ||
@return filename | ||
.. faqref:: | ||
:title: Télécharger une vidéo sur YouTube | ||
Le module :epkg:`pytube` permet de télécharger une vidéo | ||
:epkg:`youtube`. Chaque vidéo est disponible selon plusieurs | ||
format dont on récupère la liste avant de choisir | ||
qui correspond à celui voulu. | ||
:: | ||
from pytube import YouTube | ||
yt = YouTube('https://www.youtube.com/watch?v=tRFHXMQP-QU') | ||
st = yt.streams | ||
fil = st.filter(mime_type="video/mp4", res="720p") | ||
fil.first().download() | ||
""" | ||
yt = YouTube('https://www.youtube.com/watch?v={0}'.format(tag)) | ||
st = yt.streams.filter(mime_type=mime_type, res=res, **kwargs) | ||
fi = st.first() | ||
fi.download(output_path=output_path) | ||
return fi.default_filename |