22 ''' |
24 ''' |
23 if source[len(source)-3:len(source)] == 'MP4' or source[len(source)-3:len(source)] == 'mp4': |
25 if source[len(source)-3:len(source)] == 'MP4' or source[len(source)-3:len(source)] == 'mp4': |
24 tomp4 = 0 |
26 tomp4 = 0 |
25 if tomp4 == 1: |
27 if tomp4 == 1: |
26 source = source[0:len(source)-3]+"mp4" |
28 source = source[0:len(source)-3]+"mp4" |
27 if source[0:4] == "http" or source[0:4] == "sftp": |
29 if source[0:5] == "https": |
|
30 return source |
|
31 elif source[0:4] == "http" or source[0:4] == "sftp": |
28 return "https"+source[4:len(source)] |
32 return "https"+source[4:len(source)] |
29 elif source[0:7] == "/video/": |
33 elif source[0:7] == "/video/": |
30 return "https://media.iri.centrepompidou.fr"+source |
34 return "https://media.iri.centrepompidou.fr"+source |
31 elif source[0:6] == "video/" or source[0:6] == "audio/": |
35 elif source[0:6] == "video/" or source[0:6] == "audio/": |
32 return "https://media.iri.centrepompidou.fr/"+source |
36 return "https://media.iri.centrepompidou.fr/"+source |
33 elif source[0:4] == "mp4:": |
|
34 return "hue" |
|
35 elif vidpath == 'rtmp://media.iri.centrepompidou.fr/ddc_player/video/regardssignes/' or \ |
37 elif vidpath == 'rtmp://media.iri.centrepompidou.fr/ddc_player/video/regardssignes/' or \ |
36 vidpath == 'rtmp://media.iri.centrepompidou.fr/ddc_player/mp4:video/regardssignes/': |
38 vidpath == 'rtmp://media.iri.centrepompidou.fr/ddc_player/mp4:video/regardssignes/': |
37 return "https://media.iri.centrepompidou.fr/video/regardssignes/"+source |
39 return "https://media.iri.centrepompidou.fr/video/regardssignes/"+source |
38 else: |
40 elif source[0:4] == "mp4:": |
39 return "https://media.iri.centrepompidou.fr/video/ldtplatform/"+source |
41 if vidpath == 'rtmp://media.iri.centrepompidou.fr/ddc_player/': |
|
42 return "https://media.iri.centrepompidou.fr/" + source[4:] |
|
43 return "https://media.iri.centrepompidou.fr/video/ldtplatform/"+source |
40 |
44 |
41 def numberofcontents(source): #this counts the number of contents linked to a media |
45 def numberofcontents(source): #this counts the number of contents linked to a media |
42 ''' |
46 ''' |
43 numberofcontents |
47 numberofcontents |
44 ''' |
48 ''' |
76 "Request status", |
79 "Request status", |
77 "Informations", |
80 "Informations", |
78 "Number of contents", |
81 "Number of contents", |
79 "Number of projects" |
82 "Number of projects" |
80 ]] |
83 ]] |
81 |
84 if options['f']: |
82 j=0 |
85 infos = open('results.txt', 'w') |
|
86 else: |
|
87 infos = open('projectsToChange.txt', 'w') |
|
88 j = 0 |
|
89 parser = etree.XMLParser(encoding='utf-8') |
|
90 logger = logging.getLogger(__name__) |
83 files1 = models.Media.objects.all() #this list contains every media |
91 files1 = models.Media.objects.all() #this list contains every media |
84 for elem1 in files1: |
92 for elem1 in files1: |
85 if numberofcontents(elem1) == 0: |
93 if numberofcontents(elem1) == 0: |
86 if options['f']: |
94 if options['f']: |
87 elem1.delete() #if there is no content |
95 elem1.delete() #if there is no content |
88 #linked to the media, the media is removed for the database |
96 #linked to the media, the media is removed for the database |
89 self.stdout.write(" No content found, media has been removed") |
97 self.stdout.write(" No content found, media has been removed") |
90 else: |
98 else: |
91 forcsv += [[ |
99 forcsv += [[ |
92 elem1.src, |
100 elem1.src, |
93 "XXX", |
101 "XXX", |
94 "XXX", |
102 "XXX", |
95 "XXX", |
103 "XXX", |
96 "NO CONTENT : media will be erased", |
104 "NO CONTENT : media will be erased", |
97 "0", |
105 "0", |
98 "0" |
106 "0" |
99 ]] |
107 ]] |
100 j += 1 |
108 j += 1 |
|
109 continue |
|
110 if numberofproject(elem1) == 0: |
|
111 if options['f']: |
|
112 mycontentid = models.Content.objects.filter(media_obj_id=elem1.id)[0].iri_id |
|
113 management.call_command('initfrontproject', mycontentid) |
|
114 else: |
|
115 forcsv += [[ |
|
116 elem1.src, |
|
117 "XXX", |
|
118 "XXX", |
|
119 "XXX", |
|
120 "No project : will be initialized", |
|
121 "1", |
|
122 "0" |
|
123 ]] |
|
124 ldtproj = models.Project.objects.filter\ |
|
125 (content=models.Content.objects.filter(media_obj_id=elem1.id)[0]) |
|
126 if elem1.src.lower() == tohttps(elem1.src, elem1.videopath).lower(): |
|
127 for numproject in xrange(len(ldtproj)): |
|
128 root = etree.XML(ldtproj[numproject].ldt.encode('utf-8'), parser) |
|
129 mediapathlen = len(root.xpath('medias/media')) |
|
130 if mediapathlen == 0: |
|
131 self.stdout.write(" .ldt has no media", ending='') |
|
132 continue |
|
133 if options['f'] and\ |
|
134 re.match(r"rtmp://media.iri.centrepompidou.fr/ddc_player/.*",elem1.videopath) != None: |
|
135 root.xpath('medias/media')[0].set("video", '') |
|
136 ldtproj[numproject].ldt = etree.tostring(root) |
|
137 ldtproj[numproject].save() |
|
138 self.stdout.write(" Project videopath modified!") |
|
139 infos.write(" Project videopath modified ") |
|
140 if re.match(r".*\.youtube\.com.*", elem1.src) != None\ |
|
141 or re.match(r".*youtu\.be.+", elem1.src) != None: |
|
142 if re.match(r".*feature=player_embedded.+", elem1.src) != None: |
|
143 myembed = "http://www.youtube.com/oembed?url=http://youtube.com/watch?v="\ |
|
144 + elem1.src[len(elem1.src)-11:] +"&format=json" |
|
145 else: |
|
146 myembed = "http://www.youtube.com/oembed?url=" + elem1.src + "&format=json" |
|
147 if requests.get(myembed).status_code == 404: |
|
148 self.stdout.write("%s : Video doesn't exists"% elem1.src) |
|
149 if numberofproject(elem1) > 0: |
|
150 ldtproj = models.Project.objects.get(id=models.Content.objects.filter\ |
|
151 (media_obj_id=elem1.id)[0].front_project_id).ldt |
|
152 root = etree.XML(ldtproj.encode('utf-8'), parser) |
|
153 if root.xpath('annotations/content/ensemble/decoupage/elements/element')\ |
|
154 == []: |
|
155 if options['f']: |
|
156 elem1.delete() |
|
157 self.stdout.write("video doesn't exist anymore : media deleted") |
|
158 else: |
|
159 forcsv += [[ |
|
160 elem1.src, |
|
161 "XXX", |
|
162 "XXX", |
|
163 "404", |
|
164 "Video doesn't exist anymore + empty projects", |
|
165 "1", |
|
166 "1" |
|
167 ]] |
|
168 |
101 if options['f']: |
169 if options['f']: |
102 self.stdout.write("%s files deleted"%j) |
170 self.stdout.write("%s files deleted"%j) |
103 infos = open('results.txt', 'w') |
|
104 parser = etree.XMLParser(encoding='utf-8') |
|
105 else: |
171 else: |
106 self.stdout.write("%s files to delete"%j) |
172 self.stdout.write("%s files to delete"%j) |
107 infos = open('projectsToChange.txt', 'w') |
|
108 i = 0 |
173 i = 0 |
109 files = list(chain( |
174 files = list(chain( |
110 models.Media.objects.filter(src__iregex=r".*.flv$"), |
175 models.Media.objects.filter(src__iregex=r".*.flv$"), |
111 models.Media.objects.filter(src__iregex=r".*.f4v$"), |
176 models.Media.objects.filter(src__iregex=r".*.f4v$"), |
|
177 models.Media.objects.filter(src__iregex=r".*.m4v$"), |
112 models.Media.objects.filter(src__iregex=r".*.mp4$").exclude(src__iregex=r"^https://.*") |
178 models.Media.objects.filter(src__iregex=r".*.mp4$").exclude(src__iregex=r"^https://.*") |
113 )) |
179 )) |
114 logger = logging.getLogger(__name__) |
180 |
115 for elem in files: |
181 for elem in files: |
116 self.stdout.write(" \n%s/%s files done"%(i+1, len(files)), ending='') |
182 self.stdout.write(" \n%s/%s files done"%(i+1, len(files)), ending='') |
117 i += 1 |
183 i += 1 |
118 if numberofcontents(elem) == 0: |
184 if numberofcontents(elem) == 0: |
119 self.stdout.write(" no content",ending='') |
185 self.stdout.write(" no content", ending='') |
120 continue |
186 continue |
121 mysrc = elem.src |
187 mysrc = elem.src |
122 newsource = tohttps(elem.src, elem.videopath) |
188 newsource = tohttps(elem.src, elem.videopath) |
123 try: |
189 try: |
124 res = requests.head(newsource, timeout=10).status_code |
190 res = requests.head(newsource, timeout=10).status_code |
307 infos.write("having as old media %s \nAs new media %s \nAs content %s \n"\ |
373 infos.write("having as old media %s \nAs new media %s \nAs content %s \n"\ |
308 % (elem.src, newsource, models.Content.objects.filter(media_obj_id=elem.id)[0].iri_id)) |
374 % (elem.src, newsource, models.Content.objects.filter(media_obj_id=elem.id)[0].iri_id)) |
309 if options['f']: |
375 if options['f']: |
310 for numproject in xrange(len(ldtproj)): |
376 for numproject in xrange(len(ldtproj)): |
311 root = etree.XML(ldtproj[numproject].ldt.encode('utf-8'), parser) |
377 root = etree.XML(ldtproj[numproject].ldt.encode('utf-8'), parser) |
312 if len(root.xpath('medias/media')) == 0: |
378 mediapathlen = len(root.xpath('medias/media')) |
|
379 if mediapathlen == 0: |
313 self.stdout.write(" le .ldt ne contient pas de media", ending='') |
380 self.stdout.write(" le .ldt ne contient pas de media", ending='') |
314 infos.write("le .ldt ne contient pas de media") |
381 infos.write("le .ldt ne contient pas de media") |
315 continue |
382 continue |
316 root.xpath('medias/media')[0].set("video", '') |
383 root.xpath('medias/media')[0].set("video", '') |
317 ldtproj[numproject].ldt = etree.tostring(root) |
384 ldtproj[numproject].ldt = etree.tostring(root) |