int loadPosts(struct website * configuration) { fprintf(stderr," Loading posts .. \n"); configuration->post.currentPosts=0; char filename[FILENAME_MAX]={0}; snprintf(filename,FILENAME_MAX,"src/Services/MyBlog/res/posts/post%u.html",configuration->post.currentPosts); while (AmmServer_FileExists(filename)) { struct AmmServer_MemoryHandler * tmp = AmmServer_ReadFileToMemoryHandler(filename); if (tmp!=0) { fprintf(stderr," Loading post %u (%s) .. \n",configuration->post.currentPosts,filename); configuration->post.item[configuration->post.currentPosts].content.data = tmp->content; //If we didnt use this we shold -> AmmServer_FreeMemoryHandler(&tmp); tmp->content=0; loadPostInfo(configuration,configuration->post.currentPosts); //------------- ++configuration->post.currentPosts; snprintf(filename,FILENAME_MAX,"src/Services/MyBlog/res/posts/post%u.html",configuration->post.currentPosts); } else { break; } } return 1; }
int CheckIfFileIsVideo(const char * filename) { if (AmmServer_FileExists(filename)) { char contentType[512]; GetContentType(filename,contentType,512); if ( GetExtentionType(contentType)==VIDEO) { //Todo also check internals of files ( file magic number headers etc ) return 1; } } return 0; }
char * generateThumbnailOfVideo(int live,const char * videoDirectory,const char * videofile,const char * thumbDirectory) { fprintf(stderr,"generateThumbnailOfVideo(%s,%s,%s)\n",videoDirectory,videofile,thumbDirectory); unsigned int thumbDirectoryLength=strlen(thumbDirectory); unsigned int videoFileLength=strlen(videofile); unsigned int thumbnailFileLength=thumbDirectoryLength+videoFileLength+25; char * thumbnailFile = (char*) malloc(sizeof(char) * thumbnailFileLength); if (thumbnailFile!=0) { snprintf(thumbnailFile,thumbnailFileLength,"%s/%s_thumb.jpg",thumbDirectory,videofile); if (AmmServer_FileExists(thumbnailFile)) { fprintf(stderr,"Thumbnail already exists\n"); return thumbnailFile; } else { if (live) { #if GENERATE_NEW_THUMBNAILS_LIVE #warning "This build generates new thumbnails live ,this is not very good.." #else free(thumbnailFile); return 0; #endif // GENERATE_NEW_THUMBNAILS } char what2Execute[1024]; snprintf(what2Execute,1024,"ffmpeg -y -i \"%s/%s\" -ss 00:00:14.435 -vframes 1 -vf scale=320:240 \"%s\" ",videoDirectory,videofile,thumbnailFile); fprintf(stderr,"Spawning %s .. ",thumbnailFile); int i=system(what2Execute); if (i==0) { fprintf(stderr,"success \n"); return thumbnailFile; } fprintf(stderr,"failed\n"); free(thumbnailFile); } } return 0; }