mps-youtube / yewtube

yewtube, forked from mps-youtube , is a Terminal based YouTube player and downloader. No Youtube API key required.
GNU General Public License v3.0
8.01k stars 643 forks source link

Search don’t display results #254

Closed Sandlayth closed 9 years ago

Sandlayth commented 9 years ago

When I search a video, one result appear : 1 https://youtube.com/devicesupport 03:56 But playlists research displays well.

guaraqe commented 9 years ago

It is related to this issue with pafy, which is used by mps-youtube to get the search results, and it is due to an API change by YouTube. https://github.com/np1/pafy/issues/78 Also: https://github.com/np1/mps-youtube/issues/249

dabn commented 9 years ago

Oh, this is a sad day. So, guess I am going back to watching youtube on youtube.com with double the cpu workload again. My battery life will be crippled.

Sandlayth commented 9 years ago

I think I mispoke. This result is the uniq one, regardless of the query

RobertoGongora commented 9 years ago

This is due to the API being deprecated :(

ids1024 commented 9 years ago

I have created a branch with a very incomplete search functionality based on gdata 3: https://github.com/ids1024/mps-youtube/tree/gdata3wip

Currently it only can display page one of results and all videos appear to have a length of 20 sec. It is probably a bad idea to try to add a video to a playlist on this branch, because it will save the wrong metadata. Caveat emptor.

lol768 commented 9 years ago

Nice work, @ids1024. I know it's not grabbing all the data yet but it's neat how few changes to the existing codebase were required to get it to show a page of results. It seems pretty snappy too.

It unfortunately looks like you can't request the "contentDetails" part along with a search request, so there's no way to get information about the duration etc without at least one additional HTTP requests. Maybe YouTube could add this.

I believe I'm correct in stating you can only get the following info for each video via the search endpoint, which doesn't seem like too much:

{
   "snippet":{
      "publishedAt":"2014-02-12T21:01:24.000Z",
      "channelId":"UCJ6td3C9QlPO9O_J5dF4ZzA",
      "title":"[Happy Hardcore] - nanobii - Rainbow Road [Monstercat Release]",
      "description":"Support on Beatport: http://monster.cat/1gqSVQY Support on Bandcamp: http://monster.cat/1eUyTym Support on iTunes: http://monster.cat/1g2TwX9 --- Listen on ...",
      "thumbnails":{
         "default":{
            "url":"https://i.ytimg.com/vi/a0Aauep0VWs/default.jpg"
         },
         "medium":{
            "url":"https://i.ytimg.com/vi/a0Aauep0VWs/mqdefault.jpg"
         },
         "high":{
            "url":"https://i.ytimg.com/vi/a0Aauep0VWs/hqdefault.jpg"
         }
      },
      "channelTitle":"MonstercatMedia",
      "liveBroadcastContent":"none"
   }
}

Having a look at the quota, using the same key for the whole application would allow approximately 1500 daily users who perform an average of 50 searches and look through a couple of pages of data (using 100 + 5 per video units per page of results, 100 for search + 5 for each video for which duration/extra data is retrieved with an assumption of 30 videos per page and each user flicking through 5 pages or so of data).

JKatzwinkel commented 9 years ago

Having missed the previous update by @ids1024, I also made some changes to get at least the standard search to work with the new API. Just like the solution by @ids1024 , it is currently limited to the first page of search results, but since I am in fact making the additional HTTP request @lol768 was concerned with, track durations are obtained correctly.

Edit: sorry, forgot to link the commit: JKatzwinkel/mps-youtube@42bc06374488c645f7ca23e6757f73eb33a965f6

lol768 commented 9 years ago

@JKatzwinkel

Good to see that you can use the videos endpoint to grab that extra info though it's annoying it's not included in the search items.


I had a look at grabbing channel uploads. The easiest way I can see of doing this is:

Step 1: GET request to https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=monstercatmedia&fields=items%2FcontentDetails

Returns:

{
 "items": [
  {
   "contentDetails": {
    "relatedPlaylists": {
     "likes": "LLJ6td3C9QlPO9O_J5dF4ZzA",
     "favorites": "FLJ6td3C9QlPO9O_J5dF4ZzA",
     "uploads": "UUJ6td3C9QlPO9O_J5dF4ZzA"
    },
    "googlePlusUserId": "109256493672759116762"
   }
  }
 ]
}

Step 2: GET request to https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails%2Csnippet&playlistId=UUJ6td3C9QlPO9O_J5dF4ZzA

Returns (truncated to only show one item):

{
 "kind": "youtube#playlistItemListResponse",
 "etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/fgpGhgiWmwxeuQXhdDg_uqZsC1Q\"",
 "nextPageToken": "CDIQAA",
 "pageInfo": {
  "totalResults": 650,
  "resultsPerPage": 50
 },
 "items": [
  {
   "kind": "youtube#playlistItem",
   "etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/UsP9M4B4N4xIf5FuiPXUQ3rBcSQ\"",
   "id": "UUTIu2cnPopwhu13Y42miXAL1EP_jSpAy0",
   "snippet": {
    "publishedAt": "2015-05-08T05:27:37.000Z",
    "channelId": "UCJ6td3C9QlPO9O_J5dF4ZzA",
    "title": "[Trance] - Trivecta - Evaporate (feat. Aloma Steele) [Monstercat Release]",
    "description": "Support on iTunes: http://monster.cat/1EovKiV\nSupport on Beatport: http://monster.cat/1zKsUZV\nSupport on Bandcamp: http://monster.cat/1KqNrD6\n---\nListen on SoundCloud: http://monster.cat/1KRT91H\nListen on Spotify: http://monster.cat/1GTKBUb\n\n▼ Follow Monstercat\nYouTube: http://www.youtube.com/Monstercat\nSpotify: http://monster.cat/1hGrCWk\nFacebook: http://facebook.com/Monstercat\nTwitter: http://twitter.com/Monstercat\nInstagram: http://instagram.com/monstercat\nVine: https://vine.co/monstercat\nSoundCloud: http://soundcloud.com/Monstercat\nGoogle+: https://plus.google.com/+Monstercat\nMonstercat FM: http://live.monstercat.com\n\n▼ Follow Trivecta\nFacebook: http://facebook.com/trivectamusic\nTwitter: http://twitter.com/trivectamusic\nSoundcloud: http://soundcloud.com/trivectamusic\nYoutube: http://www.youtube.com/trivectamusic\n\n▼ Follow Aloma Steele\nFacebook: http://www.facebook.com/alomasteele\nTwitter: http://twitter.com/AlomaSteele \nSoundcloud: http://soundcloud.com/alomasteele \nYoutube: http://www.youtube.com/user/LomaTherapy\nInstagram: https://instagram.com/alomasteele\n\n▼ Want some new Merchandise?\nhttp://monster.cat/MonstercatShop\n-----------------------------------\nWant to use this song in your own videos? Please go to: http://monster.cat/YouTube_License",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/1eXGv_wa7DE/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/1eXGv_wa7DE/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/1eXGv_wa7DE/hqdefault.jpg",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "https://i.ytimg.com/vi/1eXGv_wa7DE/sddefault.jpg",
      "width": 640,
      "height": 480
     }
    },
    "channelTitle": "Monstercat",
    "playlistId": "UUJ6td3C9QlPO9O_J5dF4ZzA",
    "position": 0,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "1eXGv_wa7DE"
    }
   },
   "contentDetails": {
    "videoId": "1eXGv_wa7DE"
   }

Step 3: GET request to https://www.googleapis.com/youtube/v3/videos to get the duration of the videos (see above comments).

Three HTTP requests - not sure if anyone can get lower than that? I think you could probably get it in one if you scraped :P

JKatzwinkel commented 9 years ago

Thanks for the advice and for placing confidence in my skills, @lol768 , but I have so far failed to find a way with less requests involved. I have in fact come up with nearly the same queries as you are suggesting, even though yours seem to yield more compact responses. What is best practice regarding the API key issue btw? Should users be expected to provide their own key? How would that look like? @ids1024 @np1 jkatzwinkel/mps-youtube@218925ef5c94e24e4612ef5ef6c263fc981dc5ab

ids1024 commented 9 years ago

Probably the app should provide an api key. I guess it should use the same key as pafy, which could be obtained by using pafy.api_key (after pafy is changed to use gdata v3, of course).

Requiring two requests is not too bad since it seems fairly fast. I didn't take the time to look at the api for that, and was concerned it would require a request for each video.

ids1024 commented 9 years ago

@JKatzwinkel Github is not recognizing your commits as yours since you do not have an actual email set up with git. This is not really an issue, but you should probably run git config --global user.email EMAIL_YOUR_GITHUB_ACCOUNT_USES. Or if you want to keep your email address private: https://help.github.com/articles/keeping-your-email-address-private/

laapsaap commented 9 years ago

This is seriously a big problem, my life is over. I wont be able to work until this is fixed, I cant risk opening youtube in a browser and risk being distracted!!

I appreciate the hard work on this problem. I run no windows manager, just Xterm + tmux, so mps-youtube is really essential ;) Thanks

ids1024 commented 9 years ago

@laapsaap Try using PR #256. It's incomplete, but a lot of the basic functionality seems to be working fine.

pdvyas commented 9 years ago

pip install --upgrade https://github.com/ids1024/mps-youtube/archive/gdata3wip.zip till it's merged

Thanks @ids1024 !!