예제 #1
0
def download_youtube_sample(source_url: str) -> AudioSample:
    "Download and transcode a YouTube video to audio."
    if is_short_url(source_url):
        short_url = source_url
        source_url = get_origin_url(short_url)

    metadata = fetch_youtube_metadata(source_url)

    t = tempfile.NamedTemporaryFile(delete=False, suffix='.mp3')

    output_template = os.path.splitext(t.name)[0] + '.%(ext)s'
    youtube_dl('-x', '--audio-format=mp3',
               '--output={}'.format(output_template), source_url)

    return AudioSample(tempfile=t, metadata=metadata)
예제 #2
0
def download_youtube_sample(source_url: str) -> AudioSample:
    "Download and transcode a YouTube video to audio."
    if is_short_url(source_url):
        short_url = source_url
        source_url = get_origin_url(short_url)

    metadata = fetch_youtube_metadata(source_url)

    t = tempfile.NamedTemporaryFile(delete=False, suffix='.mp3')

    output_template = os.path.splitext(t.name)[0] + '.%(ext)s'
    youtube_dl('-x', '--audio-format=mp3', '--output={}'.format(output_template),
               source_url)

    return AudioSample(tempfile=t, metadata=metadata)
예제 #3
0
 def getVideo(self, in_url):
     stdout = youtube_dl('-v', '-4', '--add-metadata',
                         '--restrict-filename', in_url)
     prefix = "[ffmpeg] Merging formats into "
     out_file = self.get_filename(stdout,
                                  prefix)[1:-1]  # strip quotes in filename
     return stackhut.put_file(out_file)
예제 #4
0
 def check_exists(self, url):
     try:
         url = youtube_dl(url, g=True)
         if url.startswith("http"):
             return True
     except pbs.ErrorReturnCode_1:
         pass
     return False
예제 #5
0
    def resolve_format(self, url):
        self.log.info("Trying to resolve %s" % url)

        # if it's a YouTube video, we have to find the best quality video
        if self.youtube_url.match(url):
            for format in self.youtube_formats:
                self.log.debug("Trying %s with format %d" % (url, format))
                try:
                    url = youtube_dl(url, g=True, format=format)
                    if url.startswith("http"):
                        return format
                except pbs.ErrorReturnCode_1:
                    pass
            raise IOError("Failed to resolve format for %s" % url)

        # otherwise just check it if exists
        else:
            try:
                url = youtube_dl(url, g=True)
                if url.startswith("http"):
                    return None
            except pbs.ErrorReturnCode_1:
                pass
            raise IOError("Failed to resolve format for %s" % url)
예제 #6
0
def main(url):
    opts, args = parse_args()

    if "youtube.com" not in url:
        sh.mplayer("/usr/share/sounds/freedesktop/stereo/message.oga")
        return "%r is not a valid youtube url." % url

    notify("Grabbing %r" % url)
    prefix = os.path.expanduser("~/Music/youtube")

    if not os.path.exists(prefix):
        os.makedirs(prefix)

    location = "%s/%%(stitle)s.%%(ext)s" % prefix
    output = sh.youtube_dl(
        url,
        extract_audio=True,
        audio_format="mp3",
        output=location,
    )
    # Just report on the last line of text..
    output = unicode(output).strip().split('\n')[-1]
    sh.mplayer("/usr/share/sounds/freedesktop/stereo/complete.oga")
    return output
예제 #7
0
 def getAudio(self, in_url):
     stdout = youtube_dl('-v', '-4', '-x', '--add-metadata', '--restrict-filename', in_url)
     prefix = "[download] Destination: "
     out_file = self.get_filename(stdout, prefix)
     return stackhut.put_file(out_file)
예제 #8
0
 def getVideo(self, in_url):
     stdout = youtube_dl('-v', '-4', '--add-metadata', '--restrict-filename', in_url)
     prefix = "[ffmpeg] Merging formats into "
     out_file = self.get_filename(stdout, prefix)[1:-1] # strip quotes in filename
     return stackhut.put_file(out_file)
예제 #9
0
def download_audio(url, target_dir):
    output = os.path.join(target_dir, r'%(title)s.%(ext)s')
    # Execute in subprocess; youtube_dl dies after the first download completes
    output = sh.youtube_dl(url, output=output)
    # Report last line of output
    print unicode(output).strip().split('\n')[-1]
예제 #10
0
c.Search = search
c.Hide_output = True
c.Store_object = True
c.Store_object_tweets_list = tweets

# Run
twint.run.Search(c)

# Extract link from every tweet
capture_pattern = r'(https\:\/\/.*)'
links = []

# Pass if tweet has no link
for tweet in tweets:
    try:
        link = re.search(capture_pattern, tweet.tweet)
        links.append(link.group())
    except:
        pass

# Delete duplicated links
video_links = list(dict.fromkeys(links))

# Download videos using youtube-dl flags
open(archive, "a").close()

for link in video_links:
    print("Downloading link: " + link)
    sh.youtube_dl("-o",
                  download_dir + "Informativo_matinal_%(upload_date)s.%(ext)s",
                  "--download-archive", archive, link)  # pylint: disable=no-member
예제 #11
0
 def getAudio(self, in_url):
     stdout = youtube_dl('-v', '-4', '-x', '--add-metadata',
                         '--restrict-filename', in_url)
     prefix = "[download] Destination: "
     out_file = self.get_filename(stdout, prefix)
     return stackhut.put_file(out_file)