Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 1ce5144e authored by SoleneDc's avatar SoleneDc

Merge remote-tracking branch 'origin/master'

parents f631aa01 f72f62e4
File added
......@@ -20,4 +20,4 @@ spectrumImages2014/
spectrumImages2015/
spectrumImages2016/
spectrumImages2017/
spectrumImages/
import requests
import datetime
import time
import ast
url = 'https://api.themoviedb.org/3/discover/movie?api_key=e4c6a6f5fbd60b0316b7ff30e73bec74&language=en-US&sort_by=popularity.desc&include_adult=false&include_video=false&'
......@@ -22,7 +22,7 @@ def get_movie_ids(year):
# movie_id = item['id']
# video_link = get_video_link(movie_id)
# dict_movies[movie_id] = [item['vote_average'], item["genre_ids"], video_link]
# f = open("./Link-dictionnaries/Link-dictionnary" + str(year) + ".txt", "w")
# f = open("./Link-dictionaries/Link-dictionary" + str(year) + ".txt", "w")
# f.write(str(dict_movies))
# f.close()
......@@ -38,7 +38,7 @@ def get_movie_ids(year):
video_link = get_video_link(movie_id)
if video_link != '':
dict_movies[movie_id] = [item['vote_average'], item["genre_ids"], video_link]
f = open("./Link-dictionnaries/Link-dictionnary" + str(year) + "-2.txt", "w")
f = open("./Link-dictionaries/Link-dictionary" + str(year) + "-2.txt", "w")
f.write(str(dict_movies))
f.close()
return dict_movies
......@@ -54,5 +54,34 @@ def get_video_link(movie_id):
return ''
# Helpers
def concatenate_dict():
path = "./Link-dictionaries/Link-dictionary2005-1.txt"
file = open(path, "r").read()
dictyear = ast.literal_eval(file)
print(len(dictyear))
path2 = "./Link-dictionaries/Link-dictionary2005-2.txt"
file2 = open(path2, "r").read()
dict2 = ast.literal_eval(file2)
print(len(dict2), 'dict2')
dictyear.update(dict2)
print(len(dictyear), 'new dictyear')
path3 = "./Link-dictionaries/Link-dictionary2005-3.txt"
file3 = open(path3, "r").read()
dict3 = ast.literal_eval(file3)
print(len(dict3))
dictyear.update(dict3)
print(len(dictyear))
f = open("./Link-dictionaries/Link-dictionary2005.txt", "w")
f.write(str(dictyear))
f.close()
return (dictyear)
concatenate_dict()
print(get_movie_ids(2010))
......@@ -50,6 +50,7 @@ def downloadTrailer(): #called by main()
'noplaylist': True,
'nocheckcertificate':True,
#'max_filesize' : 10000000,
"nocheckcertificate": True,
'save_path' : videoDir }
for key in linkDict.keys():
if not os.path.isfile(spectrumDir+linkDict[key][2]+'.jpg'):
......
import ast
import os
import cv2
#L = ['Sithad108Og.','fBNpSRtfIUA', '2e-eXJ6HgkQ', 'tN1A2mVnrOM', 'myTaigPrbsg', 'b75lZw8nkvo']
genres = [28, 35, 18, 99, 10749, 10752, 10402, 53, 878, 27, 9648, 80, 14, 12, 36, 10769, 16, 10751, 37, 10770]
list_of_eligible_spectrums = []
for file in os.listdir("SpectrumImages2005"):
if str(file)[-4:] == '.jpg':
list_of_eligible_spectrums += [file]
print(len(list_of_eligible_spectrums))
# def get_genre_from_link():
# path = "./Link-dictionaries/Link-dictionary2005.txt"
# file = open(path, "r").read()
# dictyear = ast.literal_eval(file)
# dict_inverse = {}
# links_to_be_removed = []
# for movie_id in dictyear.keys():
# if dictyear[movie_id][1] != []:
# dict_inverse[str(dictyear[movie_id][2])] = {}
# for genre in genres:
# if genre in dictyear[movie_id][1]:
# dict_inverse[str(dictyear[movie_id][2])][genre] = 1
# else:
# dict_inverse[str(dictyear[movie_id][2])][genre] = 0
# else:
# #print(f'careful, link {dictyear[movie_id][2]} needs to be removed from the list')
# links_to_be_removed += [dictyear[movie_id][2]]
# return dict_inverse, links_to_be_removed
#
#
# def get_output_list(L):
# dict_inverse, links_to_be_removed = get_genre_from_link()
# eligible_links = []
# output = []
# for link in L:
# link = str(link)
# #print(dict_inverse[str(link)])
# if link[-1] == ".":
# print("do something! Too many points.......")
# if link[:-4] not in links_to_be_removed:
# output += [dict_inverse[link[:-4]]]
# eligible_links += [link]
# return output, eligible_links
# labels, eligible_links = get_output_list(list_of_eligible_spectrums)
def get_genre_from_link():
path = "./Link-dictionnaries/Link-dictionnary2000.txt"
path = "./Link-dictionaries/Link-dictionary2005.txt"
file = open(path, "r").read()
dictyear = ast.literal_eval(file)
dict_inverse = {}
links_to_be_removed = []
for movie_id in dictyear.keys():
if dictyear[movie_id][1] != []:
dict_inverse[dictyear[movie_id][2]] = dictyear[movie_id][1][0]
dict_inverse[str(dictyear[movie_id][2])] = {}
for genre in genres:
if genre in dictyear[movie_id][1]:
dict_inverse[str(dictyear[movie_id][2])][genre] = 1
else:
dict_inverse[str(dictyear[movie_id][2])][genre] = 0
else:
print(f'careful, link {dictyear[movie_id][2]} needs to be removed from the list')
#print(f'careful, link {dictyear[movie_id][2]} needs to be removed from the list')
links_to_be_removed += [dictyear[movie_id][2]]
return dict_inverse, links_to_be_removed
def get_output_list(L):
dict_inverse, links_to_be_removed = get_genre_from_link()
eligible_links = []
output = []
for link in L:
if link in links_to_be_removed:
L.remove(link)
else:
output += [dict_inverse[link]]
return output
link = str(link)
#print(dict_inverse[str(link)])
if link[-1] == ".":
print("do something! Too many points.......")
if link[:-4] not in links_to_be_removed:
eligible_links += [link[:-4]]
return dict_inverse, eligible_links
dict_inverse, eligible_links = get_output_list(list_of_eligible_spectrums)
for file in eligible_links:
img = cv2.imread('SpectrumImages2005/' + file + '.jpg', 1)
img = img[0:1]
img = img.reshape((img.shape[1], img.shape[2]))
dict_inverse[file]['image'] += [img]
print(get_output_list(L))
\ No newline at end of file
print('coucocu')
This diff is collapsed.
{212858: [0, [27, 35], 'oXh2Z9y7860'], 326629: [0, [99], 'AOHmvL5KeXw'], 80434: [0, [], 'nH11YWwIuVI'], 292550: [0, [18], 'uF0baKF1SIc'], 183579: [0, [], 'Qy8fwFj4Fg4'], 463703: [0, [10402, 35], 'RNqQPcMYcG8'], 444333: [0, [28, 18], 'FHai0cFFLPA'], 213814: [0, [27, 10749, 35], 'nn2M-m6wkJ4'], 439037: [0, [99], 'YTCiNyHc2tA'], 87618: [0, [35, 28], 'ZnwsKK-bcNk'], 221663: [0, [10402], 'tZQ3cUiQGD4'], 472185: [0, [35, 27], 'N6ibLbbfqj4'], 244303: [0, [18], 'Bv8XqGrenWQ'], 185201: [0, [10402, 99], 'oV0EZvG_oHs'], 372771: [0, [99], 'ut9dIOsptI8'], 444992: [0, [10402], '3ieows2KADQ']}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
import cv2
import os
def valid_spectrums():
def valid_spectrums(path):
ok_files = []
for file in os.listdir("Spectrums_sample"):
img = cv2.imread('./Spectrums_sample/' + file, 1)
image = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
length, width, lab = image.shape
colors = []
for i in range(width):
tuple = (image[0][i][0], image[0][i][1], image[0][i][2])
if tuple not in colors:
colors += [tuple]
if len(colors) >= 10:
ok_files += [file]
break
f = open("spectrums_to_keep.txt", "w")
f.write(str(ok_files))
f.close()
for file in os.listdir(path):
if str(file)[-4:] == '.jpg':
print(file)
img = cv2.imread('./'+ path + '/' + file, 1)
image = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
length, width, lab = image.shape
colors = []
for i in range(width):
tuple = (image[0][i][0], image[0][i][1], image[0][i][2])
if tuple not in colors:
colors += [tuple]
if len(colors) >= 10:
ok_files += [file]
break
print(valid_spectrums())
for file in os.listdir(path):
if file not in ok_files:
print('removing', file, '....')
os.remove(path + "/" + file)
print(ok_files)
print(valid_spectrums('spectrumImages2005'))
......@@ -70,7 +70,9 @@
{
"cell_type": "code",
"execution_count": 118,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#!/usr/bin/python\n",
......@@ -328,7 +330,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
......@@ -349,7 +353,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.6.3"
}
},
"nbformat": 4,
......
......@@ -6,7 +6,7 @@ url = "https://api.themoviedb.org/3/genre/movie/list?"
API = 'api_key=a9075982d1f7ce05cc45adec0e5f5358&language=en-US'
def get_genres(year):
path = "./Link-dictionnaries/Link-dictionnary" + str(year) +".txt"
path = "./Link-dictionaries/Link-dictionary" + str(year) +".txt"
file = open(path, "r").read()
dictyear = ast.literal_eval(file)
dict_genres = {}
......@@ -27,6 +27,7 @@ def translate_genre():
def sum_genre(list_years):
final_dict_genre = {}
for year in list_years:
print(f'dealing with {year}...')
dict_genre = get_genres(year)
for key in dict_genre.keys():
if key in final_dict_genre.keys():
......@@ -42,8 +43,8 @@ def sum_genre(list_years):
# print(get_genres(2003).keys())
# print(get_genres(2004).keys())
# print(get_genres(2005).keys())
print(translate_genre())
sum_genre = sum_genre([2001, 2003, 2004, 2005, 2006])
#print(translate_genre())
sum_genre = sum_genre(range(2003, 2014))
L = []
for key in sum_genre.keys():
L += [str(key)]
......
File added
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment