Пример #1
0
 def download(self, download_path: str = "downloads"):
     # TODO: Add creating folders if not exist
     videos = [
         "https://www.cda.pl/video/2486267d4",
         "https://www.cda.pl/video/248630943",
         "https://www.cda.pl/video/250105452",
         "https://www.cda.pl/video/2518128a9",
         "https://www.cda.pl/video/2531640cb",
         "https://www.cda.pl/video/2546847e8",
         "https://www.cda.pl/video/256809044",
         "https://www.cda.pl/video/2583666bd",
         "https://www.cda.pl/video/25999076f",
         "https://www.cda.pl/video/261542952",
         "https://www.cda.pl/video/2652516eb",
         "https://www.cda.pl/video/2671470a4",
         "https://www.cda.pl/video/3424375c3",
         "https://www.cda.pl/video/3443971c3",
         "https://www.cda.pl/video/3463282e8",
         "https://www.cda.pl/video/3485605e6",
         "https://www.cda.pl/video/351312746",
         "https://www.cda.pl/video/35377301f",
         "https://www.cda.pl/video/35612772a",
         "https://www.cda.pl/video/358452193",
         "https://www.cda.pl/video/360697930",
         "https://www.cda.pl/video/362523795"
     ]
     for url in videos:
         video = Video(url)
         print(url)
         video.download(download_path)
Пример #2
0
 def parse_splash(self, response):
     for li in Selector(text=response.body).xpath('//ol[@class = "playlist-videos-list yt-uix-scroller yt-viewport"]/li').extract():
         img_url = Selector(text=li).xpath('//img/@data-thumb').extract_first()
         if img_url:
             img_src = img_url.split('&rs')[0] + '&rs' + img_url.split('&rs')[1]
         else:
             img_url = Selector(text=li).xpath('//img/@src').extract_first()
             img_src = img_url.split('&rs')[0] + '&rs' + img_url.split('&rs')[1]
         href = 'https://youtube.com' + Selector(text=li).xpath('//a/@href').extract_first()
         title = Selector(text=li).xpath('//h4 [@class = "yt-ui-ellipsis yt-ui-ellipsis-2"]/text()').extract_first().strip()
         try:
             v = Video.get(title=title)
         except Exception as e:
             print(e)
             exit(1)
         if not v:
             try:
                 v = Video(title=title, url=href, img_src=img_src, img_thumb=img_url)
                 v.save(self.download_path)
                 if self.vDownload:
                     v.download(self.vPath)
             except Exception as e:
                 print(e)
                 exit(1)
         send_message('/tmp/url_pipe', href)
         yield {
                 'title': title,
                 'url': href,
                 'img_src': img_src,
                 'img_thumb': img_url
             }
Пример #3
0
 def parse(self, response):
     for vid in Selector(text=response.body).xpath(
             '//ytd-grid-video-renderer[@class="style-scope ytd-grid-renderer use-ellipsis"]'
     ).extract():
         duration = Selector(text=vid).xpath(
             '//span[@class="style-scope ytd-thumbnail-overlay-time-status-renderer"]/text()'
         ).extract_first().strip()
         href = 'https://youtube.com' + Selector(
             text=vid).xpath('//a[@id="thumbnail"]/@href').extract_first()
         title = Selector(text=vid).xpath(
             '//a[@id="video-title"]/text()').extract_first()
         views = int(
             Selector(text=vid).xpath('//a[@id="video-title"]/@aria-label').
             extract_first().split()[-2].replace(',', ''))
         img_thumb = Selector(text=vid).xpath('//img/@src').extract_first()
         img_src = None
         if img_thumb:
             img_src = img_thumb.split(
                 '?sqp')[0] + '?amp;sqp' + img_thumb.split('?sqp')[1]
         v = Video.get(title=title)
         if v:
             v.update(views=views, duration=duration)
         else:
             v = Video(title, href, img_src, img_thumb, views, duration)
             v.save(self.download_path)
             if self.vDownload:
                 v.download(self.vPath)
Пример #4
0
def main(args):
  """
    Mainline of application
  """
  
  config = config_from_args(args)
  
  if config.single['id'] != '':
    id = int(config.single['id'])
    v = Video(config, id)
    s = SubtitleV4(config, id)
    filename = '%s.srt' % (os.path.basename(v.video_url()))
    s.download(filename)
    v.download()
  elif config.search['query'] == default_config.search['query']:
    print 'Please specify a query. Example: "--search-query=Queen Seon Deok"'
    sys.exit(1)
  else:
    searcher = ChannelSearcher(config)
    channels = searcher.search(config.search['query'], config.search['method'])
    
    for channel in channels:
      sys.stdout.write('Channel: %s\n' %(channel.name))
      for episode in channel.episodes():
        sys.stdout.write('Episode: %s\n' % (episode.episode_num))
        media_id = episode.media_id
        
        video = Video(config, media_id)
        if not config.video['skip']:
          video.download()
        
        video_info = video.video_info()
        
        filename = video.filename()
        
        # remove the extension
        filename = os.path.splitext(filename)[0]
        
        if config.subtitles['check_parts']:
          # videos that have multiple subtitle parts will need
          # to have them downloaded separately and merged
          parts = VideoParts(config, episode.full_url).parts()
          first = True
          start_index = 0
          for part in parts:
            start_time = int(part['part_info']['start_time'])
            subtitle = Subtitle(config, part['media_resource_id'], start_index, start_time)
            if first:
              subtitle.download(filename)
              first = False
            else:
              subtitle.merge(filename)
            start_index = subtitle.end_index
        else:
          media_resource_id = video.media_resource(video_info)
          subtitle = Subtitle(config, media_resource_id)
          subtitle.download(filename)
Пример #5
0
    def process_screen(self):
        """Method for process current screen. Form handling, initialize necessary classes, etc"""

        # If it is simple menu-type screen, just listen keyboard to switch screen
        if self.name in self.menu_map.keys():
            self.set_next_screen()

            # If download directory is not given, user have to do it
        elif self.name == 'force_download_path' or self.name == 'force_download_path_invalid':
            path = input()
            if self.path.is_valid(path):
                self.path.write(path)
                self.next = 'force_download_path_valid'
            else:
                self.next = 'force_download_path_invalid'

        # If user want to change download directory, use this code
        elif self.name == 'set_download_path_input' or self.name == 'set_download_path_invalid':
            path = input()
            if path == '':
                self.next = 'main_menu'
            else:
                if self.path.is_valid(path):
                    self.path.write(path)
                    self.next = 'set_download_path_valid'
                else:
                    self.next = 'set_download_path_invalid'
        elif self.name == 'set_download_path_valid':
            time.sleep(2)
            self.next = 'main_menu'

        # If user want to download file from yt, use this code:
        elif self.name == 'video_menu' or self.name == 'video_invalid':
            link = input()
            if link == '': self.next = 'main_menu'
            else:
                video = Video(link)
                if video.link_is_correct:
                    video.download(self.path.read())
                    self.next = 'video_valid'
                else:
                    self.next = 'video_invalid'
        elif self.name == 'mp3_menu' or self.name == 'mp3_invalid':
            link = input()
            if link == '': self.next = 'main_menu'
            else:
                video = Video(link)
                if video.link_is_correct:
                    video.download(self.path.read(), as_mp3=True)
                    self.next = 'mp3_valid'
                else:
                    self.next = 'mp3_invalid'

        elif self.name == 'channel_menu':
            # TODO: Create channel menu for full channel download
            self.next = 'main_menu'
Пример #6
0
 def download(self, filename, path=None):
     if not path:
         path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     resp = self.get_video_data()
     url_data = resp['args']['stream_map']
     d = defaultdict(object)
     urls = url_data['url']
     url = urls[0]
     v = Video(url, filename)
     v.download(path)
Пример #7
0
	def download_click(self):
		artist = self.artist_entry.get()
		song = self.song_entry.get()
		string = artist + ' ' + song
		popup = self.popup()
		popup.update_idletasks()
		popup.update()
		video = Video(self.choice, string)
		video.search(popup)
		popup = self.popup()
		while True:
			popup.update_idletasks()
			popup.update()
			video.download()
			popup.destroy()
Пример #8
0
def index():
    form = DownloadForm()
    link = form.link.data
    if form.validate_on_submit():
        video = Video(link)
        if video.vadlidate_link():
            video.download()
            flash('Video downloaded successfully:👍')
        else:
            flash(
                'Error occurred while downloading video. Maybe link is invalid🤔'
            )

        return redirect(url_for('index'))

    return render_template('index.html', form=form)
Пример #9
0
"""
  Viki.com
    Flash video downloader
    
  Hekar Khani 2012
"""

import os
from config import default_config
from video import Video
from subtitles import SubtitleV4

if __name__ == '__main__':
  media_id = 1042610
  c = default_config
  v = Video(c, media_id)
  s = SubtitleV4(c, media_id)

  filename = '%s.srt' % (os.path.basename(v.video_url()))
  s.download(filename)
  v.download()