summaryrefslogtreecommitdiff
path: root/mg_image_provider.h
blob: 3c7433c02eb20d1f8d18bfab0ff68d1a5f301aa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106


#ifndef MG_IMAGE_PROVIDER
#define MG_IMAGE_PROVIDER

class mgItemGd;

#include <vdr/thread.h>

#include <string>
#include <vector>

#include <id3v2frame.h>
#include <tbytevector.h>
#include <id3v2tag.h>

class mgImageProvider : public cThread
{
 public:

  /*! \brief obtain next image in list
   */
  std::string getImagePath( std::string &source );

  /*! \brief tell the image provider that we are replaying a different item now. Return, whether images were found.
   */
  bool updateItem( mgItemGd *item );

  /*! \brief Initialize image provider with all files in the given directory
   */
  static mgImageProvider* Create( std::string dir );

  /*! \brief Initialize image provider for use with a Giantdisc item
   */
  static mgImageProvider* Create();

  /*! \brief destroy instance and delete remaining temporary files
   */
  ~mgImageProvider();

 protected:

  /*! \brief Executes image conversion (.jpg to .mpg) in a separate thread
   */
  virtual void Action();

 private:

  mgImageProvider( std::string dir );

  mgImageProvider( );
  
  /*! \brief Obtain all images in dir in alphabetic order
   */
  void fillImageList( std::string dir );

  /*! \brief update images according to GD scheme from database entry
   */
  bool extractImagesFromDatabase( mgItemGd *item );

  /*! \brief find images for an item
   */
  void updateFromItemDirectory( mgItemGd *item );

  /*! \brief write image from an id3v2 frame to a file
   */
  void writeImage( TagLib::ByteVector &image, int num, std::string &image_cache );

  /*! \brief convert all images found in the APIC frame list 
   */
  std::string treatFrameList( TagLib::ID3v2::FrameList &l, std::string &image_cache );

  /*! \brief save images from APIC tag and save to file. returns directory where images were saved or empty string if no images were found in the APIC tag
   */
  std::string extractImagesFromTag( std::string filename );

  /*! \brief delete temporary images
   */
  void deleteTemporaryImages();

  //! \brief define various modes how images can be obtained
  enum ImageMode 
    { 
      IM_ITEM_DIR, //< Use images from the directory in which the mgItem resides
      IM_PLAYLIST  //< Use a separate playlist passed from an external plugin
    };

  //! \brief the current image delivery mode
  ImageMode m_mode;

  //! \brief index of last image delivered
  unsigned m_image_index;

  //! \brief list of all image filenames when in modes ITEM_DIR or PLAYLIST
  std::vector<std::string> m_image_list;

  //! \brief list of all converted image filenames (.mpg) when in modes ITEM_DIR or PLAYLIST
  std::vector<std::string> m_converted_images;
  
  std::string m_source_dir;  

  bool m_delete_imgs_from_tag;
};

#endif