Get title from YouTube videos

前端 未结 17 1923
抹茶落季
抹茶落季 2020-12-07 17:30

I want to extract the Title of YouTube\'s videos. How can I do this?

Thanks.

相关标签:
17条回答
  • 2020-12-07 17:42

    using python i got itimport pafy url = "https://www.youtube.com/watch?v=bMt47wvK6u0" video = pafy.new(url) print(video.title)

    0 讨论(0)
  • 2020-12-07 17:45
    // This is the youtube video URL: http://www.youtube.com/watch?v=nOHHta68DdU
    $code = "nOHHta68DdU";
    // Get video feed info (xml) from youtube, but only the title | http://php.net/manual/en/function.file-get-contents.php
    $video_feed = file_get_contents("http://gdata.youtube.com/feeds/api/videos?v=2&q=".$code."&max-results=1&fields=entry(title)&prettyprint=true");
    // xml to object | http://php.net/manual/en/function.simplexml-load-string.php
    $video_obj = simplexml_load_string($video_feed);
    // Get the title string to a variable
    $video_str = $video_obj->entry->title;
    // Output
    echo $video_str;
    
    0 讨论(0)
  • 2020-12-07 17:49

    If python batch processing script is appreciated: I used BeautifulSoup to easily parse the title from HTML, urllib to download the HTML and unicodecsv libraries in order to save all the characters from Youtube title.

    The only thing you need to do is to place csv with single (named) column url with URLs of the Youtube videos in the same folder as the script is and name it yt-urls.csv and run the script. You will get file yt-urls-titles.csv containing the URLs and its titles.

    #!/usr/bin/python
    
    from bs4 import BeautifulSoup
    import urllib
    import unicodecsv as csv
    
    with open('yt-urls-titles.csv', 'wb') as f:
        resultcsv = csv.DictWriter(f, delimiter=';', quotechar='"',fieldnames=['url','title'])
        with open('yt-urls.csv', 'rb') as f:
            inputcsv = csv.DictReader(f, delimiter=';', quotechar='"')
            resultcsv.writeheader()
            for row in inputcsv:
                soup = BeautifulSoup(urllib.urlopen(row['url']).read(), "html.parser")
                resultcsv.writerow({'url': row['url'],'title': soup.title.string})
    
    0 讨论(0)
  • 2020-12-07 17:50

    I believe the best way is to use youTube's gdata, and then grab info from XML that is returned

    http://gdata.youtube.com/feeds/api/videos/6_Ukfpsb8RI

    Update: There is a newer API out now which you should use instead

    https://developers.google.com/youtube/v3/getting-started

    URL: https://www.googleapis.com/youtube/v3/videos?id=7lCDEYXw3mM&key=YOUR_API_KEY
         &fields=items(id,snippet(channelId,title,categoryId),statistics)&part=snippet,statistics
    
    Description: This example modifies the fields parameter from example 3 so that in the API response, each video resource's snippet object only includes the channelId, title, and categoryId properties.
    
    API response:
    
    {
     "videos": [
      {
       "id": "7lCDEYXw3mM",
       "snippet": {
        "channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
        "title": "Google I/O 101: Q&A On Using Google APIs",
        "categoryId": "28"
       },
       "statistics": {
        "viewCount": "3057",
        "likeCount": "25",
        "dislikeCount": "0",
        "favoriteCount": "17",
        "commentCount": "12"
       }
      }
     ]
    }
    
    0 讨论(0)
  • 2020-12-07 17:50

    You can do using Json to get the all info about video

    $jsonURL = file_get_contents("https://www.googleapis.com/youtube/v3/videos?id={Your_Video_ID_Here}&key={Your_API_KEY}8&part=snippet");
    $json = json_decode($jsonURL);
    
    $vtitle = $json->{'items'}[0]->{'snippet'}->{'title'};
    $vdescription = $json->{'items'}[0]->{'snippet'}->{'description'};
    $vvid = $json->{'items'}[0]->{'id'};
    $vdate = $json->{'items'}[0]->{'snippet'}->{'publishedAt'};
    $vthumb = $json->{'items'}[0]->{'snippet'}->{'thumbnails'}->{'high'}->{'url'};
    

    I hope it will solve your problem.

    0 讨论(0)
  • 2020-12-07 17:54

    JavaX now ships with this function. Showing a video's thumbnail and title, for example, is a two-liner:

    SS map = youtubeVideoInfo("https://www.youtube.com/watch?v=4If_vFZdFTk"));
    showImage(map.get("title"), loadImage(map.get("thumbnail_url")));
    

    Example

    0 讨论(0)
提交回复
热议问题