import cache
import network
import scraper
import urllib

YTS_URL = 'http://yts.re'

################################################################################
def movie(movie_info):
    magnet_infos = []

    json_data = network.json_get_cached_optional(YTS_URL + '/api/v2/list_movies.json', expiration=cache.HOUR, params={ 'query_term': movie_info['imdb_id'] })
    if 'data' in json_data:
        if 'movies' in json_data['data']:
            for movie_item in json_data['data']['movies']:
                if 'imdb_code' in movie_item and movie_item['imdb_code'] == movie_info['imdb_id'] and 'torrents' in movie_item:
                    for torrent_item in movie_item['torrents']:
                        magnet_title = '{0} ({1}) {2} - YIFY'.format(movie_item['title'], movie_item['year'], torrent_item['quality'])
                        magnet_url   = 'magnet:?xt=urn:btih:{0}&dn={1}&tr=http://exodus.desync.com:6969/announce&tr=udp://tracker.openbittorrent.com:80/announce&tr=udp://open.demonii.com:1337/announce&tr=udp://exodus.desync.com:6969/announce&tr=udp://tracker.yify-torrents.com/announce'.format(torrent_item['hash'], urllib.quote(magnet_title))
                        magnet_infos.append(scraper.Magnet(magnet_url, None, torrent_item['seeds'], torrent_item['peers']))

    return magnet_infos

import cache
import network
import scraper

YTS_URL = 'http://yts.re'

################################################################################
def movie(movie_info):
    magnet_infos = []

    json_data = network.json_get_cached_optional(YTS_URL + '/api/listimdb.json', expiration=cache.HOUR, params={ 'imdb_id': movie_info['imdb_id'] })
    if 'MovieList' in json_data:
        for json_item in json_data['MovieList']:
            title = '{0} ({1}) {2} - YIFY'.format(json_item['MovieTitleClean'], json_item['MovieYear'], json_item['Quality'])
            magnet_infos.append(scraper.Magnet(json_item['TorrentMagnetUrl'], title, int(json_item['TorrentSeeds']), int(json_item['TorrentPeers'])))

    return magnet_infos

--- 
+++ 
@@ -1,6 +1,7 @@
 import cache
 import network
 import scraper
+import urllib
 
 YTS_URL = 'http://yts.re'
 
@@ -8,10 +9,14 @@
 def movie(movie_info):
     magnet_infos = []
 
-    json_data = network.json_get_cached_optional(YTS_URL + '/api/listimdb.json', expiration=cache.HOUR, params={ 'imdb_id': movie_info['imdb_id'] })
-    if 'MovieList' in json_data:
-        for json_item in json_data['MovieList']:
-            title = '{0} ({1}) {2} - YIFY'.format(json_item['MovieTitleClean'], json_item['MovieYear'], json_item['Quality'])
-            magnet_infos.append(scraper.Magnet(json_item['TorrentMagnetUrl'], title, int(json_item['TorrentSeeds']), int(json_item['TorrentPeers'])))
+    json_data = network.json_get_cached_optional(YTS_URL + '/api/v2/list_movies.json', expiration=cache.HOUR, params={ 'query_term': movie_info['imdb_id'] })
+    if 'data' in json_data:
+        if 'movies' in json_data['data']:
+            for movie_item in json_data['data']['movies']:
+                if 'imdb_code' in movie_item and movie_item['imdb_code'] == movie_info['imdb_id'] and 'torrents' in movie_item:
+                    for torrent_item in movie_item['torrents']:
+                        magnet_title = '{0} ({1}) {2} - YIFY'.format(movie_item['title'], movie_item['year'], torrent_item['quality'])
+                        magnet_url   = 'magnet:?xt=urn:btih:{0}&dn={1}&tr=http://exodus.desync.com:6969/announce&tr=udp://tracker.openbittorrent.com:80/announce&tr=udp://open.demonii.com:1337/announce&tr=udp://exodus.desync.com:6969/announce&tr=udp://tracker.yify-torrents.com/announce'.format(torrent_item['hash'], urllib.quote(magnet_title))
+                        magnet_infos.append(scraper.Magnet(magnet_url, None, torrent_item['seeds'], torrent_item['peers']))
 
     return magnet_infos
Upgrade YTS to API v2
