10 examples of 'python download video from url' in Python

Every line of 'python download video from url' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
137@staticmethod
138def _download(url):
139 return urllib2.urlopen(urllib2.Request(url, headers=Provider.HEADERS))
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

6def download_youtube_video(url, itag=None, audio_only=False, output_path=None,
7 filename=None, filename_prefix=None,
8 proxies=None, progress_callback=None):
9 """
10 Download a YouTube Video.
11 :param url: Full URL to YouTube Video or YouTube Video ID
12 :type url: str
13 :param itag: YouTube Stream ITAG to Download
14 :type itag: int
15 :param audio_only: Download only the audio for the video. Takes longer than video.
16 :type audio_only: bool
17 :param output_path: Path to folder to output file.
18 :type output_path: str
19 :param filename: Filename override. Does not override extension.
20 :type filename: str
21 :param filename_prefix: Currently Does Not Work on pytube
22 :type filename_prefix: str
23 :param proxies: Dictionary containing protocol (key) and address (value) for the proxies
24 :type proxies: dict
25 :return: Filename of downloaded video/audio
26 :rtype: str
27 """
28 if output_path:
29 makedirs(output_path, exist_ok=True)
30 if 'http' not in url:
31 url = 'https://www.youtube.com/watch?v=%s' % url
32 if proxies:
33 video = YouTube(url, proxies=proxies)
34 else:
35 video = YouTube(url)
36 if progress_callback:
37 video.register_on_progress_callback(progress_callback)
38 if itag:
39 itag = int(itag)
40 stream = video.streams.get_by_itag(itag)
41 else:
42 stream = video.streams.filter(only_audio=audio_only).first()
43 print('Download Started: %s' % video.title)
44 if filename:
45 filename = safe_filename(filename)
46 stream.download(output_path=output_path, filename=filename)
47 file_type = '.' + stream.mime_type.split('/')[1]
48 filename = stream.default_filename if filename is None else filename + file_type
49 print('Download Complete! Saved to file: %s' % filename)
50 return filename
165def download(url):
166 downloader = get_best_downloader()
167 downloader(url, os.path.basename(url))
58def download(self, url):
59 '''
60 下载指定url页面
61 :param url:
62 :return:
63 '''
64 headers = {
65 'User-Agent': useragent.getUserAgent()
66 }
67 s = requests.session()
68 r = s.request(method='get', url=url, headers=headers)
69 if r.status_code == 200:
70 print('正在抓取地址:%s' % url)
71 print('User-Agent:', r.request.headers.get('user-agent'))
72 return r.content
73 return None
78def download_videos(video_urls, opts):
79 """
80 Receives a list of URLs given in video_urls and a dictionary called opts
81 with the preferences made by the user and performs the actual download
82 of the videos with URLs with the options given in opts.
83 """
84 # FIXME: Create subdirectories for each lecture and name the files under
85 # those directories
86
87 cmd = ['youtube-dl', '-A']
88
89 if opts.format:
90 cmd.append('-f %d' % opts.format)
91 if opts.subtitles:
92 cmd.append('--write-srt')
93
94 cmd.extend(video_urls)
95
96 subprocess.call(cmd)
7def download(url):
8 wget.download(url)
87@utils.url_dispatcher.register('252', ['url', 'name'], ['download'])
88def Playvid(url, name, download=None):
89 if utils.addon.getSetting("paradisehill") == "true": playall = True
90 else: playall = ''
91 videopage = utils.getHtml(url, '')
92
93 match0 = re.compile('<div class="fp-playlist">(.+?)</div>', re.DOTALL | re.IGNORECASE).findall(videopage)[0]
94 match = re.compile('<a href="(.+?)">', re.DOTALL | re.IGNORECASE).findall(match0)
95 videos = match
96
97 if playall == '':
98 if len(videos) > 1:
99 i = 1
100 videolist = []
101 for x in videos:
102 videolist.append('Part ' + str(i))
103 i += 1
104 videopart = dialog.select('Multiple videos found', videolist)
105 if videopart == -1:
106 return
107 videourl = videos[videopart]
108 else: videourl = videos[0]
109 videourl = videourl.replace('\/','/')
110 videourl = "https:" + videourl
111
112 if download == 1 and playall == '':
113 utils.downloadVideo(videourl, name)
114 else:
115 iconimage = xbmc.getInfoImage("ListItem.Thumb")
116
117 if playall:
118 pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
119 pl.clear()
120 i = 1
121 for videourl in videos:
122 newname = name + ' Part ' + str(i)
123 listitem = xbmcgui.ListItem(newname, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
124 listitem.setInfo('video', {'Title': newname, 'Genre': 'Porn'})
125 listitem.setProperty("IsPlayable","true")
126 videourl = videourl + "|referer="+ url
127 pl.add(videourl, listitem)
128 i += 1
129 listitem = ''
130 xbmc.Player().play(pl)
131 else:
132 xbmc.Player().play(str(videourl))
36def download_videos(dest_dir=SOURCE_VIDEOS_DIR):
37 for vid_data in PAPER_REPLICATION_VALUES:
38 name = vid_data[0]
39 source_filename = name + '.mp4'
40 os.makedirs(dest_dir, exist_ok=True)
41 dest_filename = os.path.join(dest_dir, source_filename)
42 download_file('http://people.csail.mit.edu/mrub/evm/video/' + source_filename, dest_filename)
67@utils.url_dispatcher.register('802', ['url', 'name'], ['download'])
68def Playvid(url, name, download=None):
69 links = {}
70 vp = utils.VideoPlayer(name, download)
71 vp.progress.update(25, "", "Loading video page", "")
72 html = utils.getHtml(url)
73# html = re.compile('<center><!-- Display player -->(.+?)<center>', re.DOTALL | re.IGNORECASE).findall(videopage)[0]
74 srcs = re.compile('<a title="([^"]+)" href="([^"]+)"', re.DOTALL | re.IGNORECASE).findall(html)
75 for title, src in srcs:
76 title = title.replace(name.split("[",1)[0],'').replace(' on','')
77 if '/goto/' in src:
78 src = url_decode(src)
79 if vp.resolveurl.HostedMediaFile(src):
80 links[title] = src
81 if 'mangovideo' in src:
82 title = title.replace(' - ','')
83 html = utils.getHtml(src)
84 match = re.compile("video_url:\s*'([^']+)'", re.DOTALL | re.IGNORECASE).findall(html)[0]
85 links[title] = match
86 videourl = utils.selector('Select server', links, dont_ask_valid=False, reverse=True)
87 if not videourl:
88 return
89 vp.progress.update(90, "", "Loading video page", "")
90 if 'mango' in videourl:
91 vp.direct_regex = '(' + re.escape(videourl) + ')'
92 vp.play_from_html(html)
93 else:
94 vp.play_from_link_to_resolve(videourl)
49def download_urls(urls=None, title=None, ext=None, total_size=None, refer=None):
50 ve = last_info
51 if not ve:
52 ve = VideoExtractor()
53 ve.name = ''
54 ve.url = urls
55 ve.title=title
56 # save download info in streams
57 stream = {}
58 stream['container'] = ext
59 stream['size'] = total_size
60 stream['src'] = urls
61 if refer:
62 stream['refer'] = refer
63 stream['video_profile'] = '__default__'
64 ve.streams = {}
65 ve.streams['__default__'] = stream
66 output(ve)

Related snippets