-1

I am trying to download a youtube video using python.Below is my code.But it is giving me ValueError: Attempted relative import in non-package.Can anyone help me solving this issue.I am new to python ...Someone please help

  import pafy
  url = raw_input("https://www.youtube.com/watch?v=PT2_F-1esPk")
  video = pafy.new(url)
  t= video.title
  r = video.rating
  print t
  print r
  best = video.getbest("mp4")
  filename = best.download(quiet = False)
lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
Sharmili Nag
  • 663
  • 2
  • 8
  • 10
  • I don't know that this is allowed. Also, please format code properly. –  Nov 15 '16 at 00:00

1 Answers1

0

Instead of

url = raw_input("https://www.youtube.com/watch?v=PT2_F-1esPk")
video = pafy.new(url)

Just do

video = pafy.new("PT2_F-1esPk")

Initialize the video with the 11 digit id. raw_input gives back an empty string.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Manali
  • 226
  • 1
  • 4
  • from __future__ import unicode_literals import youtube_dl import urllib import shutil ydl_opts = {} with youtube_dl.YoutubeDL(ydl_opts) as ydl: ydl.download(['https://www.youtube.com/watch?v=PT2_F-1esPk']) – Sharmili Nag Nov 18 '16 at 07:24